tracel-ai/burn · error

deserialize_bytes is not implemented

Error message

deserialize_bytes is not implemented

What it means

The nested-value deserializer panics on `deserialize_bytes` because NestedValue cannot represent raw byte sequences (only typed vectors/strings). Serde calls this method for `Vec<u8>`-like targets (bytes fields), hitting the deliberate unimplemented!().

Source

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

        unimplemented!("deserialize_char is not implemented")
    }

    fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        match self.value {
            Some(NestedValue::String(val)) => visitor.visit_str(&val),
            Some(other) => Err(custom_err(format!("expected str but got {other:?}"))),
            None => Err(custom_err("expected str, found nothing")),
        }
    }

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

    fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        match self.value {
            Some(NestedValue::Bytes(bytes)) => match bytes.try_into_vec::<u8>() {
                Ok(bytes) => visitor.visit_byte_buf(bytes),
                Err(bytes) => visitor.visit_bytes(&bytes),
            },
            Some(NestedValue::U8s(bytes)) => visitor.visit_byte_buf(bytes),
            Some(other) => Err(custom_err(format!(
                "expected byte buffer but got {other:?}"
            ))),
            None => Err(custom_err("expected byte buffer, found nothing")),
        }
    }

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Store the bytes as a Vec<u8> of numeric values (deserialized via seq) or as a base64/hex String instead of a byte-buffer type.
  2. Use #[serde(deserialize_with)] to decode a string/array field into the byte buffer you need.
  3. Keep binary payloads out of record items — store them as separate tensors/parameters.
  4. Regenerate the checkpoint to match the supported schema.

Example fix

// before
struct Item { blob: serde_bytes::ByteBuf } // -> deserialize_bytes panic
// after
struct Item { blob_b64: String }
// decode: use base64::decode(&item.blob_b64)
Defensive patterns

Strategy: validation

Validate before calling

// Store bytes as base64 String instead of byte buffers:
fn bytes_from_b64<'de, D: serde::Deserializer<'de>>(d: D) -> Result<Vec<u8>, D::Error> {
    let s = String::deserialize(d)?;
    base64::decode(s).map_err(serde::de::Error::custom)
}
// avoid #[serde(with = "serde_bytes")] in record items

Try / catch

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

Prevention

When it happens

Trigger: Deserializing a record type with a field annotated #[serde(with = "serde_bytes")] or of a byte-buffer type (Vec<u8> routed through deserialize_bytes, Cow<[u8]>, ByteBuf) from Burn nested value data.

Common situations: User-defined record items that embed binary blobs or serialized payloads in checkpoint data; schema changes adding binary fields between Burn versions; attempting to store raw model bytes inside a record item.

Related errors


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