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 module
max.experimental.realization_context
Implementations of various realization strategies.
“Eager” execution: tensors are realized as soon as the realization context exits. This is the default behavior.
This has a huge concrete advantage over eagerly executing one operation at a time: by controlling the boundary of where the eager context starts and ends, we can give advanced users a tool to enable fine-grained bounds for automatic fusion.
In practice the easiest way to do this is to mark a function as F.functional. This function is then assumed to be “atomic” for the purposes of eager execution. All ops within the function execute as part of the same graph, meaning the compiler is free to fuse operations and generate fused kernels within this region.
“Lazy” execution: tensors are realized only when code later tries to use them.
This enables a class of interface design common in the ML world, in which layers are constructed with randomized weights which are never used. Lazy execution neatly allows constructing entire models, only performing the weight initialization and allocating memory for them if and when those weights are actually used.
Graph compilation: tensors must never be realized.
This allows tensor operations to be composed with direct usage of the Graph API, for instance Module.compile, or using F.* operations in another Graph API usage.
Contexts
EagerRealizationContext | Computation graph for managing tensor operations. |
|---|---|
GraphRealizationContext | A realization context for ahead-of-time graph compilation. |
LazyRealizationContext | A realization context that defers execution until explicitly requested. |
Default context
default_realization_context | Constructs a context for ops realized outside any explicit context. |
|---|---|
ensure_context | Ensures a realization context exists for Tensor / TensorValue conversion. |
in_graph_context | Returns True when executing inside a Graph context. |
lazy | Defers tensor realization until explicitly awaited. |
set_default_realization_context | Sets the constructor used by default_realization_context(). |
Seeding
seed | Gets the global random seed tensor used in eager execution mode. |
|---|---|
set_seed | Sets the global random seed value. |