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 class

GraphRealizationContext

GraphRealizationContext​

class max.experimental.realization_context.GraphRealizationContext(graph, signal_buffers=None, prefix='')

source

Bases: RealizationContext

A realization context for ahead-of-time graph compilation.

This context is used when building computation graphs that will be compiled and executed later (such as during compile()). Tensors in this context remain as symbolic graph values and cannot be realized.

Unlike eager contexts, this context does not support executing operations immediately. Attempting to realize tensors will raise a TypeError.

Example:

graph = Graph("my_model", input_types=[TensorType(...)])
with GraphRealizationContext(graph) as ctx:
    x = Tensor.from_graph_value(graph.inputs[0])
    y = x + 1  # Creates graph operation, not computation
    graph.output(y)

Initializes the graph realization context.

Parameters:

  • graph (Graph) – The graph to construct operations in.
  • signal_buffers (list[BufferValue] | None) – GPU signal buffer graph values for multi-device collective ops.
  • prefix (str) – What names recorded in this graph are relative to.

add_mutable_source()​

add_mutable_source(tensor)

source

In graph context, same as add_source (constants are immutable).

Parameters:

tensor (Tensor)

Return type:

RealizationState

add_source()​

add_source(tensor)

source

Adds a tensor as a constant in the graph.

In graph context, source tensors become constant values embedded in the graph rather than graph inputs.

Parameters:

tensor (Tensor) – The tensor to embed as a constant.

Returns:

The state with the constant graph value.

Return type:

RealizationState

create_unrealized()​

create_unrealized(values, *, mapping=None)

source

Creates a tensor backed by graph value(s).

Parameters:

Return type:

Tensor

graph​

graph: Graph

source

The graph being constructed in this context.

prefix​

prefix: str

source

What names here are relative to: the enclosing call’s prefix, or "".

realize_all()​

async realize_all()

source

Raises TypeError - graph contexts cannot realize tensors.

Raises:

TypeError – Always raised, as graph contexts are for symbolic graph construction only.

Return type:

list[Tensor]

signal_buffers​

signal_buffers: list[BufferValue] | None

source

subgraph_cache​

subgraph_cache: dict[Any, Any] | None

source

Subgraph dedup table; armed by the root trace, None inlines.

subgraph_out_defs​

subgraph_out_defs: dict[str, Any]

source

Output tree structure per keyed subgraph, so a caller that reuses a cached subgraph (skipping its body trace) can still rebuild the call’s results. Keyed by the same dedup key as subgraph_cache.