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

LazyRealizationContext

LazyRealizationContext​

class max.experimental.realization_context.LazyRealizationContext(executor=None, *, use_interpreter=None)

source

Bases: EagerRealizationContext

A realization context that defers execution until explicitly requested.

Unlike EagerRealizationContext, this context does not automatically execute the computation graph when the context exits. Tensors remain unrealized until explicitly awaited via await tensor.realize.

This is useful for batching many operations together before execution, improving performance by reducing compilation overhead.

Example:

with F.lazy():
    a = Tensor.zeros([5, 5])
    b = a + 1
    c = b * 2
assert not c.real

await c.realize  # Now compile and execute
assert c.real

Initializes the context.

Parameters:

  • executor (Executor | None) – Executor used to run the finalized graph. None resolves to default_executor() at construction time.
  • use_interpreter (bool | None) – Deprecated. Selects an executor for backward compatibility when executor is not given: True forces the interpreter for any graph the interpreter accepts (runtime errors propagate), False forces compilation, and None uses the default executor.

subgraph_cache​

subgraph_cache: dict[Any, Any] | None = None

source

Subgraph dedup table; armed per instance by lazy().

subgraph_out_defs​

subgraph_out_defs: dict[str, Any] = {}

source

Output tree structure per keyed subgraph (see GraphRealizationContext.subgraph_out_defs).