Skip to content

feat(tt-blockfloat): sequential block-by-block GPTQ calibration - #4009

Merged
Qubitium merged 2 commits into
mainfrom
feat/tt-blockfloat-sequential
Nov 14, 2026
Merged

Qubitium merged 2 commits into
mainfrom
feat/tt-blockfloat-sequential

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

What

quantize_model_blockfloat(..., sequential=True, seqlen=...) runs GPTQ block by block: each decoder block's Hessians come from the outputs of the blocks already quantized before it, so later layers calibrate against the activations they will actually see. The default one-pass mode, where every Hessian comes from the dense model, is unchanged.

flowchart TD
    A["iter_calibration_windows"] --> B["pre-forward hook on block 0<br/>capture hidden + rotary/mask kwargs, stop"]
    B --> C["for each block"]
    C --> D["forward hooks: X^T X per nn.Linear<br/>shared input -> one matmul"]
    D --> E["gptq_solve_blockfloat per linear<br/>block_axis, act_order"]
    E --> F["propagate hidden through the QUANTIZED block"]
    F --> C
    C --> G["embedding RTN onto the grid"]
Loading
  • Side inputs (rotary embeddings, masks) don't depend on the weights, so they are captured once and reused for every block.
  • scripts/tt_quantize_blockfloat.py: --sequential, --seqlen.

Result

Llama-3.2-1B-Instruct, --block-axis out --act-order --sequential --nsamples 128 --seqlen 512 on 4000 neuralmagic calibration rows (bf8 attention/down, bf4 gate/up, bf8 tied embed). CPU fp32 perplexity, 40×512-token windows of held-out text:

model nm held-out GSM8K test
dense 4.523 4.390
published in-axis bf4/bf8 4.635 (+2.5 %) 4.506 (+2.6 %)
out-axis one-pass (#3994) 4.594 (+1.6 %) 4.452 (+1.4 %)
out-axis sequential (this PR) 4.594 (+1.6 %) 4.426 (+0.8 %)

All 113 modules are on the grid, and the checkpoint reloads bit-exactly (logits maxdiff 0.0).

Tests

  • tests/test_tt_blockfloat_out_axis.py: 22 passed. New tests: the first block's quantized weights are identical in sequential and one-pass mode (same inputs reach it), later blocks differ, and sequential does not lose to one-pass on calibration loss. Both block axes are covered.
  • test_tenstorrent_support.py + test_tt_blockfloat_precision.py: 138 passed, 18 skipped. The one failure is the pre-existing test_calibration_hessian_strides_through_the_text, which also fails on main.
  • ruff check clean.

🤖 Generated with Claude Code

quantize_model_blockfloat(sequential=True) quantizes decoder blocks one at a
time and collects each block's Hessians from the outputs of the blocks
already quantized before it (standard GPTQ). The first block's inputs and
side arguments (rotary embeddings, masks) are captured once with a
pre-forward hook; hidden states are then propagated through each quantized
block. The default one-pass mode (every Hessian from the dense model) is
unchanged. seqlen is now a parameter of both modes.

scripts/tt_quantize_blockfloat.py: --sequential, --seqlen.

Llama-3.2-1B-Instruct, out-axis + act-order + sequential, 128 x 512-token
windows (bf8 attn/down, bf4 gate/up, bf8 tied embed), CPU fp32 perplexity on
held-out text: nm 4.594 (+1.6 % over dense 4.523), GSM8K 4.426 (+0.8 % over
4.390); the published in-axis checkpoint was +2.5 % / +2.6 %.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread gptqmodel/utils/tt_blockfloat_quant.py Resolved
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
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