Repository navigation
perf(looper): reuse the native first-layer capture for GPTAQ/FOEM (#5831) - #5890
Merged
Merged
Conversation
Qubitium
marked this pull request as ready for review
November 20, 2026 11:39
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.
Summary
InputCache.What Changed
gptqmodel/looper/module_looper.py:_loop_impl()asks_reusable_initial_capture()before runningcache_inputsfor a processor. When it returns the native capture, the GPTQ processor receivescopy.deepcopy(capture)and the second model forward is skipped. The clone gives each stream private replay state because per-layer kwargs and hidden frontiers diverge as the native and quantized passes advance._reusable_initial_capture()requires: previous processor isNativeProcessor, current isGPTQProcessorwithgptaq/foemactive, identicalcalibration_datasetobject (a distinct adapter/rotation dataset still captures its own), a generic model capture path, and a plain non-emptyInputCache._model_initial_capture_is_generic()compares every capture hook (run_input_capture, the pre-quantize hooks, input/example capture hooks, first-layer positional/kwargs capture, andbuild_quantization_input_cache) againstBaseQModel. Models with vision staging, looped-decoder capture, or custom positional inputs keep the old second capture until qualified.tests/test_gptaq_foem_first_capture_5831.py: 6 tests — one capture per batch for GPTAQ and FOEM, bitwise-equal packed tensors against a forced double capture, the reused cache being a distinct tensor copy, and a capture-hook override disabling reuse.No config, packing, kernel, or model-definition changes.
Tests
Red evidence on base
0e0c85066with the same test file and unfixed library: 4 failed, 2 passed — both per-batch capture counts (32 instead of 16) and both bitwise comparisons (the reuse hook does not exist). The two guard tests pass on both revisions by design.Environment note:
tests/test_gptaq_shuffle_pairing_4869.pyfails identically on base and head in this CPU/MPS host (Device not in pool: mps:0), so it could not be used as a local regression signal. No CUDA host was available; CUDA suites were skipped.Measured Impact
Fixture: 2-layer FP16 Llama (hidden 64), 16 variable-length calibration rows (88-118 tokens),
batch_size=1,sort="shuffle", GPTAQ and FOEM (alpha=0.25) in separate runs. Apple Silicon macOS, CPU, torch 2.15.0, transformers 5.23.0,torch.set_num_threads(1),offload_to_disk=Falsefor the timing fixture. Median of 5 interleaved before/after runs per config. "Capture phase" is the summedModuleLooper.cache_inputswall time plus the replacement clone; the after value is capture + clone.cache_inputscalls per run (count)cache_inputscalls per run (count)Accuracy: the reused path and the forced double-capture path produce byte-identical packed tensors for GPTAQ and FOEM (77 tensors each, compared as
uint8views). The quantized weights are therefore unchanged; only the redundant forward disappears. VRAM was not measured: the clone's transient host copy matches the allocation the skipped second capture would have made, so peak host memory is expected to be unchanged, but that was not instrumented.Benchmark method: a local script that wraps
ModuleLooper.cache_inputsandcopy.deepcopywith timers and runs the same fixture with reuse enabled and with_reusable_initial_captureforced to returnNone; base0e0c85066, heada09de1f5b.Model Support / Module Plan
Not applicable — no
MODEL_MAPentries, model definitions, aliases, or fusion configs change.Logic Flow Documentation
ModuleLooper._loop_implpreviously calledcache_inputsfor every processor whose dataset verification passed, so GPTAQ/FOEM forwarded every batch once forNativeProcessorand again forGPTQProcessor. The new_reusable_initial_capturebranch runs before that call and reuses the native capture only when the ownership, dataset-identity, model-hook, and cache-shape checks above all pass. The branch is skipped for every other processor chain (plain GPTQ, EoRA, AWQ/Paro, looped decoders, vision models with capture overrides), which keeps the existing capture path unchanged.Review Requirements