Skip to content

test(calibration): cover real-model left-pad capture parity (#4861) - #4944

Merged
Qubitium merged 1 commit into
mainfrom
root/calib-position-ids-4861
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
root/calib-position-ids-4861

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

Follow-up coverage for #4861, whose fix landed in #4930 (5fb25294f). That PR's tests drive run_input_capture with a recording stand-in and pin the derived position_ids, but nothing checks the symptom that motivated the issue: the layer-0 inputs a real absolute-position model produces for a left-padded calibration row. This adds that end-to-end assertion plus the negative controls the issue asked for.

What Changed

  • New tests/test_calibration_left_pad_positions_4861.py, CPU/fp32, no hub download (hand-built 2-layer, hidden-32 GPT-2 and tiny OPT, plus a tokenizers WordLevel tokenizer).
    • Capture layer-0 inputs at batch_size=1 (reference) and at batch_size=2 with padding_side="left", drop pad slots, require max|diff| < 1e-5.
    • Same for the left-padded final window of calibration_dataset_concat_size packing — the case a collation-only fix could not reach.
    • Negative controls: right padding still matches the unpadded reference; OPT (which derives positions from the mask itself) is unchanged; a forward with no position_ids and no **kwargs is never given the keyword; an unpadded single row is bit-identical with and without the mask; interior zeros keep the running position.
  • No production code change; no test in this file duplicates an existing one.

Tests

Measured with the new file (layer-0 inputs of the real tokens, batch_size=2 vs batch_size=1):

model padding row len max abs diff on unmodified main on main with #4930
tiny-gpt2 right 0 17 0.000e+00 0.000e+00
tiny-gpt2 right 1 10 0.000e+00 0.000e+00
tiny-gpt2 left 0 17 0.000e+00 0.000e+00
tiny-gpt2 left 1 10 7.983e-02 0.000e+00
tiny-gpt2 left, concat_size=24 tail 0 17 8.136e-02 0.000e+00
tiny-opt left 0 17 0.000e+00 0.000e+00
tiny-opt left 1 10 0.000e+00 0.000e+00

The reporter measured 4.255e+00 on row 1 of real gpt2; the fixture is smaller, so the magnitude is smaller while the shift is the same in kind.

CUDA_VISIBLE_DEVICES="" python -m pytest tests/test_calibration_left_pad_positions_4861.py -q
# before #4930: 4 failed, 5 passed
# after  #4930: 9 passed

Related suite (all tests/test_calibration*.py + tests/test_prepare_dataset.py + tests/test_generator_calibration_4307.py, same command):

CUDA_VISIBLE_DEVICES="" python -m pytest tests/test_calibration_padding_mask.py tests/test_prepare_dataset.py \
  tests/test_calibration*.py tests/test_generator_calibration_4307.py -q
# before #4930: 6 failed, 229 passed, 4 skipped
# after  #4930: 2 failed, 237 passed, 4 skipped

The two remaining failures (test_stage_capture_balanced_mode_empty_filter_fallback, test_balanced_mode_fallback_when_input_device_not_in_forward_devices in test_calibration_data_device.py) are pre-existing and identical without this change under CUDA_VISIBLE_DEVICES="": both call torch.cuda and raise RuntimeError: No CUDA GPUs are available before reaching this code.

  • Unit tests have been executed and passed, or the reason they are not applicable is documented.
  • I added a new simple/fast unit test for this change, or documented why that is not applicable.

Model Support / Module Plan

Not applicable: test-only change.

Logic Flow Documentation

Not applicable: no production code change.

Review Requirements

  • Reviewed this PR.
  • Checked that the code matches existing project structure, APIs, and conventions.
  • Avoided unnecessary monkeypatching (the only hook is a register_forward_pre_hook to read layer-0 inputs, removed in a finally).
  • Minimized and compacted the impacted code surface (one new test file).
  • Considered and eliminated potential regressions (test-only; asserts on current main).

Kernel Accuracy Requirements

Not applicable: no kernel or fusion change.

Notes

Refs #4861. The fix itself is already merged as #4930; this PR only strengthens its regression coverage with a real-model parity check and the concat_size tail case.

…er-0 inputs (#4861)

The fix for #4861 landed in #4930 and its tests drive `run_input_capture`
with a recording stand-in.  They pin the derived `position_ids` but never
check the symptom that motivated the issue: the layer-0 inputs a real
absolute-position model produces for a left-padded row.

Add that regression test on a tiny GPT-2 (2 layers, hidden 32, hand-built
tokenizer, CPU/fp32): capture layer-0 inputs at batch_size=1 and at
batch_size=2 with padding_side="left", drop the pad slots, and require
max|diff| < 1e-5.  It also covers the left-padded final window of
`calibration_dataset_concat_size` packing, which the collation-level fix
could not reach, and the negative controls the issue asked for: right
padding still matches, and OPT (which derives positions from the mask
itself) is unchanged.  A model whose forward has no `position_ids` and no
`**kwargs` is never given the keyword, and an unpadded single row stays
bit-identical with and without the mask.

Before the fix this file is red (4 failed, 5 passed); on current main it
is green (9 passed).
@Qubitium
Qubitium merged commit 774916f into main Nov 17, 2026
6 checks passed
@Qubitium
Qubitium deleted the root/calib-position-ids-4861 branch November 17, 2026 19:27
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