{"record":{"id":"ea2fe2095f267c39","repo":"tracel-ai/burn","slug":"other-reduction-is-not-supported-ea2fe2","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/huber.rs","lineNumber":95,"sourceCode":"    ///\n    /// `Reduction::Auto` behaves as `Reduction::Mean`.\n    ///\n    /// # Shapes\n    ///\n    /// - predictions: \\[...dims\\]\n    /// - targets: \\[...dims\\]\n    /// - output: \\[1\\]\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 loss = self.forward_no_reduction(predictions, targets);\n        match reduction {\n            Reduction::Mean | Reduction::Auto => loss.mean(),\n            Reduction::Sum => loss.sum(),\n            other => panic!(\"{other:?} reduction is not supported\"),\n        }\n    }\n    /// Compute the loss element-wise for the predictions and targets.\n    ///\n    /// # Shapes\n    ///\n    /// - predictions: [...dims]\n    /// - targets: [...dims]\n    /// - output: [...dims]\n    pub fn forward_no_reduction<const D: usize>(\n        &self,\n        predictions: Tensor<D>,\n        targets: Tensor<D>,\n    ) -> Tensor<D> {\n        let residuals = targets - predictions;\n        self.forward_residuals(residuals)\n    }\n    /// Compute the loss element-wise for the given residuals.","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-nn/src/loss/huber.rs#L77-L113","documentation":"HuberLoss::forward supports only Mean, Auto, and Sum reductions; any other variant panics. The unreduced element-wise loss (|error| beyond delta is delta*|error|, else 0.5*error^2) is available via forward_no_reduction.","triggerScenarios":"Calling HuberLoss::forward(predictions, targets, reduction) with Reduction::None or any unsupported variant.","commonSituations":"Porting PyTorch HuberLoss/SmoothL1Loss with reduction='none' for per-sample weighting; passing a shared reduction config through; version differences where a previous burn variant accepted None.","solutions":["Use Reduction::Mean, Reduction::Sum, or Reduction::Auto.","Use HuberLoss::forward_no_reduction and apply your own reduction (e.g. .sum(), .mean(), or per-sample weighting).","Constrain the config enum to supported reductions or map unsupported ones explicitly."],"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 huber 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":["Pass only Mean/Auto/Sum to HuberLoss::forward.","Use forward_no_reduction for custom/weighted reductions.","Reject unsupported reduction variants during config load.","Keep a per-loss compatibility table in your config validation."],"tags":["rust","burn","loss","huber","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"}