Skip to content

test: align post-reload max_error_count with pre-reload check in test_optimizer32bit - #2093

Open
CS-liujf wants to merge 1 commit into
bitsandbytes-foundation:mainfrom
CS-liujf:fix/lion-reload-threshold
Open

CS-liujf wants to merge 1 commit into
bitsandbytes-foundation:mainfrom
CS-liujf:fix/lion-reload-threshold

Conversation

@CS-liujf

Copy link
Copy Markdown

Description

test_optimizer32bit checks bnb-vs-torch parameter closeness twice per step: once right after the optimizers step, and again immediately after the state_dict save/load roundtrip that runs every k // 5 steps.

Commit 36f5c4f raised the first check's max_error_count from 10 to 15 (to tolerate Lion's noisy boundary updates) but left the post-reload copy at 10.

These two assertions measure bit-identical data: between them only state_dict(), optimizer re-creation and load_state_dict() run, and load_state_dict restores optimizer state without ever touching parameters (state tensors are cast/copied; params are only used as keys). The mismatch count after the roundtrip therefore always equals the count measured just before it.

With the thresholds out of sync, a step producing 11-15 mismatched elements passes the first check but fails the second whenever it coincides with a checkpoint iteration (i % (k // 5) == 0) — a flake that misleadingly points at the state_dict roundtrip instead of the Lion noise that 36f5c4f explicitly decided to tolerate.

This PR sets the post-reload threshold to 15 to match. The state-buffer comparison below it is a different measurement (the 32-bit state roundtrip is byte-exact and already asserted strictly before the reload), so it is left unchanged.

Changes

  • tests/test_optim.py: max_error_count 10 → 15 in the post-reload parameter assertion of test_optimizer32bit (comment updated to match)

Test-only change; no production code touched.

Commit 36f5c4f raised the max_error_count of the parameter comparison
after each optimizer step from 10 to 15 to tolerate Lion's noisy
boundary updates, but did not update the identical comparison that runs
right after the state_dict save/load roundtrip, which still allows
only 10.

Both assertions compare the same tensors: between them only
state_dict(), optimizer recreation and load_state_dict() run, and
load_state_dict restores optimizer state without touching parameters.
The mismatch count after the roundtrip is therefore identical to the
one measured before it. With the thresholds out of sync, a step
producing 11-15 mismatched elements passes the first check but fails
the second, misleadingly pointing at the state_dict roundtrip instead
of the tolerated Lion noise.

Set the post-reload threshold to 15 to match.

This branch has not been deployed

No deployments
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.

1 participant