Repository navigation
fix(config): report wrong-typed training values as validation errors - #2382
MakazhanAlpamys merged 4 commits into
Conversation
Nari-Ab
left a comment
There was a problem hiding this comment.
Thanks for the fix. I found a compatibility regression on the declared minimum Pydantic 2.0.0, verified against this PR's current head c9018fad42373d7404fe23e857b330286c578e8d (macOS, Python 3.11).
With Pydantic 2.0.0, both of these valid inputs now raise RuntimeError, rather than building a config:
from soup_cli.config.schema import TrainingConfig
TrainingConfig(minillm_enabled=False)
TrainingConfig(fp8_attention=False)The error is:
This validator expected to be run inside the context of a model field but no model field was found
TrainingConfig(minillm_enabled=0) raises the same RuntimeError, so the original refusal contract also remains broken on the floor. These cases produce the expected results on Pydantic 2.13.5. The outer wildcard wrap handler loses the field context of the inner info-consuming before validators on 2.0.
Please cover both the valid boolean case and the invalid-type case on the declared floor before merging. A working alternative is a shared TypeError-to-ValueError decorator on the schema callbacks themselves, preserving their signatures with functools.wraps. That leaves the runtime helpers unchanged and avoids the outer wrap issue.
I prepared that alternative in Nari-Ab/Soup, codex/config-type-errors-2366, commit ce132070. It is based on main at c38330cf and is available for comparison or adaptation. My implementation and tests were written independently before I noticed this PR. I have not opened a competing PR. If you incorporate code from the linked branch, please retain my attribution for those changes.
Validation of that alternative: 31 new cases pass on both Pydantic 2.0.0 and 2.13.5; the related suite passes 1,374 tests with one skip. The field walk covers 336 fields across eight models with six values each. Removing the converter makes all six field-walk cases fail. No full local suite or native Windows/Linux run is claimed.
AI assistance: OpenAI Codex implementation and verification.
…r keeps field context
|
Thanks @Nari-Ab, confirmed on Pydantic 2.0: the outer
|
|
Thank you, @shu-chen-dot-ca, for the rework, and for answering the review of @Nari-Ab so quickly and plainly. This is the first word from the maintainers on this pull request, so here is the whole standing.
Nothing else is asked of you now. We will say here when the decision on the workflow line and the validators is made. |
|
Thanks @MakazhanAlpamys. Yes: on head
Run with the I'll update the description to match the current head. |
MakazhanAlpamys
left a comment
There was a problem hiding this comment.
@shu-chen-dot-ca, an update on the decision that was still open on this pull request.
The maintainer has decided the error form for wrong-typed config values: the error is reported against the field (training -> minillm_enabled), each field keeps its own existing message where one exists, and a model-level conversion whose error sits at training is not taken.
This pull request already has that form, so nothing in it needs to change for the decision. By reading the diff at 92ddeeff:
_type_error_as_value_error(src/soup_cli/config/schema.py:47) converts inside each of the 24 validators and re-raises withstr(exc), so Pydantic puts the error ontraining -> <field>and the text stays the validator's own, including the helper texts such asnum_labels must not be bool.tests/test_config_field_types.pypins that location for the loader (:109) and forsoup trainandsoup plan(:128).- The five bool guards that named a release now name the field, which is what #2366 asked for in its proposed fix.
Still open, and separate from the code: the line that adds tests/test_config_field_types.py to the core-floor job (.github/workflows/ci.yml:696, with the REQUIRED_TESTS entry at tests/test_core_dependency_floors.py:36) is a maintainer decision that has not been made yet, and the checks start after it. Nothing is needed from you in the meantime. Thank you as well for bringing the description in line with the current head.
On #2366 this pull request goes first; #2419 and #2462 rebase after it.
|
@shu-chen-dot-ca, an update: the line that adds |
|
@shu-chen-dot-ca, thank you for the rework to per-validator decorators and for the floor evidence. A correction to our comment of 4 Nov (#2382 (comment)), which said the checks were being started on What has run on
So the Pydantic 2.0.0 numbers in the description (688 passed, 6 skipped for the file) come from your own run, and CI confirms them when that run ends. Nothing is needed from you for this. |
MakazhanAlpamys
left a comment
There was a problem hiding this comment.
@shu-chen-dot-ca, the checks that were waiting have now run on 92ddeeff, and they confirm the part of this change that mattered most. core-floor installed Pydantic 2.0, ran tests/test_config_field_types.py from the line you added to its list, and ended with 875 passed, 8 skipped, the same count as in your description. lint, mlx-smoke, transformers-floor, pytorch-smoke and test on ubuntu 3.11, ubuntu 3.12, macOS 3.12 and Windows 3.12 are green too. By reading the diff, the decorator does what the description says: functools.wraps keeps info working on the floor, and the field walk (tests/test_config_field_types.py:53-60) fails for any validator that lets a TypeError out, so a new field cannot bring the bug back. Thank you for the careful rework.
One thing is left before this can merge, and it is about timing rather than your code.
- Move the changelog fragment to
changelog.d/0.77.2/. Those checks ran on a merge withmainas it was on 3 Nov, when the latest release was v0.77.1. v0.77.2 was released on 5 Nov, andchangelog.d/onmainnow holds only0.77.2/. By reading,changelog.d/0.77.1/2382.fixed.mdis therefore rejected bytests/test_issue487_changelog_fragments.py::test_repository_fragments_match_the_newest_release(line 256) with "fragment baseline is 0.77.1, but the latest release is 0.77.2" (scripts/assemble_changelog.py:96-101). We have not run it, and the green checks above cannot show it. Please move it yourself, because maintainers do not push to contributors' branches. A trial merge of the branch with today'smainshows no conflicts, so a rebase is not needed; the move and a push are enough:
git mv changelog.d/0.77.1/2382.fixed.md changelog.d/0.77.2/2382.fixed.md
git commit -m "docs(changelog): move the #2382 fragment to 0.77.2"
git push
- While the file is open, end the entry with your credit, the way entries for outside work end: replace
(#2382, closes #2366)with(#2382 by @shu-chen-dot-ca, closes #2366). TheChangelog:line in the description names the old path; please update it as well.
The push starts a new run. For a first contribution it waits for a maintainer to start it, as the first one did, so "action required" is expected for a while; nothing more is needed from you for that.
|
Moved the fragment to |
|
Thank you, @shu-chen-dot-ca, for
The hosted checks on this head ran after your push and are all green: Nothing else is asked of you. Reading verdict: READY-BY-READING. The change turns a bare By reading; nothing was run here. The hosted runs, labels and merge order are answered separately in this thread. |
|
Thank you, @shu-chen-dot-ca, for #2382. It is the pull request that went first on #2366: a wrong-typed |
Display names from `gh api users/<login>`.
…akazhanAlpamys#2382) A wrong-typed value in one of 38 `training` fields (for example `minillm_enabled: 0`, `fp8_attention: "false"` or `num_labels: true`) raised a bare `TypeError` from a field validator. Pydantic does not turn a `TypeError` into a `ValidationError`, so `soup train` printed `Error: TypeError: v0.70.0 MiniLLM flag must be bool, got int`, `soup plan` exited 2, and `load_config_from_string` raised `TypeError` where it documents `ValueError` (MakazhanAlpamys#2366). The value is now a config validation error on `training -> <field>`, with exit 1 from both `soup train` and `soup plan`. `_type_error_as_value_error` in `src/soup_cli/config/schema.py` is a `functools.wraps` decorator on the 24 `TrainingConfig` validators behind those 38 fields. It re-raises a `TypeError` as a `ValueError` with the same text, so Pydantic reports it with the field's location, and `functools.wraps` keeps the signature Pydantic inspects to decide whether a validator takes `info`. The shared helpers (`num_labels`, `distill_temperature`, the `grace_codebook_*` checks and others) keep raising `TypeError` for their other callers. The first head used one `@field_validator("*", mode="wrap")`, as the issue proposed; on the declared floor, Pydantic 2.0.0, that wrap strips the field context from every validator that takes `info`, and a review by @Nari-Ab found `TrainingConfig(minillm_enabled=False)` raising `RuntimeError` there, so it was replaced. The five bool-guard validators that named a release (`v0.70.0 MiniLLM flag must be bool`, `v0.53.0 flag must be bool` and the others) now name the field, for example `minillm_enabled must be bool, got int`. `tests/test_config_field_types.py` walks every field of every model reachable from `SoupConfig` with `0`, `true`, `"false"`, `[]`, `{}` and `1.5` and accepts only success or `ValidationError`; it also checks that every field accepts its own default, that six bool flags accept `True` and `False`, that `load_config_from_string` raises `ValueError` naming `training -> <field>`, and that `soup train` and `soup plan` exit 1 with `Config validation error:`. Eight existing cases that pinned the old `TypeError` (`test_bool_guards_reject_int` in `tests/test_v0530.py` for 7 fields and `test_unlearn_alpha_bool_rejected` in `tests/test_v0610_part_a.py`) now expect a validation error that names the field. The file is added to the pytest list of the `core-floor` job in `.github/workflows/ci.yml` (the one change to a workflow: one appended line) and to `REQUIRED_TESTS` in `tests/test_core_dependency_floors.py`, so it runs on Pydantic 2.0.0. The change carries the fragment `changelog.d/0.77.2/2382.fixed.md`. What users notice: a wrong-typed `training` value ends in `Config validation error:` with a line naming `training -> <field>` and exit 1, instead of a `TypeError` line, and `soup plan` exits 1 where it exited 2 for these configs. A value that loaded on v0.77.2 still loads; only values that already crashed change. Verified by CI on the head `d90a9856` (labelled `ci:full`), merged with `2db8e0c55` by GitHub's test merge: lint, mlx-smoke, transformers-floor and pytorch-smoke succeeded, `core-floor` succeeded on Pydantic 2.0 (job 131004079243, 875 passed, 8 skipped), and so did the test cells ubuntu 3.11 (job 131004079203, 55261 passed, 598 skipped), ubuntu 3.12 (job 131004079360, 55266 passed, 593 skipped), macOS 3.12 (job 131004079212, 55245 passed, 614 skipped) and Windows 3.12 (job 131004079239, 55131 passed, 728 skipped). In all four test job logs `tests/test_config_field_types.py` ran 688 cases that passed and 6 skipped, and none failed. No test was run locally for this pull request. Closes MakazhanAlpamys#2366
Display names from `gh api users/<login>`.
What does this PR do?
Closes #2366, following the fix proposed in the issue, with the per-validator conversion from the review.
A wrong-typed value in 38
trainingfields (for exampleminillm_enabled: 0) raised a bareTypeErrorfrom a field validator. Pydantic does not convert aTypeErrorinto aValidationError, sosoup trainprintedError: TypeError: v0.70.0 MiniLLM flag must be bool, got int,soup planexited 2, andload_config_from_stringraisedTypeErrorinstead of its documentedValueError.functools.wrapsdecorator,_type_error_as_value_errorinconfig/schema.py, sits on the 24TrainingConfigvalidators behind the 38 fields and re-raises aTypeErroras aValueErrorwith the same text, so Pydantic reports it with the field's location.functools.wrapskeeps the signature Pydantic inspects forinfo. The shared helpers (num_labels,distill_temperature,grace_codebook_*and so on) keep raisingTypeErrorfor their other callers.@field_validator("*", mode="wrap")instead. On the declared floor, Pydantic 2.0.0, that wrap strips the field context from every inner validator that takesinfo, so 27 fields raisedRuntimeErrorthere, valid values included (review above). It is removed.v0.70.0 MiniLLM flag must be bool,v0.53.0 flag must be bool, ...) now useinfo.field_name, e.g.minillm_enabled must be bool, got int.training: {minillm_enabled: 0},soup trainandsoup planboth printConfig validation error:andtraining -> minillm_enabled: minillm_enabled must be bool, got int, and both exit 1.TypeError:test_v0530.py::TestLFParity::test_bool_guards_reject_int(7 fields) andtest_v0610_part_a.py::TestSchemaUnlearnTask::test_unlearn_alpha_bool_rejected. They now expect a validation error that names the field. Thetest_v0530.pycase validates throughSoupConfigdirectly, because forquantize_ref_modelthe loader now reaches its "read by nothing; refused as of v0.77" refusal before the bool guard, which theTypeErrorused to hide.tests/test_config_field_types.pyis added to thecore-floorjob's pytest list in.github/workflows/ci.ymland toREQUIRED_TESTSintests/test_core_dependency_floors.py, so it runs on Pydantic 2.0.0.Changelog:
changelog.d/0.77.2/2382.fixed.md.Type of change
What I ran
tests/test_config_field_types.pywalks every field of every model reachable fromSoupConfigwith0,true,"false",[],{}and1.5and accepts only success orValidationError; it also checks every field accepts its own default, six bool flags acceptTrue/False,load_config_from_stringraisesValueErrornamingtraining -> <field>, andsoup train/soup planexit 1 withConfig validation error:.core-floorconstraints (Python 3.11): the file gives 688 passed, 6 skipped; thecore-floorjob's pytest command with it added gives 875 passed, 8 skipped. The previous headc9018fadfails 72 cases of the file there.ruff check src/soup_cli/ scripts/ tests/ benchmarks/passes.pytest tests/ -n 8 --dist loadfilewith the default coverage addopts: 49005 passed, 561 skipped.Error: TypeError: v0.70.0 MiniLLM flag must be bool, got int(exit 1);soup planexits 2Config validation error:/training -> minillm_enabled: minillm_enabled must be bool, got int(exit 1 for both)AI assistance: Claude (Anthropic) implementation and verification.
Checklist
ruff check src/soup_cli/ scripts/ tests/passespytest tests/ -vpasses (run with-n 8 --dist loadfile -qinstead of-v; full suite)README.mdand the matching page underdocs/) if needed (no field, type, default or bound changed, so the generated reference pages are untouched)CONTRIBUTING.md)