Skip to content

fix(finetune): all_reduce val loss across devices for initial and final validation#2266

Open
discobot wants to merge 1 commit into
Lightning-AI:mainfrom
discobot:fix/2116-finetune-val-loss-all-reduce
Open

fix(finetune): all_reduce val loss across devices for initial and final validation#2266
discobot wants to merge 1 commit into
Lightning-AI:mainfrom
discobot:fix/2116-finetune-val-loss-all-reduce

Conversation

@discobot

Copy link
Copy Markdown

Fixes #2116.

The missing reduction for the initial and final validation is not limited to lora.py and full.pyadapter.py and adapter_v2.py have the same three validation paths, so this fixes all four finetune scripts.

The stale val_loss in the training progress line has a concrete mechanism: the periodic eval reduces into a temporary val_loss_tensor and never assigns it back, so the val: column keeps showing the rank-local value from the latest validate() call. The fix reduces via the tensor returned by Fabric.all_reduce (the documented reduced result) and reassigns it to val_loss, so the printed and logged values agree everywhere. At world_size == 1 the reduction is a no-op, so single-device runs are unchanged.

Each script gets a CPU regression test that stubs Fabric.all_reduce to make the reduced loss distinguishable from the rank-local one and asserts that the initial, periodic, and final validation losses — as well as the val: column of the progress lines — all report the reduced value. The new tests fail on main and pass with this change; the full tests/test_lora.py, tests/test_full.py, tests/test_adapter.py, and tests/test_adapter_v2.py suites pass locally. I also verified the validateall_reduce pattern in a 2-process gloo CPU run: both ranks report the cross-rank mean.

…al validation

The initial and final validation in the four finetune scripts logged the rank-local loss without reducing it across devices, unlike the periodic validation. The periodic validation also reduced into a temporary tensor that was never assigned back to val_loss, so the training progress lines kept reporting the rank-local value. Reduce the loss in all three places, using the tensor returned by Fabric.all_reduce, and reuse it in the progress lines. All reductions are no-ops on a single device. Adds a CPU regression test per script that stubs Fabric.all_reduce and asserts every printed and logged val loss is the reduced value.
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.

Initial and final evaluation in finetune scripts do not accumulate over devices

1 participant