tracel-ai/burn · error
ctc_loss_backward: 2 * max_target_len + 1 = {} exceeds the k
Error message
ctc_loss_backward: 2 * max_target_len + 1 = {} exceeds the kernel's shared-memory alpha capacity ({}). Reduce target length or raise SHARED_ALPHA_CAPACITY. What it means
RouterChannel::change_client_backend panics when the tensor description's dtype is neither float, int, nor bool. The router dispatches dtype-specific bridge calls (change_backend_float/int/bool) and has no branch for other dtypes (e.g. QFloat).
Source
Thrown at crates/burn-cubecl/src/kernel/ctc.rs:610
) -> (CubeTensor, CubeTensor, CubeTensor) {
// Manual stride indexing below requires a contiguous physical layout;
// fusion-produced tensors may arrive with layouts that break that
// assumption. No-op when already contiguous.
let log_probs = into_contiguous(log_probs);
let targets = into_contiguous(targets);
let input_lengths = into_contiguous(input_lengths);
let target_lengths = into_contiguous(target_lengths);
let log_probs_shape = log_probs.shape();
let [max_input_length, batch_size, _c] = log_probs_shape.dims::<3>();
let target_shape = targets.shape();
let max_target_len = target_shape.dims::<2>()[1];
let max_l_prime = 2 * max_target_len + 1;
assert!(
max_l_prime as u32 <= SHARED_ALPHA_CAPACITY,
"ctc_loss_backward: 2 * max_target_len + 1 = {} exceeds the kernel's shared-memory \
alpha capacity ({}). Reduce target length or raise SHARED_ALPHA_CAPACITY.",
max_l_prime,
SHARED_ALPHA_CAPACITY,
);
let hw_max = log_probs.client.properties().hardware.max_cube_dim.0;
let cube_dim_x = (max_l_prime as u32).min(hw_max).min(256);
let client = log_probs.client.clone();
let device = log_probs.device.clone();
let f_dtype = log_probs.dtype;
let i_dtype = targets.dtype;
// Pre-fill alpha/beta with -inf so positions the kernel doesn't touch
// (s >= 2U+1, or t outside the valid range for an individual batch
// element) are not read as stale zeros by the gradient composition.
let shape_abt = Shape::new([max_input_length, batch_size, max_l_prime]);
let neg_inf = InputScalar::new(f32::NEG_INFINITY, dtype_to_storage_type(f_dtype));
let alpha_out = crate::ops::numeric::full_device_dtype(View on GitHub (pinned to d16f7ba2ed)
Solutions
- Do not migrate quantized tensors with change_client_backend; dequantize first, move, then re-quantize on the target backend.
- Verify tensor dtype is Float/Int/Bool before attempting backend migration.
- If this stems from a newly added DType variant, update burn-router to add the corresponding change_backend_* bridge branch.
Example fix
// before handle.change_client_backend::<B2>(device); // panics for QFloat // after assert!(!matches!(desc.dtype, DType::QFloat(_))); let float_t = dequantize(q_tensor); let moved = float_t.change_client_backend::<B2>(device);
Defensive patterns
Strategy: validation
Validate before calling
fn can_migrate(dtype: burn_tensor::DType) -> bool {
matches!(dtype, burn_tensor::DType::F32 | burn_tensor::DType::F64
| burn_tensor::DType::I32 | burn_tensor::DType::I64
| burn_tensor::DType::U32 | burn_tensor::DType::U64
| burn_tensor::DType::Bool)
}
// call: assert!(can_migrate(desc.dtype)) before change_client_backend Type guard
fn is_quantized(dtype: &burn_tensor::DType) -> bool {
matches!(dtype, burn_tensor::DType::QFloat(_))
} Try / catch
std::panic::catch_unwind(std::panic::AssertUnwindSafe(||
handle.change_client_backend::<B2>(&device)
)).map_err(|_| anyhow::anyhow!("dtype not supported for backend migration")) Prevention
- Never route QFloat tensors through change_client_backend; dequantize first.
- Check desc.dtype before any cross-backend tensor migration.
- Pin to a burn version matching your dtype usage; new DType variants may lack router branches.
- Write a smoke test migrating each dtype you use.
When it happens
Trigger: Calling change_client_backend (client backend migration, e.g. moving a tensor between backends/devices via register/change_client) on a tensor whose DType is not Float/Int/Bool — practically a quantized (QFloat) tensor.
Common situations: Moving a model containing quantized tensors between backends, or a new DType variant added upstream without updating the router's dtype dispatch chain.
Related errors
- Invalid broadcast shapes: Next grad shape {:?}, Previous gra
- Can't differentiate embedding backward.
- Can't differentiate linear_x_backward.
- Can't differentiate linear_weight_backward.
- Can't differentiate linear_bias_backward.
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/98e8605c71c1dd9c.
Report an issue: GitHub.