Skip to content

Add Flux.setup(f, model) and warn on 16-bit parameters without MixedPrecision - #2852

Merged
CarloLucibello merged 1 commit into
masterfrom
cl/setup-function-lowprec-warning
Nov 24, 2026
Merged

CarloLucibello merged 1 commit into
masterfrom
cl/setup-function-lowprec-warning

Conversation

@CarloLucibello

Copy link
Copy Markdown
Member

Closes #2851. Closes #2843.

  • Flux.setup(f, model) (and the Duplicated method) calls Optimisers.setup(f, model) with the same mutability check as Flux.setup(rule, model), so that each array can get its own rule. Optimisers compat is raised to 0.4.13, the release with setup(f, model) and adjust!(tree, filter; kw...). Documented in the setup docstring and the training guide.
  • Flux.setup warns once if a trainable array is Float16 or BFloat16 and its rule is not a MixedPrecision, naming the first such array and suggesting MixedPrecision(rule). This applies to both forms of setup.
  • The GPT-2 example builds its rule per array with setup(f, model), replacing no_decay!.

The NaN in #2843 no longer happens on Optimisers 0.4.13 (Adam now keeps Float64 hyperparameters), so the warning only describes the lost small updates.

Tested on Julia 1.13.4: test/train.jl passes (173/173) and ext_reactant/optimisers_reactant passes (35/35). On a Reactant device, setup(f, model) with the example's rule gives losses and parameters bit-identical to the old no_decay! after 6 steps, in f32 and in bf16 with MixedPrecision. I did not run the full GPT-2 example.

🧔‍♂️🤖 Assisted by AI

…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>
@CarloLucibello
CarloLucibello merged commit b3edc94 into master Nov 24, 2026
9 of 11 checks passed
@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.87%. Comparing base (7c77260) to head (506b8cd).
⚠️ Report is 2 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Flux.setup(f, model), choosing a rule for each array Flux.setup: warn when 16-bit parameters get a rule without MixedPrecision

1 participant