{"record":{"id":"b8ba9f18f20c5a97","repo":"tracel-ai/burn","slug":"other-reduction-is-not-supported-b8ba9f","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/smooth_l1.rs","lineNumber":165,"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_with_reduction<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(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 smooth L1 loss with reduction over specified dimensions.\n    ///\n    /// Calculates element-wise smooth L1 loss, then takes the mean\n    /// over the specified dimensions. Useful for per-sample or per-channel losses.\n    ///\n    /// Dimensions can be provided in any order.\n    ///\n    /// # Arguments\n    ///\n    /// - `predictions` - The model's predicted values.\n    /// - `targets` - The ground truth target values.\n    /// - `dims` - Dimensions to reduce over.\n    ///   Negative dimensions are supported and count from the end.\n    ///\n    /// # Returns","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-nn/src/loss/smooth_l1.rs#L147-L183","documentation":"SmoothL1Loss's `forward_with_reduction` only supports Mean, Auto (as Mean), and Sum reductions; any other Reduction variant panics in the catch-all arm. The reduced API returns a scalar `Tensor<1>`, so unsupported modes cannot be honored.","triggerScenarios":"Calling `SmoothL1Loss::forward_with_reduction(predictions, targets, reduction)` with a Reduction value outside {Mean, Auto, Sum}, most often Reduction::None.","commonSituations":"Sharing a reduction enum across multiple losses where one supports None and others do not; config deserialization producing an unexpected variant; refactoring to a newer burn version that extended the Reduction enum.","solutions":["Use Reduction::Mean, Reduction::Auto, or Reduction::Sum.","Call `SmoothL1Loss::forward(predictions, targets)` to get the element-wise (unreduced) loss.","Guard user/config-supplied Reduction values before invoking."],"exampleFix":"// before\nlet loss = smooth_l1.forward_with_reduction(pred, target, Reduction::None);\n// after\nlet elemwise = smooth_l1.forward(pred, target); // unreduced\nlet loss = elemwise.mean();","handlingStrategy":"validation","validationCode":"fn is_supported_reduction(r: &Reduction) -> bool {\n    matches!(r, Reduction::Mean | Reduction::Auto | Reduction::Sum)\n}\nassert!(is_supported_reduction(&reduction));","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(|| smooth_l1.forward_with_reduction(pred, target, reduction));\nmatch result {\n    Ok(loss) => loss,\n    Err(_) => smooth_l1.forward(pred, target).mean(),\n}","preventionTips":["Call SmoothL1Loss::forward directly when reduction='none' semantics are wanted.","Centralize reduction mapping in one helper tested against all losses.","Validate configs at deserialization time."],"tags":["rust","panic","loss-function","unsupported-argument"],"backgroundTag":"unsupported-reduction-mode","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"}