fix(merge_lora): silence false-positive '16-mixed' AMP warning on CPU#2252
Closed
jbbqqf wants to merge 1 commit into
Closed
fix(merge_lora): silence false-positive '16-mixed' AMP warning on CPU#2252jbbqqf wants to merge 1 commit into
jbbqqf wants to merge 1 commit into
Conversation
…Lightning-AI#1242) When a LoRA checkpoint records `precision: 16-mixed` (a common default for GPU finetune runs), `litgpt merge_lora` instantiates Fabric on CPU with that precision and Fabric emits: "You passed `Fabric(accelerator='cpu', precision='16-mixed')` but AMP with fp16 is not supported on CPU. Using `precision='bf16-mixed'` instead." The warning is a false positive: the merge step overrides the dtype with `model.to(dtype=lora_dtype, device='cpu')` immediately after loading, so the precision passed to Fabric has no effect on the saved checkpoint. The warning confuses users who configure Fabric in their training script and don't know what's happening under the hood (reported in Lightning-AI#1242). Downgrade '16-mixed' to 'bf16-mixed' ourselves before constructing Fabric, matching what Fabric would do internally but without the warning. All other precision values pass through unchanged. Add a regression test that exercises the fix by setting `precision: 16-mixed` in `hyperparameters.yaml` and asserting the Fabric warning is not captured by `caplog`.
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.
Summary
Fixes #1242.
When a user finetunes LoRA with
precision: 16-mixed(a common default for GPU runs),litgpt merge_loraruns Fabric on CPU with that precision and Fabric prints:The warning is a false positive: the merge step only loads weights and immediately overrides their dtype with
model.to(dtype=lora_dtype, device="cpu")(merge_lora.py:75), so theprecisionpassed to Fabric has no effect on the saved checkpoint. The warning still surfaces to users who configure Fabric in their training script and don't know what's happening under the hood, as flagged in the original issue.This PR downgrades
"16-mixed"→"bf16-mixed"ourselves before callingL.Fabric(...), matching what Fabric would do internally but without the noisy warning. All other precision values pass through unchanged, so behaviour is preserved.Reproduce BEFORE/AFTER yourself (copy-paste)
What I ran locally
Unit test under
tests/test_merge_lora.py::test_merge_lora_downgrades_16_mixed_to_avoid_cpu_warning:origin/main: fails — the Fabric warning record matches"AMP with fp16 is not supported on CPU".caplogcaptures no such record;lit_model.pthis written successfully.The existing parametrised
test_merge_lora(3 cases) still passes because the new branch only fires whenprecision == "16-mixed", which the existing tests don't exercise.Edge cases
precisionfromhyperparameters.yaml"16-mixed"bf16-mixedbf16-mixedhere"bf16-mixed""bf16-true","32-true","16-true", etc.None(no precision in metadata)--precision 16-mixedexplicitly on CLIThe downgrade applies to both the metadata-driven path (
lora_precisionfromhyperparameters.yaml) and the CLI-driven path (--precision), because the warning is purely a function of(precision, accelerator)andmerge_lorais always CPU-bound here.PR drafted with assistance from Claude Code (Anthropic). The change was reviewed manually against
litgpt/scripts/merge_lora.pyandtests/test_merge_lora.py. The reproducer block above is the one I used during development; reviewers can paste it verbatim.