tracel-ai/burn · error
deserialize_any is not implemented
Error message
deserialize_any is not implemented
What it means
Burn's nested-value serde Deserializer (crates/burn-store/src/nested/de.rs) implements only the concrete deserialize_* methods it supports (struct, map, seq, i16, i32, i64, str, etc.) and deliberately panics in deserialize_any. Because the format is not self-describing in a generic way, any type whose Deserialize impl falls back to deserialize_any triggers this panic during record loading.
Source
Thrown at crates/burn-store/src/nested/de.rs:67
let value = self
.value
.ok_or_else(|| custom_err(format!("expected {expected}, found nothing")))?;
match extractor(&value) {
Some(val) => Ok(val),
None => Err(custom_err(format!("expected {expected} but got {value:?}"))),
}
}
}
impl<'de, A: BurnModuleAdapter> serde::Deserializer<'de> for Deserializer<A> {
type Error = Error;
fn deserialize_any<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
unimplemented!("deserialize_any is not implemented")
}
fn deserialize_struct<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
let value = match self.value {
Some(value) => {
// Adapt modules
if let Some(name) = name.strip_suffix(RECORD_ITEM_SUFFIX) {
A::adapt(name, value)
} else {
valueView on GitHub (pinned to d16f7ba2ed)
Solutions
- Ensure the type being deserialized is a struct/map/seq/primitive that serde deserializes via type-specific methods, not via deserialize_any.
- Replace untagged or internally-tagged enum fields in the record type with explicit tagged structs that use deserialize_struct/deserialize_enum.
- If you own the Deserialize impl, add #[serde(deserialize_with = ...)] or a manual impl that calls concrete deserialize_* methods.
- Check for a version change: a Burn upgrade may have changed record item types; adapt checkpoints with a BurnModuleAdapter.
Example fix
// before
#[derive(Deserialize)]
#[serde(untagged)]
enum Value { Int(i32), Text(String) } // untagged -> deserialize_any -> panic
// after
#[derive(Deserialize)]
#[serde(rename_all = "snake_case")]
enum Value { Int(i32), Text(String) } // externally tagged -> deserialize_enum is implemented Defensive patterns
Strategy: type-guard
Validate before calling
// Only deserialize record item types built from structs/enums with explicit tags; // audit #[derive(Deserialize)] types for untagged enums or Value-like fields before use.
Type guard
fn nested_deserialize_safe<T: DeserializeOwned>() -> bool {
// Safe if T's impl never requires deserialize_any:
// no #[serde(untagged)], no serde_json::Value / DynamicValue fields.
!std::any::TypeId::of::<T>().needs_any() // conceptual: audit manually
} Try / catch
// unimplemented! panics are not catchable via Result; only catch_unwind helps
let result = std::panic::catch_unwind(|| load_record(path));
match result {
Ok(Ok(record)) => record,
_ => eprintln!("nested deserializer hit an unsupported type (deserialize_any)"),
} Prevention
- Keep record item types to named structs, externally tagged enums, options, vecs, and supported primitives.
- Avoid #[serde(untagged)] and serde_json::Value fields in record types.
- Test save/load round trips whenever a record item type changes.
When it happens
Trigger: Deserializing a type from a Burn nested value (e.g., ModuleRecorder load / store record deserialization) whose serde Deserialize implementation relies on the generic `deserialize_any` entry point instead of a type-specific method — e.g., #[serde(untagged)] enums, deserializing into serde_json::Value, or serde data formats forwarding to any.
Common situations: Loading a Burn module record where a field's type changed to something requiring untagged/any-based deserialization; custom adapters or record items containing arbitrary JSON-like values; using the nested deserializer for types it was never designed for (it only supports the shapes Burn record items use).
Related errors
- deserialize_i8 is not implemented
- deserialize_u32 is not implemented
- deserialize_char is not implemented
- deserialize_bytes is not implemented
- deserialize_unit is not implemented
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/6f5d181f4bfb8176.
Report an issue: GitHub.