fix(config): read YAML config files as UTF-8#124
Open
nankingjing wants to merge 1 commit into
Open
Conversation
_load_yaml opened config files with the platform default (locale) encoding instead of UTF-8. The shipped configs (e.g. configs/_base_/default.yaml) contain UTF-8 non-ASCII characters (em-dash, arrows, box-drawing), so load_config() raises UnicodeDecodeError on any non-UTF-8 locale (e.g. Windows cp936/cp1252), breaking scripts/train.py and scripts/eval_only.py before startup. YAML is UTF-8 by spec, and the rest of the codebase already opens text files with encoding="utf-8". Pass encoding="utf-8" here for parity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
skillopt/config.py::_load_yamlopens YAML config files without specifying anencoding:
open()therefore decodes using the platform's locale-dependent defaultencoding (
locale.getpreferredencoding()), not UTF-8. The shipped configscontain UTF-8 non-ASCII characters — for example the very first line of
configs/_base_/default.yaml:The
—(U+2014 em-dash), along with→and box-drawing─used elsewhere inthe configs, are multi-byte in UTF-8. On any host whose default encoding is not
UTF-8 (e.g. Windows with a
cp936/cp1252locale),load_config()raisesUnicodeDecodeErrorbefore training can start, breaking both entry points(
scripts/train.pyandscripts/eval_only.py).Reproduction (locale where preferred encoding is not UTF-8):
Fix
Open the YAML file as UTF-8. YAML is UTF-8 by spec, and the rest of the
codebase already opens text files with
encoding="utf-8"(e.g.skillopt/prompts/__init__.py,skillopt/datasets/base.py), so this justrestores parity.
Verification
python -m py_compile skillopt/config.pypasses.load_config("configs/_base_/default.yaml")raisedUnicodeDecodeErrorunder acp936locale; after the change,load_config(...)+flatten_config(...)succeed for the base config andevery env config that inherits it (searchqa, spreadsheetbench, alfworld, and
features/soft_gate.yaml).