Conversation
build_hydra_overrides left top-level TOML strings unquoted unless they
held a comma or a space. Hydra re-types an unquoted right-hand side, so a
string field such as job.name = "20260913", "true" or "null" reached the
config as an int, bool or None, and a string containing "=", "(", "[",
"#" or an apostrophe was rejected by the override grammar, aborting the
load before training starts.
Quote every string value, escaping quotes and the backslashes Hydra would
otherwise consume. Numbers, bools, lists, ${...} interpolation and the
"???" skip are unchanged.
Signed-off-by: kevin9327 <5299031+kevin9327@users.noreply.github.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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
A string value in an SFT TOML can be changed or rejected on its way into the config.
_hydra_formatonly quotes a top-level string when it holds a comma or a space, and Hydra re-types an unquoted value:name = "20260913"job.name=20260913int20260913name = "1e-4"job.name=1e-4float0.0001name = "true"/"null"job.name=true/job.name=nullTrue/Nonename = "lr=1e-5"job.name=lr=1e-5OverrideParseException: mismatched input '=' expecting <EOF>name = "run(v2)"job.name=run(v2)Unknown function 'run'name = "run[1]","exp#3"name = "bob's run"job.name='bob's run'So a run name, group, project or path containing
=,(,[,#or an apostrophe stops--sft-tomlloading before training starts. A numeric-looking run name loads but is anint, whichConfig.validatethen passes tobytearray(self.job.name, "utf-8"), and that raisesTypeError: encoding without a string argument. String items inside lists were already quoted, but their apostrophes weren't escaped either.Fix
Quote every string value, in lists or not. The new
_hydra_quoteescapes'and doubles only the backslashes Hydra would otherwise consume, meaning those just before a quote or at the end of the string. Numbers, bools, lists,${oc.env:...}interpolation (still resolved inside quotes) and the"???"skip are unchanged. The now-unusedin_listparameter is removed.Tests
New tests in
cosmos_framework/configs/toml_config/sft_config_test.py(TestBuildHydraOverrides) feed the emitted override back through Hydra's ownOverridesParser:test_string_value_reaches_hydra_as_the_same_string: parametrized over the values in the table plusa\'bandends\. The result must be astrequal to the TOML value.test_string_list_items_reach_hydra_as_the_same_strings:["480", "bob's"].test_non_string_values_keep_their_types:lr=1e-5,betas=[0.9, 0.99],max_iter=200,ema.enabled=false,vae_path="${oc.env:WAN_VAE_PATH}"andload_path="???"parse to the same types and values as before. This test passes both before and after the change, so the change doesn't widen what is emitted for non-strings.Fail-before (source reverted, tests kept):
(
ends\passes before too: an unquoted trailing backslash already parsed.)Counts for
sft_config_test.py:main, existing testsThe shipped
examples/toml/sft_config/*.tomlstill validate and build overrides; those parametrized cases are part of the 34.Run on CPU:
PYTHONUTF8=1 COSMOS_TRAINING=0 pytest cosmos_framework/configs/toml_config/sft_config_test.py. On a non-UTF-8 locale,PYTHONUTF8=1is needed for the existing example-TOML test to read the files.COSMOS_TRAINING=0avoids the object-store backend import.Lint
ruff 0.12.7(repo pin) on both touched files:ruff checkoutput is identical before and after (one pre-existingI001intoml_config_helper.py).ruff format --diffis the same size before and after (28 changed lines, all pre-existing).sft_config_test.pyis clean both ways.🤖 Generated with Claude Code