Skip to content

fix(paro): join mixed-shape calibration captures on the row axis (#5198) - #5234

Merged
Qubitium merged 1 commit into
mainfrom
fix/paro-mixed-shape-capture-5198
Nov 18, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/paro-mixed-shape-capture-5198

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

What

ParoProcessor._layer_input_features joined per-batch captures with torch.cat(tensors, dim=0) and, on the resulting RuntimeError, silently kept tensors[0].

Each capture is [1, rows_b, hidden] (or [bs, seq_b, hidden]), so dim=0 only lines up when every batch has the same row count. Routed MoE experts always have different token counts per batch, and any dense layer with one calibration row shorter than the per-batch quota (#5175) hits it too. The module was then optimized on the first calibration batch only — no error, no warning.

Change

Flatten every non-empty capture to rows x hidden and join on the row axis, then let the existing target_rows cap apply:

rows = [t.reshape(-1, t.shape[-1]) for t in tensors if t.numel() > 0]
features[name] = torch.cat(rows, dim=0).unsqueeze(0) if rows else torch.empty(0)
  • No error is swallowed any more; a shape that cannot be flattened to rows raises.
  • Empty captures are skipped instead of forcing the old fallback.
  • The returned rank stays [1, rows, hidden], so the downstream optimizer contract is unchanged.

Tests

  • tests/test_paro_mixed_batch_rows_5198.py (new): mixed row counts keep every batch in calibration order, the target_rows cap still applies after joining, and empty captures are skipped.
  • tests/test_paro_capture_order.py: updated to the row-axis contract (order and values unchanged).
  • Broader tests/test_paro*.py pass except pre-existing JIT/CUDA tests that need a local CUDA toolkit (this host has none).

Follow-up (not in this PR)

The issue also notes that the fixed per-batch quota under-fills rare experts; a per-module reservoir is a separate change and is left for a follow-up.

Fixes #5198

`_layer_input_features` concatenated per-batch captures on the batch axis
and silently fell back to `tensors[0]` when the shapes differed, so every
routed MoE expert (and any dense layer with one short calibration row) was
optimized on the first batch only. Flatten each capture to rows and join
them on the row axis instead; empty captures are skipped rather than
forcing the fallback.
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