Repository navigation
Fix AttributeError in auto-augment factories when hparams is None - #2747
Merged
rwightman merged 1 commit intoAug 26, 2026
Merged
Conversation
auto_augment_transform, rand_augment_transform and augment_and_mix_transform
all default hparams to None but call hparams.setdefault(...) for the mstd/mmax
config sections before normalizing it. augment_and_mix_transform also has an
unconditional hparams.setdefault('magnitude_std', inf), so it raised on ANY
config string. Each factory's own documented example (e.g. 'augmix-m5-w4-d2',
'rand-m9-n3-mstd0.5', 'original-mstd0.5') therefore crashed with
'NoneType' object has no attribute 'setdefault' when called without hparams.
Normalize to a copy of _HPARAMS_DEFAULT at the top of each factory, matching
the hparams = hparams or _HPARAMS_DEFAULT guard the ops helpers already use.
A copy is used because the factories mutate hparams via setdefault, which would
otherwise leak magnitude_std into the shared module-level default across calls.
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
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.
What
The three public auto-augment factory functions crash on their own documented default
hparams=None:Each of those config strings is copied verbatim from the corresponding function's own docstring example.
Why
All three functions declare
hparams: Optional[Dict] = None, but parse themstd/mmaxconfig sections by callinghparams.setdefault(...)beforehparamsis normalized:auto_augment_transform—hparams.setdefault('magnitude_std', ...)(mstd path)rand_augment_transform—hparams.setdefault('magnitude_std'/'magnitude_max', ...)(mstd/mmax paths)augment_and_mix_transform— same for mstd, plus an unconditionalhparams.setdefault('magnitude_std', float('inf')), so it raises on any config string, not just ones containingmstd.The ops helpers these factories call (
auto_augment_policy,rand_augment_ops,augmix_ops,AugmentOp) already guard withhparams = hparams or _HPARAMS_DEFAULT, but the factories dereferencehparamsbefore delegating, so that guard is never reached. The internaltransforms_factory.pypath always passes a real dict, which is why this wasn't caught in normal training runs — it only bites callers who use the factories directly with the documented default.Fix
Normalize
hparamsat the top of each factory, mirroring the existinghparams = hparams or _HPARAMS_DEFAULTidiom — but using a copy (dict(_HPARAMS_DEFAULT)). The factories mutatehparamsviasetdefault, and_HPARAMS_DEFAULThas nomagnitude_stdkey, so reusing the shared module-level dict directly would leakmagnitude_stdinto it and pin that value for every later call that relies on the defaults. Passing a realhparamsdict is unchanged.Tests
Added a parametrized regression test in
tests/test_data.pycovering every factory and each affected path (the mstd/mmax sections and augmix's unconditional default), asserting the transforms build and that the shared_HPARAMS_DEFAULTis never mutated. It fails onmain(6 cases) and passes with the fix;tests/test_data.py+tests/test_factory.pystay green (52 passed).