{"record":{"id":"ffe9b245b01bf80a","repo":"tracel-ai/burn","slug":"other-reduction-is-not-supported-ffe9b2","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/hinge_embedding.rs","lineNumber":79,"sourceCode":"    ///\n    /// `Reduction::Auto` behaves as `Reduction::Mean`.\n    ///\n    /// # Shapes\n    ///\n    /// - input:  `[...dims]`\n    /// - target: `[...dims]` (values in `{-1, 1}`)\n    /// - output: `[1]`\n    pub fn forward<const D: usize>(\n        &self,\n        input: Tensor<D>,\n        target: Tensor<D>,\n        reduction: Reduction,\n    ) -> Tensor<1> {\n        let loss = self.forward_no_reduction(input, target);\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\n    /// Compute the loss element-wise for the input and target.\n    ///\n    /// # Shapes\n    ///\n    /// - input:  `[...dims]`\n    /// - target: `[...dims]` (values in `{-1, 1}`)\n    /// - output: `[...dims]`\n    pub fn forward_no_reduction<const D: usize>(\n        &self,\n        input: Tensor<D>,\n        target: Tensor<D>,\n    ) -> Tensor<D> {\n        // y == 1  -> x ;  y == -1 -> max(0, margin - x)\n        let negative = input.clone().neg().add_scalar(self.margin).clamp_min(0.0);\n        let positive_mask = target.equal_scalar(1);","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-nn/src/loss/hinge_embedding.rs#L61-L97","documentation":"Reduction-enum exhaustiveness guard in HingeEmbeddingLoss::forward: only Mean, Auto (treated as Mean), and Sum are implemented; any other `Reduction` variant reaches the fallback arm and panics. It fires when a caller passes a reduction value the loss does not reduce with (typically a newly added enum variant or a bad cast).","triggerScenarios":"Calling HingeEmbeddingLoss::forward(input, target, reduction) with Reduction::None or any unsupported variant.","commonSituations":"Migrating PyTorch HingeEmbeddingLoss(reduction='none'); config-driven reduction values not validated per loss type; assuming all burn losses accept Reduction::None.","solutions":["Use Reduction::Mean, Reduction::Sum, or Reduction::Auto.","Use HingeEmbeddingLoss::forward_no_reduction for element-wise losses and reduce yourself.","Validate the reduction variant against a per-loss whitelist before calling forward."],"exampleFix":"// before\nlet loss = criterion.forward(input, target, Reduction::None); // panics\n// after\nlet elem = criterion.forward_no_reduction(input, 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 hinge embedding: {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(input, target, reduction.clone())));","preventionTips":["Use only Mean/Auto/Sum with HingeEmbeddingLoss::forward.","Prefer forward_no_reduction when you need per-element values.","Centralize reduction validation in one helper used by all losses.","Cover all reduction variants in CI tests."],"tags":["rust","burn","loss","hinge-embedding","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"}