IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).

Python function

dataclass

dataclass()

max.tree.dataclass(cls: type[_T], /) → type[_T]

source

max.tree.dataclass(cls: None = None, /, **kwargs: Any) → Callable[[type[_T]], type[_T]]

Makes a dataclass a tree node.

Usable bare or with dataclasses.dataclass() arguments.

from max import tree

@tree.dataclass
class AttentionInputs:
    layer_idx: TensorValue
    freqs_cis: TensorValue
    indexer: TensorValue | None = None

@tree.dataclass(frozen=True)
class PLEInputs:
    conv_pool: BufferValue
    slot_idx: TensorValue

The generated __tree_flatten__ includes fields that are not None at flatten time, in declaration order. The generated __tree_unflatten__ restores any absent field to None – a field is dropped only when it is None, so a non-None default is not reapplied.

Parameters:

  • cls – The class to decorate, or None when called with arguments.
  • kwargs – Passed to dataclasses.dataclass() when cls is not already a dataclass.

Returns:

The decorated class, or a decorator when called with arguments.