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='')
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)
In graph context, same as add_source (constants are immutable).
-
Parameters:
-
tensor (Tensor)
-
Return type:
-
RealizationState
add_source()
add_source(tensor)
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)
Creates a tensor backed by graph value(s).
-
Parameters:
-
- values (tuple[GraphValue, ...])
- mapping (DeviceMapping | None)
-
Return type:
graph
graph: Graph
The graph being constructed in this context.
prefix
prefix: str
What names here are relative to: the enclosing call’s prefix, or "".
realize_all()
async realize_all()
Raises TypeError - graph contexts cannot realize tensors.
signal_buffers
signal_buffers: list[BufferValue] | None
subgraph_cache
Subgraph dedup table; armed by the root trace, None inlines.
subgraph_out_defs
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.