Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions swanlab/api/upload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from ..http import get_http, sync_error_handler
from .model import ColumnModel
from typing import List, Tuple, Dict
from swanlab.error import FileError
from swanlab.error import FileError, ApiError
from swanlab.log import swanlog
import json
import yaml
import os
Expand Down Expand Up @@ -140,7 +141,11 @@ def upload_column(columns: List[ColumnModel]):
http = get_http()
url = f'/experiment/{http.exp_id}/column'
# WARNING 这里不能使用并发请求,可见 https://github.com/SwanHubX/SwanLab-Server/issues/113
_ = [http.post(url, data=column.to_dict()) for column in columns]
for column in columns:
try:
http.post(url, column.to_dict())
except ApiError as e:
swanlog.error(f"Upload column {column.key} failed: {e.resp.status_code}")


__all__ = [
Expand Down
23 changes: 10 additions & 13 deletions swanlab/api/upload/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class ColumnModel:
def __init__(self, key, column_type: str, error: dict = None):
"""
:param key: 列名称
:param column_type: 列类型,'FLOAT', 'IMAGE', 'AUDIO', 'TEXT', 'ANY',必须为大写,如果传入 'DEFAULT',则会转为 'FLOAT'
:param error: 错误信息,如果错误信息不为None,column_type必须为'ANY'
:param column_type: 列类型,'FLOAT', 'IMAGE', 'AUDIO', 'TEXT',必须为大写,如果传入 'DEFAULT',则会转为 'FLOAT'
:param error: 错误信息,如果错误信息不为None
"""
self.key = key
if column_type == "DEFAULT":
Expand All @@ -27,14 +27,11 @@ def __init__(self, key, column_type: str, error: dict = None):
self.error = error

def to_dict(self):
if self.error is not None:
return {
"key": self.key,
"type": 'ANY',
"error": self.error
}
else:
return {
"key": self.key,
"type": self.column_type,
}
return {
"key": self.key,
"type": self.column_type,
} if self.error is None else {
"key": self.key,
"type": self.column_type,
"error": self.error
}
2 changes: 1 addition & 1 deletion swanlab/cloud/_log_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def upload(self):
if msg[0] in UploadType:
upload_tasks_dict[msg[0]].extend(msg[1])
tasks_key_list = [key for key in upload_tasks_dict if len(upload_tasks_dict[key]) > 0]

# 同步执行所有的上传任务

results = [x.value['upload'](upload_tasks_dict[x]) for x in tasks_key_list]
for index, result in enumerate(results):
# 如果出现已知问题
Expand Down
22 changes: 22 additions & 0 deletions test/create_error_chart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
r"""
@DATE: 2024/5/16 20:42
@File: create_error_chart.py
@IDE: pycharm
@Description:
创建错误图表
"""
from tutils import open_dev_mode
import swanlab

swanlab.login(api_key=open_dev_mode())

swanlab.init(
description="此实验的图表将出现问题",
log_level="debug",
cloud=True,
)

for i in range(10):
swanlab.log({"success": i, "error": "abc"})