fix: Windows 系统下,与 accelerate 一起使用时,local 模式因默认 gkb 编码导致报错 #1195
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
问题背景
在使用最新版的
accelerate==1.9.0
与swanlab[dashboard]==0.6.7
进行本地实验记录时(mode="local"
),我在 Windows 平台 下遇到了编码相关的崩溃。具体来说:swanlab.config["FRAMEWORK"] = "🤗Accelerate"
时触发异常gbk
,无法解析其中包含的 emoji 字符(如 🤗)复现方式
测试环境:
复现代码(仅在官方示例基础上添加
mode="local"
):报错信息
修复方案
在文件
swanlab/proto/v0.py
中的to_file_model()
方法内,所有涉及读取文件(如 JSON、YAML)的位置(139-154 行),添加:以显式指定 UTF-8 编码,避免依赖平台默认设置。
补充说明
这个修改理论上侵入性极小,应该不会引入其他bug,望采纳