IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/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. /max/get-started.md).

Python class

PrintHook

PrintHook​

class max.nn.hooks.PrintHook(export_path=None, filter=None)

source

Bases: BasePrintHook

Hook that prints layer tensor inputs and outputs.

Initialize the class before building the graph. This way, the hook can add print ops to the graph.

Parameters:

  • export_path (str | None) – Intended as the directory to write recorded tensors into, but writing to disk isn’t yet supported on the MAX execution path. When set, the path is ignored.
  • filter (list[str] | None) – A list of layer names to restrict printing to. When None, every named layer is printed.

export_path​

property export_path: str | None

source

name_layers()​

name_layers(model)

source

Create names for all layers in the model based on nested attributes.

Parameters:

model (Layer | Module[..., Any]) – A V2 Layer or V3 Module instance.

Raises:

TypeError – If model is neither a V2 Layer nor a V3 Module.

Return type:

None

name_layers_v3()​

name_layers_v3(model)

source

Name all v3 Module layers and wrap their forward to fire the hook.

Parameters:

model (Module[..., Any])

Return type:

None

print_value()​

print_value(name, value)

source

Prints a value, and returns whether the print is successful.

Parameters:

Return type:

bool

remove()​

remove()

source

Return type:

None