{"record":{"id":"d2d184ddb95f4689","repo":"tracel-ai/burn","slug":"other-reduction-is-not-supported-d2d184","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/rnnt.rs","lineNumber":113,"sourceCode":"        }\n\n        self.gather_loss(alpha, &lpb, logit_lengths, target_lengths, b)\n    }\n\n    /// Computes RNNT loss with the given reduction. Returns shape `[1]`.\n    pub fn forward_with_reduction(\n        &self,\n        logits: Tensor<4>,\n        targets: Tensor<2, Int>,\n        logit_lengths: Tensor<1, Int>,\n        target_lengths: Tensor<1, Int>,\n        reduction: Reduction,\n    ) -> Tensor<1> {\n        let loss = self.forward(logits, targets, logit_lengths, target_lengths);\n        match reduction {\n            Reduction::Auto | Reduction::Mean => loss.mean(),\n            Reduction::Sum => loss.sum(),\n            other => panic!(\"{other:?} reduction is not supported\"),\n        }\n    }\n\n    /// Gathers `log_prob_blank[B, T, U+1]` and `log_prob_label[B, T, U]` from the full\n    /// log-probability tensor by indexing into the vocab dimension.\n    fn extract_log_probs(\n        &self,\n        log_probs: Tensor<4>,\n        targets: Tensor<2, Int>,\n    ) -> (Tensor<3>, Tensor<3>) {\n        let [b, max_t, max_up1, v] = log_probs.dims();\n        let max_u = max_up1 - 1;\n        let vocab_dim = 3;\n\n        // Blank probabilities: slice log_probs in vocab dim using the blank index\n        let lpb = log_probs\n            .clone()\n            .slice_dim(vocab_dim, self.blank)","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-nn/src/loss/rnnt.rs#L95-L131","documentation":"The RNN-T loss `forward_with_reduction` reduces the per-sequence loss only for Reduction::Auto/Mean and Reduction::Sum; any other variant hits the catch-all arm and panics. It exists because the reduced API always returns a `Tensor<1>` and unsupported reductions have no defined semantics here.","triggerScenarios":"Calling `RnntLoss::forward_with_reduction(logits, targets, logit_lengths, target_lengths, reduction)` with a Reduction variant other than Auto, Mean, or Sum (e.g. Reduction::None).","commonSituations":"Porting code from PyTorch where reduction='none' is valid; wiring a user-supplied reduction enum from config without validating it; a new Reduction variant added upstream that this loss does not handle.","solutions":["Pass Reduction::Mean, Reduction::Auto, or Reduction::Sum.","For unreduced per-sequence losses, call the underlying `forward(...)` method directly instead of forward_with_reduction.","Validate/normalize any deserialized reduction config before calling."],"exampleFix":"// before\nlet loss = rnnt_loss.forward_with_reduction(logits, targets, lens_in, lens_t, Reduction::None);\n// after\nlet loss = rnnt_loss.forward_with_reduction(logits, targets, lens_in, lens_t, Reduction::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(|| rnnt_loss.forward_with_reduction(logits, targets, ll, tl, reduction));\nmatch result {\n    Ok(loss) => loss,\n    Err(_) => rnnt_loss.forward(logits, targets, ll, tl).mean(),\n}","preventionTips":["Normalize external reduction strings ('none') to burn variants or to explicit forward() calls before use.","Wrap loss APIs in your own enum supporting only Mean/Sum.","Keep a test asserting each loss's supported reduction set."],"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"}