{"record":{"id":"053a9468f15a3d3d","repo":"tracel-ai/burn","slug":"scale-factor-is-too-large","errorCode":null,"errorMessage":"Scale factor is too large","messagePattern":"Scale factor is too large","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-nn/src/modules/interpolate/interpolate1d.rs","lineNumber":155,"sourceCode":"/// or if the scale factor is too large\nfn calculate_output_size(\n    input_dims: [usize; 3],\n    output_size: Option<usize>,\n    scale_factor: Option<f32>,\n) -> usize {\n    match (output_size, scale_factor) {\n        (Some(output_size), None) => {\n            // Use provided\n            output_size\n        }\n        (None, Some(scale_factor)) => {\n            // Calculate output size based on scale factor\n            let [_, _, l] = input_dims;\n\n            let new_dim = (l as f64) * (scale_factor as f64);\n\n            if new_dim > usize::MAX as f64 {\n                panic!(\"Scale factor is too large\");\n            }\n\n            new_dim as usize\n        }\n        _ => panic!(\"Either output_size or scale_factor must be provided\"),\n    }\n}\n\nimpl ModuleDisplay for Interpolate1d {\n    fn custom_settings(&self) -> Option<DisplaySettings> {\n        DisplaySettings::new()\n            .with_new_line_after_attribute(false)\n            .optional()\n    }\n\n    fn custom_content(&self, content: Content) -> Option<Content> {\n        content\n            .add_debug_attribute(\"mode\", &self.mode)","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-nn/src/modules/interpolate/interpolate1d.rs#L137-L173","documentation":"Interpolate1d's `calculate_output_size`, when scaling by `scale_factor`, computes `l * scale_factor` as f64 and panics if the result exceeds usize::MAX — i.e. the requested output length cannot be represented as a valid tensor dimension. This guards against absurd scale factors silently overflowing the cast to usize.","triggerScenarios":"Calling Interpolate1d forward with an Interpolate1dConfig::Scale(scale_factor) where `input_length as f64 * scale_factor as f64 > usize::MAX as f64`, e.g. a scale_factor like 1e18 on a long input.","commonSituations":"Passing a percentage (e.g. 200) intending 2.0 and compounding scales; a misparsed config value (NaN-adjacent huge numbers); accidental f64/usize unit mismatch on very large tensors.","solutions":["Use a sane scale_factor (e.g. 2.0 for upsampling) that keeps output size well within usize range.","Prefer specifying an explicit `output_size` instead of a scale factor for very large tensors.","Compute the expected output length yourself and assert it fits in usize before forwarding."],"exampleFix":"// before\nlet interp = Interpolate1d::new(Interpolate1dConfig::Scale(1e18)); // overflow\n// after\nlet interp = Interpolate1d::new(Interpolate1dConfig::Scale(2.0));\n// or explicit\nlet interp = Interpolate1d::new(Interpolate1dConfig::Output(512));","handlingStrategy":"validation","validationCode":"fn validate_scale(input_len: usize, scale_factor: f64) {\n    let out = input_len as f64 * scale_factor;\n    assert!(out.is_finite() && out <= usize::MAX as f64,\n        \"output length {out} exceeds usize range\");\n}\nvalidate_scale(input_len, scale_factor);","typeGuard":"fn output_fits(input_len: usize, scale_factor: f64) -> bool {\n    (input_len as f64 * scale_factor) <= usize::MAX as f64\n}","tryCatchPattern":"let result = std::panic::catch_unwind(|| interpolate.forward(input));\nmatch result {\n    Ok(out) => out,\n    Err(_) => {\n        let interp = Interpolate1d::new(Interpolate1dConfig::Scale(scale_factor.min(4.0)));\n        interp.forward(input)\n    }\n}","preventionTips":["Use modest scale factors (e.g. 2.0); verify the intended semantics (fraction vs percentage).","Prefer explicit Output sizes for large tensors.","Clamp computed output sizes to a sane maximum in your pipeline."],"tags":["rust","panic","interpolation","overflow","shape-mismatch"],"backgroundTag":"dimension-overflow","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"}