{"record":{"id":"92b30d649da1a370","repo":"tracel-ai/burn","slug":"other-reduction-is-not-supported-92b30d","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/lp_loss.rs","lineNumber":151,"sourceCode":"    /// A scalar tensor containing the reduced loss value.\n    ///\n    /// # Shapes\n    ///\n    /// - predictions: `[...dims]` - Any shape\n    /// - targets: `[...dims]` - Must match predictions shape\n    /// - output: `[1]` - Scalar loss value\n    pub fn forward<const D: usize>(\n        &self,\n        predictions: Tensor<D>,\n        targets: Tensor<D>,\n        reduction: Reduction,\n    ) -> Tensor<1> {\n        let unreduced_loss = self.forward_no_reduction(predictions, targets);\n\n        match reduction {\n            Reduction::Mean | Reduction::Auto => unreduced_loss.mean(),\n            Reduction::Sum => unreduced_loss.sum(),\n            other => panic!(\"{other:?} reduction is not supported\"),\n        }\n    }\n\n    /// Computes the element-wise loss `|error|^p` without reduction.\n    ///\n    /// # Arguments\n    ///\n    /// * `predictions` - The model's predicted values.\n    /// * `targets` - The ground truth target values.\n    ///\n    /// # Returns\n    ///\n    /// A tensor of the same shape as the inputs, containing `|prediction - target|^p`\n    /// for each element.\n    ///\n    /// # Shapes\n    ///\n    /// - predictions: `[...dims]` - Any shape","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-nn/src/loss/lp_loss.rs#L133-L169","documentation":"Reduction-enum exhaustiveness guard in LpLoss::forward: only Mean/Auto and Sum reductions are supported; any other `Reduction` value passed by the caller panics, indicating an unsupported or unknown reduction variant.","triggerScenarios":"Calling LpLoss::forward(predictions, targets, reduction) (L1/L2 style loss) with Reduction::None or any non-Mean/Auto/Sum variant.","commonSituations":"Migrating PyTorch L1Loss/MSELoss with reduction='none'; a global training-config reduction value reused across losses; expecting None to be valid because other frameworks allow it.","solutions":["Use Reduction::Mean, Reduction::Sum, or Reduction::Auto.","Use LpLoss::forward_no_reduction for the element-wise |error|^p tensor and reduce manually.","Validate reduction settings in the training config loader against the supported set."],"exampleFix":"// before\nlet loss = criterion.forward(pred, target, Reduction::None); // panics\n// after\nlet elem = criterion.forward_no_reduction(pred, target);\nlet loss = elem.mean();","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 Lp loss: {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    criterion.forward(pred, target, reduction.clone())));","preventionTips":["Only use Mean/Auto/Sum with LpLoss::forward.","Use forward_no_reduction + manual reduction for element-wise |error|^p.","Validate reduction once in config parsing.","Add regression tests for each reduction your configs may set."],"tags":["rust","burn","loss","lp-loss","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"}