tracel-ai/burn · error

deserialize_unit is not implemented

Error message

deserialize_unit is not implemented

What it means

The nested-value deserializer does not implement serde's `deserialize_unit` and panics instead. Unit (`()`) and unit-like placeholder fields are not representable in NestedValue, so any record type containing them routes to this deliberate unimplemented!() during load.

Source

Thrown at crates/burn-store/src/nested/de.rs:301

    fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        if let Some(value) = self.value {
            visitor.visit_some(Deserializer::<A>::new(
                value,
                self.default_for_missing_fields,
            ))
        } else {
            visitor.visit_none()
        }
    }

    fn deserialize_unit<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        unimplemented!("deserialize_unit is not implemented")
    }

    fn deserialize_unit_struct<V>(
        self,
        _name: &'static str,
        _visitor: V,
    ) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        unimplemented!("deserialize_unit_struct is not implemented")
    }

    fn deserialize_newtype_struct<V>(
        self,
        _name: &'static str,
        visitor: V,
    ) -> Result<V::Value, Self::Error>

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Remove the unit field from the record struct — it carries no data and cannot round-trip.
  2. Replace () with Option<()> via a custom deserializer, or better, drop it and use a type-level marker (PhantomData handled outside serde).
  3. Regenerate the checkpoint so it matches the supported schema.
  4. If a macro generates the field, adjust the macro or the underlying type definition.

Example fix

// before
struct Item { marker: () } // -> deserialize_unit panic
// after
struct Item { _marker: core::marker::PhantomData<()> } // not serialized
Defensive patterns

Strategy: validation

Validate before calling

// Audit record structs for unit fields; drop them:
// struct Item { data: TensorData }  // no `marker: ()` fields
// PhantomData is fine because serde skips it via derived impls configured with #[serde(skip)]

Try / catch

let record = std::panic::catch_unwind(|| from_nested_value::<MyItem>(value.clone()))
    .map_err(|_| "record contains unit (): not supported by nested deserializer");

Prevention

When it happens

Trigger: Loading a Burn record whose struct contains a field of type `()` (unit), or a unit placeholder produced by some Deserialize impls, via the nested-value recorder path.

Common situations: Record items with phantoms/unit markers; macro-generated code inserting () fields; type changes across Burn versions that turned an optional field into a unit placeholder.

Related errors


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