tracel-ai/burn · error
Either output_size or scale_factor must be provided
Error message
Either output_size or scale_factor must be provided
What it means
Interpolate1d's `calculate_output_size` requires the config to specify either an explicit output size or a scale factor; the match on the size enum has no other arms, so any other/none configuration panics. It fires when neither `Interpolate1dConfig::Output` nor `::Scale` was provided.
Source
Thrown at crates/burn-nn/src/modules/interpolate/interpolate1d.rs:160
) -> usize {
match (output_size, scale_factor) {
(Some(output_size), None) => {
// Use provided
output_size
}
(None, Some(scale_factor)) => {
// Calculate output size based on scale factor
let [_, _, l] = input_dims;
let new_dim = (l as f64) * (scale_factor as f64);
if new_dim > usize::MAX as f64 {
panic!("Scale factor is too large");
}
new_dim as usize
}
_ => panic!("Either output_size or scale_factor must be provided"),
}
}
impl ModuleDisplay for Interpolate1d {
fn custom_settings(&self) -> Option<DisplaySettings> {
DisplaySettings::new()
.with_new_line_after_attribute(false)
.optional()
}
fn custom_content(&self, content: Content) -> Option<Content> {
content
.add_debug_attribute("mode", &self.mode)
.add("output_size", &format!("{:?}", self.output_size))
.add("scale_factor", &self.scale_factor)
.optional()
}
}View on GitHub (pinned to d16f7ba2ed)
Solutions
- Construct with an explicit size: `Interpolate1d::new(Interpolate1dConfig::Output(len))` or `Interpolate1dConfig::Scale(factor)`.
- Check that deserialized configs include exactly one of output_size/scale_factor before use.
- Avoid `..Default::default()` overriding the size field when building the config.
Example fix
// before let interp = Interpolate1d::new(Interpolate1dConfig::default()); // neither set // after let interp = Interpolate1d::new(Interpolate1dConfig::Output(256)); // or let interp = Interpolate1d::new(Interpolate1dConfig::Scale(2.0));
Defensive patterns
Strategy: validation
Validate before calling
fn interpolate_config_is_set(config: &Interpolate1dConfig) -> bool {
matches!(config, Interpolate1dConfig::Output(_) | Interpolate1dConfig::Scale(_))
}
assert!(interpolate_config_is_set(&config), "Interpolate1dConfig must set Output or Scale"); Type guard
fn has_size_spec(config: &Interpolate1dConfig) -> bool {
matches!(config, Interpolate1dConfig::Output(_) | Interpolate1dConfig::Scale(_))
} Try / catch
let result = std::panic::catch_unwind(|| interpolate.forward(input));
match result {
Ok(out) => out,
Err(_) => Interpolate1d::new(Interpolate1dConfig::Scale(1.0)).forward(input), // identity fallback
} Prevention
- Never construct Interpolate1d from a bare default config; always set Output or Scale.
- Watch for `..Default::default()` wiping the size field in struct-update syntax.
- Validate deserialized interpolate configs contain a size spec before building the module.
When it happens
Trigger: Constructing Interpolate1d with a default/empty config (neither Output nor Scale set) and calling forward, causing calculate_output_size to fall through to the catch-all panic.
Common situations: Using `Interpolate1d::default()` or `..Default::default()` in struct update syntax that wipes out the size setting; deserializing an incomplete config where the size field is missing; copying a builder pattern and forgetting the final size setter.
Understand the failure class
Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.
Related errors
- Both channels must be divisible by the number of groups. Got
- Channels must be divisible by the number of groups. Got chan
- Dropout probability should be between 0 and 1, but got {}
- Scale factor is too large
- Standard deviation is required to be non-negative, but got {
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/de7612446a3366bc.
Report an issue: GitHub.