Repository navigation
Add Flux.setup(f, model) and warn on 16-bit parameters without MixedPrecision - #2852
Merged
Merged
Conversation
…edPrecision` `Flux.setup(f, model)` and its `Duplicated` method forward to `Optimisers.setup(f, model)` (Optimisers 0.4.13), with the same mutability check as `Flux.setup(rule, model)`, so that different arrays can get different rules. `Flux.setup` also warns, once, when a trainable array is `Float16` or `BFloat16` and its rule is not a `MixedPrecision`, since small updates are rounded away. The GPT-2 example uses `setup(f, model)` in place of its `no_decay!` pass. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2852 +/- ##
==========================================
- Coverage 71.89% 71.87% -0.02%
==========================================
Files 38 38
Lines 2693 2713 +20
==========================================
+ Hits 1936 1950 +14
- Misses 757 763 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Closes #2851. Closes #2843.
Flux.setup(f, model)(and theDuplicatedmethod) callsOptimisers.setup(f, model)with the same mutability check asFlux.setup(rule, model), so that each array can get its own rule. Optimisers compat is raised to 0.4.13, the release withsetup(f, model)andadjust!(tree, filter; kw...). Documented in thesetupdocstring and the training guide.Flux.setupwarns once if a trainable array isFloat16orBFloat16and its rule is not aMixedPrecision, naming the first such array and suggestingMixedPrecision(rule). This applies to both forms ofsetup.setup(f, model), replacingno_decay!.The
NaNin #2843 no longer happens on Optimisers 0.4.13 (Adamnow keeps Float64 hyperparameters), so the warning only describes the lost small updates.Tested on Julia 1.13.4:
test/train.jlpasses (173/173) andext_reactant/optimisers_reactantpasses (35/35). On a Reactant device,setup(f, model)with the example's rule gives losses and parameters bit-identical to the oldno_decay!after 6 steps, in f32 and in bf16 withMixedPrecision. I did not run the full GPT-2 example.🧔♂️🤖 Assisted by AI