Skip to content

feat(sinq): add opt-in two-dimensional tiling - #6614

Merged
Qubitium merged 1 commit into
mainfrom
feat/sinq-2d-tiling
Dec 1, 2026
Merged

Qubitium merged 1 commit into
mainfrom
feat/sinq-2d-tiling

Conversation

@ZX-ModelCloud

Copy link
Copy Markdown
Collaborator

Summary

Adds opt-in tiling_mode="2d" to SINQ. The default remains "1d", so existing checkpoints and quality are unchanged. 2D fits square group_size × group_size tiles along both matrix axes, with partial final row and column blocks fitted as their own tiles. Each tile's row scale is folded into the GPTQ-shaped scales; the input-column scale is stored as sinq_scale with shape [ceil(out_features / group_size), in_features]. 1D keeps the existing [in_features] layout.

This is rebased onto current main and composes with the NF4/NF3 codebook work from #6608: the 2D path reuses the shared tile fit and therefore works with codebook="uniform", "nf4", and "nf3".

What Changed

  • SINQConfig: accept tiling_mode="1d"|"2d", validate it, serialize it, and pass it to the kernel constructor.
  • SINQ.quantize: dispatch to _quantize_1d or _quantize_2d; share tile gating and batch fitting; record tiling_mode and row_tiles in sinkhorn_stats.
  • SinqLinear: carry tiling_mode, validate 1D/2D sinq_scale layouts, pack 2D column scales, apply per-row-block column scales in effective_weight/forward, and declare the 2D checkpoint shape in checkpoint_tensor_rules.
  • Checkpoint paths: module_constructor_config records tiling_mode; dense export applies 2D row-block column scales.
  • Benchmark: sinq_2d config plus --tiling-mode.
  • Tests and docs: 2D tile placement, partial edges, chunk invariance, per-tile gate, Conv1D, pack/forward, checkpoint rules, save/reload, dense export, and device parity; docs include flow diagrams and the A/B table.

Flow

Before (1D default):

flowchart TD
    A["SINQ.quantize"] --> B["one full-width tile per input group"]
    B --> C["Sinkhorn row/column scales"]
    C --> D["affine or codebook fit per row"]
    D --> E["scales: groups x out_features<br/>sinq_scale: in_features"]
Loading

After (mode selects tile geometry and column-scale layout):

flowchart TD
    A["SINQ.quantize"] --> B{"tiling_mode"}
    B -->|"1d"| C["full-width input-group tiles"]
    B -->|"2d"| D["square group_size tiles<br/>plus partial edges"]
    C --> E["Sinkhorn row/column scales"]
    D --> E
    E --> F["affine or codebook fit"]
    F --> G["scales: groups x out_features"]
    G --> H{"tiling_mode"}
    H -->|"1d"| I["sinq_scale: in_features"]
    H -->|"2d"| J["sinq_scale: row_tiles x in_features"]
Loading
Area 1D (default) 2D (opt-in)
Tile geometry [out_features, group_size] [group_size, group_size] plus partial edges
Row scale per output row per input group per output row per 2D tile
Column scale one per input channel one per input channel per output-row block
sinq_scale [in_features] [ceil(out_features / group_size), in_features]
Quantization cost baseline 1.2x to 3.5x slower in the measured sweep
Inference packed GPTQ decode × column scale same decode × one row-block scale

Measured Impact

WikiText-2 PPL, uniform codebook, default gate (gate_scope="group", kurtosis_threshold=10.0), same evaluation windows. Negative change means 2D is better.

Model Bits Group 1D 2D 2D vs 1D
Qwen2.5-0.5B-Instruct 4 128 16.101 16.273 +1.1%
Qwen2.5-0.5B-Instruct 4 64 15.637 15.495 -0.9%
Qwen2.5-0.5B-Instruct 3 128 32.039 29.263 -8.7%
Qwen2.5-0.5B-Instruct 3 64 23.224 24.686 +6.3%
Qwen2.5-0.5B-Instruct 3 256 44.027 40.478 -8.1%
Qwen2.5-0.5B-Instruct 2 128 142,911 114,805 -19.7%
Qwen2.5-1.5B-Instruct 4 64 9.767 9.666 -1.0%
Qwen2.5-1.5B-Instruct 3 128 14.441 14.035 -2.8%

2D wins on the coarser grids and at 3-bit group 128 on both tested models, but loses at 4-bit group 128 and 3-bit group 64, so 1D stays the default. Quantization took 1.2x to 3.5x the 1D time in the sweep (for example 27.9 s vs 8.8 s at 4-bit group 128); peak quantization memory was lower because 2D processes one output-row block at a time. Inference cost is unchanged: the checkpoint still stores packed GPTQ codes and one extra scale row per output block.

Post-merge recheck of the 3-bit group-128 case: 1D 32.039 PPL vs 2D 29.263 PPL, matching the sweep.

Tests

Commands and results (run from the worktree root):

PYTHONPATH=$PWD python -m pytest tests/test_sinq.py -q -p no:cacheprovider
# 97 passed

PYTHONPATH=$PWD python -m pytest tests/test_checkpoint_modules.py tests/test_quantization_lifecycle_contracts.py tests/test_checkpoint_resume_nf12_macaq_4792.py tests/test_config_per_module_validation_4200.py -q -p no:cacheprovider -k 'not test_checkpoint_roles_match_processor_lifecycles'
# 144 passed, 1 deselected

bash format/check.sh
# All checks passed

PYTHONPATH=$PWD python -m pytest tests/test_sinq_gpu.py -q -p no:cacheprovider
# CUDA: 17 passed; ROCm: 17 passed
  • 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.

The deselected node tests/test_quantization_lifecycle_contracts.py::test_checkpoint_roles_match_processor_lifecycles fails identically on unmodified origin/main (tetra declares CheckpointSupport.PRIMARY while the test expects UNSUPPORTED); it is unrelated to this change.

Skipped/unverified: no fused SINQ GEMM is added; 2D uses the same portable Torch decode as 1D, so no new kernel path is claimed.

Model Support / Module Plan

Not applicable: no MODEL_MAP, alias, definition, or module-plan change.

AWQ onboarding safety

Not applicable: no model/alias/definition or AWQ grouping/search/replay/fold change.

Notes for reviewers

  • 2D is opt-in and defaults are unchanged; existing 1D checkpoints load with the original [in_features] scale.
  • 2D composes with NF4/NF3 (covered by a 2D + codebook pack/forward regression), but the A/B table uses the uniform codebook to isolate tiling.
  • Follow-up (out of scope): a fused SINQ GEMM, and A-SINQ.

Comment thread tests/test_sinq.py Fixed
@ZX-ModelCloud
ZX-ModelCloud marked this pull request as ready for review December 1, 2026 07:50
Fit square group_size tiles along both matrix axes for tiling_mode=2d, with partial final row and column blocks handled as their own tiles. Fold each tile's row scale into the GPTQ-shaped scales tensor and store the per-tile input-column scale as [ceil(out_features / group_size), in_features] sinq_scale; 1D checkpoints keep the existing [in_features] layout.

Thread tiling_mode through SINQConfig, module construction/checkpoint restore, SinqLinear pack/forward/effective_weight, and dense checkpoint export. Add a sinq_2d benchmark config and document the A/B results; 1D remains the default.
@Qubitium
Qubitium merged commit cc0c705 into main Dec 1, 2026
6 checks passed
@Qubitium
Qubitium deleted the feat/sinq-2d-tiling branch December 1, 2026 08:28
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.

2 participants