fix(finetune): all_reduce val_loss for initial/final evaluation in multi-GPU training#2224
Open
NIK-TIGER-BILL wants to merge 2 commits intoLightning-AI:mainfrom
Open
Conversation
…al evaluation
The periodic validation loop inside `fit()` in both `lora.py` and `full.py`
correctly reduces the validation loss across all Fabric devices:
val_loss_tensor = val_loss.detach().clone().to(fabric.device)
fabric.all_reduce(val_loss_tensor, reduce_op="mean")
However, the **initial validation** (run once before training) and the
**final validation** (run once after training) were missing this step.
In a multi-GPU run the logged and printed loss values would only reflect
rank-0'\''s local data slice, producing incorrect (and non-reproducible)
metrics.
Fix: apply the same `detach / clone / all_reduce` pattern to both the
initial and final validation blocks in `lora.py` and `full.py`. The
`adapter.py` and `adapter_v2.py` variants do not have an
`initial_validation` / `final_validation` guard so they are unaffected.
Fixes Lightning-AI#2116
Signed-off-by: NIK-TIGER-BILL <nik.tiger.bill@github.com>
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 does this PR do?
Fixes #2116
Both
lora.pyandfull.pyhave three validation checkpoints:eval.intervalsteps)fabric.all_reduce(…, reduce_op="mean")In a multi-GPU run this means the initial and final validation metrics only reflect the local data slice of rank-0, which is both incorrect and non-reproducible.
Fix: Apply the same
detach / clone / all_reducepattern used in the periodic loop to both the initial and final validation blocks inlora.pyandfull.py.Before submitting
finetunescripts do not accumulate over devices #2116