tracel-ai/burn · error

Not yet implemented for iteration

Error message

Not yet implemented for iteration

What it means

TensorData::iter::<E>() (crates/burn-std/src/data/tensor/conversion.rs:203-210) supports iterating quantized data only for symmetric schemes with Q8/Q4/Q2 values. For symmetric float-point quantization (E4M3, E5M2, E2M1) iteration/element-casting is explicitly not implemented, so an `unimplemented!` panic is raised instead of returning an iterator.

Source

Thrown at crates/burn-std/src/data/tensor/conversion.rs:209

                            shape: self.shape.clone(),
                        };
                        let (values, _) = q_bytes.into_vec_i8();

                        Box::new(
                            values
                                .iter()
                                .map(|e: &i8| e.elem::<E>())
                                .collect::<Vec<_>>()
                                .into_iter(),
                        )
                    }
                    QuantScheme {
                        mode: QuantMode::Symmetric,
                        value:
                            QuantValue::E4M3 | QuantValue::E5M2 | QuantValue::E2M1,
                        ..
                    } => {
                        unimplemented!("Not yet implemented for iteration");
                    }
                    QuantScheme {
                        mode: QuantMode::Lookup,
                        ..
                    } => {
                        unimplemented!("lookup quantization is not supported for iteration");
                    }
                },
            }
        }
    }

    /// Converts the data to the dtype represented by `E`.
    ///
    /// # Panics
    ///
    /// Panics if storage access fails, the conversion isn't supported, or the stored
    /// representation or element count is invalid.

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Dequantize the tensor to a float dtype first (use the dequantize API) and iterate the resulting float tensor.
  2. Use Q8S/Q8F (int8) quantization schemes if element-wise iteration is required.
  3. Upgrade burn once float-point quantized iteration support lands; check the changelog.
  4. Manually decode E4M3/E5M2/E2M1 bits from the raw bytes yourself.

Example fix

// before
for v in q_tensor_data.iter::<f32>() { /* panics */ }
// after
let f_data = q_tensor.dequantize(); // returns float TensorData
for v in f_data.iter::<f32>() { /* ok */ }
Defensive patterns

Strategy: type-guard

Validate before calling

fn is_iterable_quantized(dtype: &DType) -> bool {
    match dtype {
        DType::QFloat(s) => matches!(
            s,
            QuantScheme { mode: QuantMode::Symmetric, value: QuantValue::Q8F | QuantValue::Q8S | QuantValue::Q4F | QuantValue::Q4S | QuantValue::Q2F | QuantValue::Q2S, .. }
        ),
        _ => true,
    }
}

Type guard

fn iterable_q_scheme(scheme: &QuantScheme) -> bool {
    matches!(scheme.mode, QuantMode::Symmetric)
        && !matches!(scheme.value, QuantValue::E4M3 | QuantValue::E5M2 | QuantValue::E2M1)
}

Try / catch

// iter panics instead of returning Err; check the scheme first, else dequantize
if iterable_q_scheme(&scheme) {
    let vals: Vec<f32> = data.iter::<f32>().collect();
} else {
    let vals: Vec<f32> = dequantize_to_float(data).iter::<f32>().collect();
}

Prevention

When it happens

Trigger: Calling `tensor_data.iter::<E>()` (or code paths like into_vec_i8-driven iteration / morph_impl that rely on it) on a QFloat TensorData whose scheme is Symmetric with QuantValue::E4M3, E5M2, or E2M1.

Common situations: Converting an FP8/FP4-quantized tensor to plain floats by iterating elements, e.g. `data.iter::<f32>()`, after quantizing with an E4M3 scheme, or running a tensor morph/conversion pipeline over float-point-quantized data.

Related errors


AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05). Data as JSON: /api/errors/968d9abd80e600f2. Report an issue: GitHub.