Skip to content

test(gpu): move the excluded-device gate onto CalibrationConfig (#4868) - #4919

Merged
Qubitium merged 1 commit into
mainfrom
test/excluded-device-gate-signature
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
test/excluded-device-gate-signature

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4868. Test-only; no library behaviour changed.

What was wrong

tests/test_excluded_device_warmup.py::test_quantize_never_claims_the_excluded_device
is the end-to-end gate for #4320/#4653 ("an excluded GPU gets no context and no
allocations during quantize"). It runs a subprocess script, and that script
still called the pre-#4724 API:

model.quantize(
    calibration,
    batch_size=1,
    backend=BACKEND.TORCH,
    calibration_data_min_length=1,
)

4a871bf (#4724) removed those keywords, so both parametrizations died before
measuring anything:

E  TypeError: BaseQModel.quantize() got an unexpected keyword argument 'batch_size'

The test is gpu/slow/integration and needs two devices, which is why CI
never saw it. The #4653 guarantee had no working test.

Fix

model.quantize(
    CalibrationConfig(dataset=calibration, batch_size=1, min_length=1),
    backend=BACKEND.TORCH,
)

min_length=1 is the old calibration_data_min_length=1; batch_size=1 was
already the CalibrationConfig default but is kept explicit so the two calls
read as a straight translation.

Guard so this cannot recur

The issue suggested a cheap CPU-only check. tests/test_quantize_call_signature_4868.py
parses every module under tests/ and the Python source held in its string
constants, then rejects any quantize() call that still passes a keyword
removed by #4724:

REMOVED_QUANTIZE_KWARGS = {
    "calibration_concat_size", "calibration_sort", "batch_size",
    "calibration_data_min_length", "calibration_concat_separator",
    "calibration_exclude_attention_sinks", "adapter_calibration_dataset",
}

It walks string constants because the broken call lived inside
_EXCLUDED_DEVICE_SCRIPT, which a plain tests/**/*.py scan cannot see. Two
extra cases keep the guard honest: one asserts the scan actually reaches that
embedded script, and one asserts the gate's quantize() call passes a
CalibrationConfig.

Red / green

Red, origin/main @ 985e5ab, gate script unchanged:

$ CUDA_VISIBLE_DEVICES=7,1 pytest test_excluded_device_warmup.py::test_quantize_never_claims_the_excluded_device -q
E   TypeError: BaseQModel.quantize() got an unexpected keyword argument 'batch_size'
2 failed in 40.82s

$ pytest test_quantize_call_signature_4868.py -q
E   test_excluded_device_warmup.py::_EXCLUDED_DEVICE_SCRIPT:46: quantize(..., batch_size=...)
E   test_excluded_device_warmup.py::_EXCLUDED_DEVICE_SCRIPT:46: quantize(..., calibration_data_min_length=...)
2 failed, 1 passed

Green, same host, with the fix:

$ CUDA_VISIBLE_DEVICES=7,1 pytest test_excluded_device_warmup.py::test_quantize_never_claims_the_excluded_device -q
2 passed in 35.09s

$ pytest test_quantize_call_signature_4868.py -q
3 passed in 17.79s

The gate's own assertions are what matter here — it now reaches them:

Assertion Meaning
payload["before"] is False the excluded GPU had no context before quantize
payload["peak1"] > 0 the permitted device did quantize
payload["claimed"] is False the excluded GPU still has no primary context
payload["peak0"] == 0 the excluded GPU got zero allocations

Both routes pass: compute_device_filter and device=("cuda:1",).

Validation

$ pytest test_quantize_call_signature_4868.py -q
3 passed

$ CUDA_VISIBLE_DEVICES=7,1 CUDA_DEVICE_ORDER=PCI_BUS_ID \
  pytest test_excluded_device_warmup.py -q
17 passed in 57.31s

ruff check passes on both changed files.

No logic-flow diagram

This changes no control flow, selection order or tensor lifecycle: it repairs a
test's call site and adds a static check over test sources.

Claim: agent-11788dff99fd, workload 765991797ab1.

tests/test_excluded_device_warmup.py::test_quantize_never_claims_the_excluded_device
is the end-to-end gate for #4320/#4653, but its subprocess script still called
quantize() with batch_size= and calibration_data_min_length=, both removed by
#4724. Both parametrizations raised TypeError before measuring anything, so the
"excluded GPU stays unclaimed" guarantee had no working test. The test is
gpu/slow/integration and needs two devices, which is why CI never saw it.

The script now passes CalibrationConfig(dataset=..., batch_size=1, min_length=1).

tests/test_quantize_call_signature_4868.py is the CPU-only guard: it parses
every module under tests/ and the Python source held in its string constants
(where the broken call lived) and rejects any quantize() call that passes a
keyword removed by #4724. Two extra cases keep the scan honest - it must reach
the embedded gate script, and that script's quantize() must pass a
CalibrationConfig.

Red: 2 failed (TypeError) on the gate, 2 failed in the new guard.
Green: 2 passed on the gate, 17 passed for the file, 3 passed in the guard.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant