{"record":{"id":"d190b0c450df8e79","repo":"tracel-ai/burn","slug":"other-reduction-is-not-supported-d190b0","errorCode":null,"errorMessage":"{other:?} reduction is not supported","messagePattern":"(.+?) reduction is not supported","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-nn/src/loss/mse.rs","lineNumber":40,"sourceCode":"    }\n\n    /// Compute the criterion on the input tensor.\n    ///\n    /// # Shapes\n    ///\n    /// - logits: [batch_size, num_targets]\n    /// - targets: [batch_size, num_targets]\n    pub fn forward<const D: usize>(\n        &self,\n        logits: Tensor<D>,\n        targets: Tensor<D>,\n        reduction: Reduction,\n    ) -> Tensor<1> {\n        let tensor = self.forward_no_reduction(logits, targets);\n        match reduction {\n            Reduction::Mean | Reduction::Auto => tensor.mean(),\n            Reduction::Sum => tensor.sum(),\n            other => panic!(\"{other:?} reduction is not supported\"),\n        }\n    }\n\n    /// Compute the criterion on the input tensor without reducing.\n    pub fn forward_no_reduction<const D: usize>(\n        &self,\n        logits: Tensor<D>,\n        targets: Tensor<D>,\n    ) -> Tensor<D> {\n        logits.sub(targets).square()\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n    use burn::tensor::TensorData;\n","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-nn/src/loss/mse.rs#L22-L58","documentation":"MseLoss::forward supports only Mean, Auto, and Sum reductions; any other Reduction variant panics. MseLoss computes mean squared error element-wise via forward_no_reduction then applies the reduction, so this panic comes from the catch-all arm of the match.","triggerScenarios":"Calling MseLoss::forward(logits, targets, Reduction::None) — e.g. from test_mse_loss or training code expecting per-element MSE — or any reduction value other than Mean/Auto/Sum.","commonSituations":"Porting PyTorch MSELoss(reduction='none') for per-sample or mask-weighted losses; sharing one Reduction config across losses; upgrading burn and finding Reduction::None no longer handled in forward.","solutions":["Use MseLoss::forward_no_reduction(logits, targets) to get the unreduced tensor and call .mean()/.sum() or apply custom weighting yourself.","Pass Reduction::Mean, Reduction::Sum, or Reduction::Auto to forward.","Audit configs/tests for Reduction::None and replace with explicit no-reduction APIs."],"exampleFix":"// before\nlet loss = mse.forward(predictions, targets, Reduction::None); // panics\n// after\nlet per_elem = mse.forward_no_reduction(predictions, targets);\nlet loss = per_elem.mean(); // or custom per-sample reduction","handlingStrategy":"validation","validationCode":"fn ensure_supported(r: &Reduction) -> Result<(), String> {\n    match r {\n        Reduction::Mean | Reduction::Auto | Reduction::Sum => Ok(()),\n        other => Err(format!(\"unsupported reduction for MSE: {other:?}\")),\n    }\n}","typeGuard":"fn is_supported_reduction(r: &Reduction) -> bool {\n    matches!(r, Reduction::Mean | Reduction::Auto | Reduction::Sum)\n}","tryCatchPattern":"let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(||\n    mse.forward(predictions, targets, reduction.clone())));","preventionTips":["Never pass Reduction::None to MseLoss::forward; use forward_no_reduction instead.","For per-sample or mask-weighted MSE, compute it from forward_no_reduction output.","Centralize reduction validation for all losses in one config check.","Update tests (e.g. test_mse_loss) to only use supported variants."],"tags":["rust","burn","loss","mse","reduction"],"backgroundTag":"unsupported-reduction","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"}