{"record":{"id":"fbbdd34551c1936f","repo":"tracel-ai/burn","slug":"other-reduction-is-not-supported-fbbdd3","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/margin_ranking.rs","lineNumber":88,"sourceCode":"    ///\n    /// # Shapes\n    ///\n    /// - first: \\[...dims\\]\n    /// - second: \\[...dims\\]\n    /// - target: \\[...dims\\]\n    /// - output: \\[1\\]\n    pub fn forward<const D: usize>(\n        &self,\n        first: Tensor<D>,\n        second: Tensor<D>,\n        target: Tensor<D>,\n        reduction: Reduction,\n    ) -> Tensor<1> {\n        let loss = self.forward_no_reduction(first, second, 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 inputs and target.\n    ///\n    /// # Shapes\n    ///\n    /// - first: [...dims]\n    /// - second: [...dims]\n    /// - target: [...dims]\n    /// - output: [...dims]\n    pub fn forward_no_reduction<const D: usize>(\n        &self,\n        first: Tensor<D>,\n        second: Tensor<D>,\n        target: Tensor<D>,\n    ) -> Tensor<D> {\n        // -y * (x1 - x2) + margin, then clamp negatives to zero via relu.","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-nn/src/loss/margin_ranking.rs#L70-L106","documentation":"Reduction-enum exhaustiveness guard in MarginRankingLoss::forward: only Mean/Auto and Sum are handled; passing any other `Reduction` variant panics. The failing input is the unsupported reduction argument.","triggerScenarios":"Calling MarginRankingLoss::forward(first, second, target, reduction) with Reduction::None or any unsupported variant.","commonSituations":"Porting PyTorch MarginRankingLoss(reduction='none') pipelines; config-driven reduction values not checked for this loss; assuming parity with frameworks that accept 'none'.","solutions":["Use Reduction::Mean, Reduction::Sum, or Reduction::Auto.","Use MarginRankingLoss::forward_no_reduction and apply your own reduction or per-pair weighting.","Whitelist valid reduction variants when parsing loss configuration."],"exampleFix":"// before\nlet loss = criterion.forward(a, b, target, Reduction::None); // panics\n// after\nlet elem = criterion.forward_no_reduction(a, b, 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 margin ranking: {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(first, second, target, reduction.clone())));","preventionTips":["Use only Mean/Auto/Sum with MarginRankingLoss::forward.","Use forward_no_reduction for per-pair losses and custom weighting.","Gate reduction values at config-load time.","Include unsupported variants in negative tests."],"tags":["rust","burn","loss","margin-ranking","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"}