Repository navigation
Fix OptimizerRegistry.create_optimizer crash on layer_decay without an explicit min scale - #2754
Merged
rwightman merged 1 commit intoAug 26, 2026
Conversation
…t min_scale The registry create_optimizer defaulted layer_decay_min_scale to None and forwarded it unguarded as min_scale into param_groups_layer_decay, whose layer_scales line does max(min_scale, layer_decay ** ...). With layer_decay set and min_scale left default, that evaluates max(None, float) and raises TypeError. The sibling create_optimizer_v2 and param_groups_layer_decay itself both default this to 0.0; match that. layer_decay_no_opt_scale keeps its Optional[None] default because it is used behind a truthiness guard (if no_opt_scale and ...), so None is safe there.
|
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
Minor, but a hard crash: calling the registry's
create_optimizerwithlayer_decayset and the min scale left at its default raises aTypeError.The common entry point
create_optimizer_v2is not affected — it passes0.0.Why
OptimizerRegistry.create_optimizerdefaultslayer_decay_min_scaletoNoneand forwards it unguarded asmin_scaleintoparam_groups_layer_decay, whose scale line is:max(None, <float>)raises in Python 3. Bothcreate_optimizer_v2(layer_decay_min_scale: float = 0.0) andparam_groups_layer_decayitself (min_scale: float = 0.) already default this to0.0; only the registry method defaulted it toNone.Fix
Default
layer_decay_min_scaleto0.0in the registry method, matching its siblings.0.0is a no-op clamp (the scales are already>= 0), so this only removes the crash — it doesn't change behavior for callers that passed a value.layer_decay_no_opt_scalekeeps itsOptional[float] = Nonedefault on purpose: it's consumed behind a truthiness guard (if no_opt_scale and ...), soNoneis safe there. Verified that the same call with onlyno_opt_scalestill crashes onmin_scale, confirmingmin_scaleis the sole culprit.Tests
Added
test_registry_create_optimizer_layer_decay_default_min_scale, which builds layer-decay param groups through the registry path with the min scale omitted. It fails onmain(theTypeError) and passes with the fix; the related layer-decay/param-group tests stay green.