tracel-ai/burn · error
Default content should be implemented for {self_type}.
Error message
Default content should be implemented for {self_type}. What it means
Module display formatting first tries `custom_content`, and when that returns None it falls back to `content()` (the default content renderer). This panic fires when a module (or its primitive) implements the display traits but returns None from `content`, i.e. the required default renderer is missing. It is a trait-implementation contract violation, not a runtime data problem.
Source
Thrown at crates/burn-core/src/module/display.rs:65
} else {
passed_settings
};
let indent = " ".repeat(settings.level * settings.indentation_size());
let indent_close_braces = " ".repeat((settings.level - 1) * settings.indentation_size());
let settings = settings.level_up();
let self_type = extract_type_name::<Self>();
// Use custom content if it is implemented and show_all_attributes is false,
// otherwise use default content
let content = if !settings.show_all_attributes() {
self.custom_content(Content::new(settings.clone()))
.unwrap_or_else(|| {
self.content(Content::new(settings.clone()))
.unwrap_or_else(|| {
panic!("Default content should be implemented for {self_type}.")
})
})
} else {
self.content(Content::new(settings.clone()))
.unwrap_or_else(|| panic!("Default content should be implemented for {self_type}."))
};
let top_level_type = if let Some(top_level_type) = content.top_level_type {
top_level_type.to_owned()
} else {
self_type.to_owned()
};
// If there is only one item in the content, return it or no attributes
if let Some(item) = content.single_item {
return item;
} else if content.attributes.is_empty() {
return top_level_type.to_string();View on GitHub (pinned to d16f7ba2ed)
Solutions
- Implement `content(...)` for the type named in {self_type} so it returns Some(Content) with at least the type name and parameters.
- If the type intentionally has no content, wrap rendering so `content` returns a minimal Content instead of None.
- Check the burn version's display trait requirements — an upgrade may have made `content` mandatory for your custom module.
Example fix
// before
impl ModuleContent for MyLayer {
fn content(&self, _settings: &ContentSettings) -> Option<Content> { None } // panics
}
// after
impl ModuleContent for MyLayer {
fn content(&self, settings: &ContentSettings) -> Option<Content> {
Some(Content::new(settings.clone())
.add_top_level_type("MyLayer")
.add_parameter(Param::new("in_features", self.in_features)))
}
} Defensive patterns
Strategy: validation
Validate before calling
// Before printing, assert your custom modules implement content
fn check_content<M: ModuleContent>(m: &M, s: &ContentSettings) {
assert!(m.content(Content::new(s.clone())).is_some(), "content() must be implemented");
} Prevention
- Always return Some(Content) from content() — use custom_content for extras
- After upgrading burn, recompile: trait changes usually break custom display impls at compile time
- Test display output (model.print()) in unit tests for custom modules
When it happens
Trigger: Implementing `ModuleDisplay`/`ModuleContent` (or a new primitive/backend tensor display) whose `content()` returns `None` while `show_all_attributes()` is false; a custom module that only overrides `custom_content` and never supplies default content; `format` called on a type whose content impl was forgotten after an API update.
Common situations: Printing/logging a custom module with `model.print()` or `{:#?}`-style display after upgrading burn and missing a new required `content` implementation; hand-written adapters around burn modules returning None unconditionally.
Related errors
- Can't format yet
- capture tensor operations must run inside CaptureDevice::cap
- capture tensor {} has no initialized value
- seeding is not supported during graph capture
- capture graph {graph_id:?} was not registered
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/acba8e248713ba35.
Report an issue: GitHub.