Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update:split #710

Merged
merged 4 commits into from
Sep 20, 2024
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
7 changes: 6 additions & 1 deletion swanlab/data/run/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
from ..formater import check_key_format
from swanlab.env import get_mode, get_swanlog_dir
import random
from swankit.env import is_windows


MAX_LIST_LENGTH = 108


class SwanLabRunState(Enum):
Expand Down Expand Up @@ -313,6 +315,9 @@ def log(self, data: dict, step: int = None):
and all([isinstance(i, (Line, MediaType)) for i in v])
and all([i.__class__ == v[0].__class__ for i in v])
):
if len(v) > MAX_LIST_LENGTH:
swanlog.warning(f"List length '{k}' is too long, cut to {MAX_LIST_LENGTH}.")
v = v[:MAX_LIST_LENGTH]
v = DataWrapper(k, v)
else:
# 其余情况被当作是非法的数据类型,交给Line处理
Expand Down
6 changes: 5 additions & 1 deletion swanlab/log/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import re


MAX_UPLOAD_LEN = 200


class SwanWriterProxy:
"""
标准输出流拦截代理
Expand Down Expand Up @@ -81,7 +84,8 @@ def _(message):
except UnicodeEncodeError:
# 遇到编码问题,直接pass,此时表现为终端不输出
pass
message = FONT.clear(message)
# 限制上传长度
message = FONT.clear(message)[:MAX_UPLOAD_LEN]
self.write_callback and self.write_callback(message)

# 检查文件分片
Expand Down
3 changes: 3 additions & 0 deletions test/unit/data/run/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ def test_log_text_ok(self):
# list
ll3 = run.log({"a": [Text("abc"), Text("def")]})
assert ll3["a"].data == ["abc", "def"]
data = {"a": [Text("abc")] * 109}
ll4 = run.log(data, step=4)
assert ll4["a"].data == ["abc"] * 108

# ---------------------------------- 解析log Audio ----------------------------------

Expand Down
12 changes: 12 additions & 0 deletions test/unit/log/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ def test_write_to_file(self):
assert content[-2] == a + "\n"
assert content[-1] == b + "\n"

def test_write_to_file_long_test(self):
console_dir = self.create_console_dir()
swanlog.install(console_dir)
# 加一行防止其他问题
print("\ntest write to file")
a = generate(size=201)
print(a)
files = os.listdir(console_dir)
with open(os.path.join(console_dir, files[0]), "r") as f:
content = f.readlines()
assert content[-1] == a[:200] + "\n"

def test_write_logging_to_file(self):
console_dir = self.create_console_dir()
swanlog.install(console_dir, log_level="debug")
Expand Down