{"record":{"id":"57e378b73b01b5a1","repo":"tracel-ai/burn","slug":"either-output-size-or-scale-factor-must-be-provide-57e378","errorCode":null,"errorMessage":"Either output_size or scale_factor must be provided","messagePattern":"Either output_size or scale_factor must be provided","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-nn/src/modules/interpolate/interpolate2d.rs","lineNumber":159,"sourceCode":"        (None, Some(scale_factor)) => {\n            // Calculate output size based on scale factor\n            let [_, _, h, w] = input_dims;\n\n            let new_dim_h = (h as f64) * (scale_factor[0] as f64);\n\n            if new_dim_h > usize::MAX as f64 {\n                panic!(\"Scale factor for height is too large\");\n            }\n\n            let new_dim_w = (w as f64) * (scale_factor[1] as f64);\n\n            if new_dim_w > usize::MAX as f64 {\n                panic!(\"Scale factor for width is too large\");\n            }\n\n            [new_dim_h as usize, new_dim_w as usize]\n        }\n        _ => panic!(\"Either output_size or scale_factor must be provided\"),\n    }\n}\n\nimpl ModuleDisplay for Interpolate2d {\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)\n            .add(\"output_size\", &format!(\"{:?}\", self.output_size))\n            .add(\"scale_factor\", &self.scale_factor)\n            .optional()\n    }\n}","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-nn/src/modules/interpolate/interpolate2d.rs#L141-L177","documentation":"This panic is the fallback arm of the match in Interpolate2d::calculate_output_size: the Interpolate2d module can only compute its output spatial dimensions if exactly one of output_size or scale_factor was set in the config. When neither is provided (both None, matched by the `_` arm) the library cannot proceed and panics. It is a configuration-completeness check at forward time.","triggerScenarios":"Constructing Interpolate2dConfig::new() without calling with_output_size(...) or with_scale_factor(...) and then calling forward on the resulting module. Also occurs when a config builder was created but the sizing option was set on the wrong config instance, or the value was lost during config (de)serialization.","commonSituations":"Boilerplate configs copied from examples where the sizing call was deleted, conditional code paths that forgot to set the option, migrating from another library (e.g. PyTorch's F.interpolate) where the mode/size arguments are optional at construction time, or deserializing a config from an older format that lacked these fields.","solutions":["Set the upsampling strategy explicitly: call .with_output_size([h, w]) or .with_scale_factor([sh, sw]) on the Interpolate2dConfig before init().","If the config comes from a file/network, validate on load that exactly one of the two fields is present.","Check that you are mutating the same config instance you pass to init (not a cloned/stale copy)."],"exampleFix":"// before\nlet cfg = Interpolate2dConfig::new();\nlet interpolate = Interpolate2d::new(&cfg); // panics on forward\n// after\nlet cfg = Interpolate2dConfig::new().with_scale_factor([2.0, 2.0]);\nlet interpolate = Interpolate2d::new(&cfg);","handlingStrategy":"validation","validationCode":"// call before init()/forward\nassert!(\n    config.output_size.is_some() ^ config.scale_factor.is_some(),\n    \"set exactly one of output_size or scale_factor\"\n);","typeGuard":"fn has_sizing(config: &Interpolate2dConfig) -> bool {\n    config.output_size.is_some() || config.scale_factor.is_some()\n}","tryCatchPattern":"let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| module.forward(input)));\nif result.is_err() {\n    eprintln!(\"Interpolate2d config missing output_size/scale_factor\");\n}","preventionTips":["Always chain the sizing option at the construction site: Interpolate2dConfig::new().with_scale_factor([...]) in one expression.","Add a unit test that constructs every model config and calls forward on a dummy tensor.","When deserializing configs, validate that the sizing field is present before building the module."],"tags":["rust","burn-nn","panic","config","interpolate2d"],"backgroundTag":"missing-required-config","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"}