{"record":{"id":"b5cb570e6a7cc611","repo":"tracel-ai/burn","slug":"invalid-broadcast-shapes-next-grad-shape-pr","errorCode":null,"errorMessage":"Invalid broadcast shapes: Next grad shape {:?}, Previous grad shape {:?}. Expected the shape of the next grad to be 1.","messagePattern":"Invalid broadcast shapes: Next grad shape (.+?), Previous grad shape (.+?)\\. Expected the shape of the next grad to be 1\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-autodiff/src/ops/base.rs","lineNumber":317,"sourceCode":"    }\n\n    fn distributed_params(&self) -> Option<DistributedParams> {\n        self.ops.node.distributed_params.clone()\n    }\n}\n\n/// Make sure the grad tensor has the given shape.\n///\n/// If broadcasting happened during the forward pass, the gradients will be sum along the\n/// broadcasted dimension.\npub fn broadcast_shape<B: Backend>(mut grad: FloatTensor<B>, shape: &Shape) -> FloatTensor<B> {\n    let shape_grad = grad.shape();\n    let ndims = shape_grad.num_dims();\n\n    for i in 0..ndims {\n        if shape_grad[i] != shape[i] {\n            if shape[i] != 1 {\n                panic!(\n                    \"Invalid broadcast shapes: Next grad shape {:?}, Previous grad shape {:?}. {}\",\n                    shape, shape_grad, \"Expected the shape of the next grad to be 1.\"\n                );\n            }\n            grad = B::float_sum_dim(grad, i);\n        }\n    }\n\n    grad\n}\n","sourceCodeStart":299,"sourceCodeEnd":328,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-autodiff/src/ops/base.rs#L299-L328","documentation":"read_tensor_async in the router interpreter can read Float, Int, and Bool tensors, but has no path for quantized (DType::QFloat — todo!) or any other dtype (unimplemented!). Reading such a tensor's data panics.","triggerScenarios":"Calling read_tensor_async (used by into_data/read APIs on routed backends) on a tensor whose dtype is QFloat or otherwise not Float/Int/Bool.","commonSituations":"Inspecting/serializing a quantized tensor's data through a router backend (e.g. during quantized model export or debugging); quantization support not yet wired into the router's read path.","solutions":["Dequantize the tensor to float first (via dequantize ops on a concrete backend), then read its data.","Avoid read_tensor_async on quantized tensors; keep quantized tensors opaque and read only their float counterparts.","Check tensor.dtype before reading and branch accordingly; wait for upstream QFloat read support if quantized reads are required."],"exampleFix":"// before\nlet data = q_tensor.into_data(); // panics in read_tensor_async\n// after\nlet f_tensor = my_backend::dequantize(q_tensor, FloatDType::F32);\nlet data = f_tensor.into_data();","handlingStrategy":"validation","validationCode":"fn readable_dtype(dtype: &burn_tensor::DType) -> bool {\n    !matches!(dtype, burn_tensor::DType::QFloat(_))\n}\n// call before read_tensor_async / into_data","typeGuard":"fn is_quantized(dtype: &burn_tensor::DType) -> bool {\n    matches!(dtype, burn_tensor::DType::QFloat(_))\n}","tryCatchPattern":"std::panic::catch_unwind(std::panic::AssertUnwindSafe(||\n    read_tensor_async::<B, _>(ctx, desc)\n)).map_err(|_| anyhow::anyhow!(\"reading quantized tensor data is not supported; dequantize first\"))","preventionTips":["Dequantize before calling into_data/read_tensor_async.","Do not call data-reading APIs on quantized tensors under burn-router.","Check tensor.dtype prior to any read.","Track upstream burn-router progress on QFloat read support."],"tags":["rust","burn-router","quantization","tensor-read","unimplemented"],"backgroundTag":"unsupported-dtype","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}