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

Module

Module

class max.graph.Module(mlir_module=None)

source

Bases: object

A container for one or more Graph instances compiled together.

A Module holds an MLIR module that may contain multiple mo.graph ops — for example a vision encoder and a language model that should be handed to max.engine.InferenceSession.load_all() as a single compilation unit. Constructing several Graph instances with the same module= argument adds each graph as a top-level op in this module.

Example:

module = Module()
with Graph("encoder", input_types=encoder_inputs, module=module) as encoder:
    ...
with Graph("decoder", input_types=decoder_inputs, module=module) as decoder:
    ...
models = session.load_all(module, weights_registry=weights)
encoder = models[encoder.name]
decoder = models[decoder.name]

The wrapped MLIR module is exposed as mlir_module for code that must reach the underlying representation (graph compiler internals, serializers, etc.); routine users should not need it.

Create a new, empty module, or wrap an existing builtin.ModuleOp.

Parameters:

mlir_module (ModuleOp) – An existing typed builtin.ModuleOp to wrap. When None (the default), a new empty module is created. The wrap-existing form is intended for code that already holds a typed ModuleOp (for example Graph’s subgraph plumbing or the Graph.module property) and needs to expose it through the public Module surface; routine users should leave this argument unset.

mlir_module

mlir_module: ModuleOp

source

The wrapped MLIR module, exposed through the typed nanobind dialect bindings.

top_level_graph_names()

top_level_graph_names()

source

Return the name of every top-level (non-subgraph) graph in this module.

Walks the wrapped module’s body and skips any op whose is_subgraph is set (subgraphs are inlined callees, not loaded as standalone models). Non-graph ops are skipped rather than raising. The resulting order matches MEF model order, which is the order max.engine.InferenceSession.load_all() returns models in.

Returns:

The names of the top-level graphs, in MEF order. The list is empty for a freshly constructed Module.

Return type:

list[str]