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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
swankit==0.2.1
swankit==0.2.2
urllib3>=1.26.0
requests>=2.25.0
setuptools
Expand Down
4 changes: 2 additions & 2 deletions swanlab/data/callbacker/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
from ..run import get_run


class BackupCallback(SwanLabRunCallback):
class OfflineCallback(SwanLabRunCallback):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def __str__(self) -> str:
return "SwanLabBackupCallback"
return "SwanLabOfflineCallback"

# ---------------------------------- 辅助函数 ----------------------------------
def _sync_tip_print(self):
Expand Down
18 changes: 11 additions & 7 deletions swanlab/data/run/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@Description:
在此处定义SwanLabRun类并导出
"""
import os
import random
from datetime import datetime
from typing import Any, Callable, Dict, Optional, List
Expand All @@ -16,7 +17,7 @@

from swanlab.data import namer as N
from swanlab.data.modules import DataWrapper, FloatConvertible, Line, Echarts, PyEchartsBase
from swanlab.env import get_mode, get_swanlog_dir
from swanlab.env import get_mode, get_swanlog_dir, SwanLabEnv
from swanlab.log import swanlog
from swanlab.package import get_package_version
from swanlab.swanlab_settings import reset_settings, get_settings
Expand Down Expand Up @@ -95,7 +96,7 @@ def __init__(
should_save = False
elif self.__mode == "local":
should_save = True
elif self.__mode == "backup":
elif self.__mode == "offline":
should_save = True
elif self.__mode == "cloud":
should_save = swanlab_settings.backup
Expand Down Expand Up @@ -151,9 +152,11 @@ def _(state: SwanLabRunState):
)
# 定时采集系统信息
self.monitor_cron = None
if self.monitor_funcs is not None and len(self.monitor_funcs) != 0:
swanlog.debug("Monitor on.")
self.monitor_cron = MonitorCron(self.__get_monitor_func())
# 测试时不开启此功能
if os.environ.get(SwanLabEnv.RUNTIME.value) not in ("test", "test-no-cloud"):
if self.monitor_funcs is not None and len(self.monitor_funcs) != 0:
swanlog.debug("Monitor on.")
self.monitor_cron = MonitorCron(self.__get_monitor_func())

def __get_monitor_func(self):
"""
Expand Down Expand Up @@ -237,8 +240,9 @@ def __cleanup(self, error: str = None):
"""
停止部分功能,内部清理时调用
"""
if self.monitor_cron is not None:
self.monitor_cron.cancel()
monitor_cron = getattr(self, "monitor_cron", None)
if monitor_cron is not None:
monitor_cron.cancel()
if get_settings().log_proxy_type not in ['stderr', 'all']:
error = None
self.__operator.on_stop(error)
Expand Down
6 changes: 3 additions & 3 deletions swanlab/data/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def login(api_key: str = None, host: str = None, web_host: str = None, save: boo
os.environ[SwanLabEnv.API_KEY.value] = api_key


MODES = Literal["disabled", "cloud", "local", "backup"]
MODES = Literal["disabled", "cloud", "local", "offline"]


class SwanLabInitializer:
Expand Down Expand Up @@ -139,7 +139,7 @@ def init(
If the value is 'cloud', data will be uploaded to the cloud and the local log will be saved.
If the value is 'local', data will only be saved locally and will not be uploaded to the cloud.
If the value is 'disabled', data will not be saved or uploaded, just parsing the data.
If the value is 'backup', data will be saved locally without uploading to the cloud.
If the value is 'offline', data will be saved locally without uploading to the cloud.
load : str, optional
If you pass this parameter,SwanLab will search for the configuration file you specified
(which must be in JSON or YAML format)
Expand Down Expand Up @@ -194,7 +194,7 @@ def init(
callbacks = check_callback_format(self.cbs + callbacks)
# 校验mode参数并适配 backup 模式
mode, login_info = _init_mode(mode)
if mode == "backup":
if mode == "offline":
merge_settings(Settings(backup=True))
elif mode == "disabled":
merge_settings(Settings(backup=False))
Expand Down
6 changes: 3 additions & 3 deletions swanlab/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from swankit.log import FONT

from swanlab.api import terminal_login, LoginInfo
from swanlab.data.callbacker.backup import BackupCallback
from swanlab.data.callbacker.backup import OfflineCallback
from swanlab.data.callbacker.cloud import CloudRunCallback
from swanlab.data.formatter import check_proj_name_format, check_load_json_yaml
from swanlab.data.run import SwanLabRun
Expand Down Expand Up @@ -209,8 +209,8 @@ def _create_operator(
# 本地模式不保存 media,由回调同步保存
c.append(LocalRunCallback(backup=backup, backup_media=False))
# 1.4 . 备份模式
elif mode == SwanLabMode.BACKUP.value:
c.append(BackupCallback(backup=True))
elif mode == SwanLabMode.OFFLINE.value:
c.append(OfflineCallback(backup=True))
# 1.5. 其他非法模式 报错,backup 模式不需要在此处理
# 上层已经 merge_settings , get_settings().backup 与此处是否设置 backup 功能等价
elif mode not in SwanLabMode.list():
Expand Down
4 changes: 2 additions & 2 deletions swanlab/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SwanLabEnv(enum.Enum):
"""
MODE = SwanLabSharedEnv.SWANLAB_MODE.value
"""
swanlab的解析模式,涉及操作员注册的回调,目前有三种:local、cloud、disabled,默认为cloud
swanlab的解析模式,涉及操作员注册的回调,目前有四种:local、cloud、disabled、offline,默认为cloud
大小写敏感
"""
SWANBOARD_PROT = "SWANLAB_BOARD_PORT"
Expand Down Expand Up @@ -139,7 +139,7 @@ def check(cls):
:raises ValueError: 如果环境变量的值不在预期值中
"""
envs = {
cls.MODE.value: ["local", "cloud", "disabled", "backup"],
cls.MODE.value: ["local", "cloud", "disabled", "offline"],
cls.RUNTIME.value: ["user", "develop", "test", "test-no-cloud"],
}
for k, vs in envs.items():
Expand Down
6 changes: 3 additions & 3 deletions test/unit/data/test_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,16 @@ def test_init_logdir_env(self):
run = S.init(mode="local")
assert run.public.swanlog_dir == logdir

def test_init_logdir_backup(self):
def test_init_logdir_offline(self):
logdir = os.path.join(T.TEMP_PATH, generate()).__str__()
os.environ[LOG_DIR] = logdir
run = S.init(mode="backup")
run = S.init(mode="offline")
assert run.public.swanlog_dir == logdir
run.finish()
del os.environ[LOG_DIR]
logdir = os.path.join(T.TEMP_PATH, generate()).__str__()
os.environ[LOG_DIR] = logdir
run = S.init(mode="backup")
run = S.init(mode="offline")
assert run.public.swanlog_dir == logdir

@pytest.mark.skipif(T.is_skip_cloud_test, reason="skip cloud test")
Expand Down
14 changes: 9 additions & 5 deletions tutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@
"""
from .check import *
from .config import *
from swanlab.env import SwanLabEnv

API_HOST = os.getenv(SwanLabEnv.API_HOST.value)
WEB_HOST = os.getenv(SwanLabEnv.WEB_HOST.value)
API_KEY = os.getenv(SwanLabEnv.API_KEY.value)


def reset_some_env():
os.environ[SwanLabEnv.SWANLOG_FOLDER.value] = SWANLOG_FOLDER
os.environ[SwanLabEnv.SWANLAB_FOLDER.value] = SWANLAB_FOLDER
os.environ[SwanLabEnv.RUNTIME.value] = runtime
SwanLabEnv.set_default()
SwanLabEnv.check()
if not is_skip_cloud_test:
Expand All @@ -27,6 +23,14 @@ def reset_some_env():
os.environ[SwanLabEnv.API_KEY.value] = API_KEY


# env 必须在 config 之后导入
from swanlab.env import SwanLabEnv

API_HOST = os.getenv(SwanLabEnv.API_HOST.value)
WEB_HOST = os.getenv(SwanLabEnv.WEB_HOST.value)
API_KEY = os.getenv(SwanLabEnv.API_KEY.value)


if not os.path.exists(TEMP_PATH):
os.mkdir(TEMP_PATH)
reset_some_env()
Expand Down