tracel-ai/burn · error

Reshape of ND block-quantized tensor is not yet supported.

Error message

Reshape of ND block-quantized tensor is not yet supported.

What it means

q_reshape analyzes how the requested reshape interacts with a block-quantized tensor's scales. A general reshape (neither pure broadcast-like prepend nor a split) of a tensor with ND blocks (block_size.len() > 1) would require recomputing block boundaries, which is not implemented, so it panics.

Source

Thrown at crates/burn-cubecl/src/ops/base.rs:382

        &shape_values,
    );
    let action_values =
        analysis_values.action(values.meta.shape(), values.meta.strides(), &shape_values);

    let n_new_dims = shape.num_dims().saturating_sub(curr_shape.num_dims());
    let is_unsqueeze = n_new_dims > 0 && shape[n_new_dims..] == **curr_shape;

    // Check valid reshapes
    if let ReshapeAction::UpdateStrides { .. } = &action_values {
        match analysis_values {
            ReshapeAnalysis::IsContiguous => {
                if let Some(block_size) = scheme.block_size()
                    && block_size.len() > 1
                    && !is_unsqueeze
                {
                    // General reshape (e.g. [32, 4] -> [16, 8]): only valid if
                    // reshaped dimension is aligned with the block boundaries.
                    unimplemented!("Reshape of ND block-quantized tensor is not yet supported.");
                }
            }
            ReshapeAnalysis::Broadcasted => {} // only preprends unit dims
            ReshapeAnalysis::Split => {
                if let Some(block_size) = scheme.block_size()
                    && block_size.len() > 1
                {
                    // Split reshape (e.g. [32, 4] -> [32, 2, 2]): only valid if
                    // reshaped dimension is aligned with the block boundaries.
                    unimplemented!(
                        "Split reshape of ND block-quantized tensor is not yet supported."
                    );
                }
            }
            other => unreachable!("Reshape analysis {other:?} should not update strides."),
        }
    }

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Avoid reshaping ND block-quantized tensors; keep the original shape until after dequantization
  2. Dequantize, reshape, then re-quantize
  3. Use 1D (per-row/per-tensor) block sizes if reshaping is essential
  4. Upgrade burn to check for added ND block reshape support

Example fix

// before
let y = x.reshape([16, 8]); // ND block quant -> panic
// after
let y = x.dequantize().reshape([16, 8]); // reshape in floating point
Defensive patterns

Strategy: validation

Validate before calling

fn nd_block_reshape_safe(scheme: &QuantScheme, is_unsqueeze: bool) -> bool {
    match scheme.block_size() {
        Some(bs) if bs.len() > 1 && !is_unsqueeze => false,
        _ => true,
    }
}

Type guard

fn is_1d_block(scheme: &QuantScheme) -> bool {
    scheme.block_size().map_or(true, |b| b.len() <= 1)
}

Try / catch

// Guard before reshape:
if nd_block_reshape_safe(&scheme, false) { x.reshape(shape) } else { x.dequantize().reshape(shape) }

Prevention

When it happens

Trigger: Calling reshape on a tensor quantized with multi-dimensional block sizes (e.g. block_size [16,4]) where the reshape is a general shape change like [32,4] -> [16,8], and it is not an unsqueeze.

Common situations: Using ND block quantization (e.g. NVFP4-style 2D blocks) and reorganizing tensor shapes between layers; dynamic model code that reshapes activations between ops.

Related errors


AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05). Data as JSON: /api/errors/3b0d81b8ef396b55. Report an issue: GitHub.