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

CompiledCallable

CompiledCallable

class max.experimental.compilation.CompiledCallable

source

Bases: Generic[_P, _R]

A compiled function over tensors.

Returned by compile(). Call it like the original function, with a real tensor in each spec’s place. The first call also binds weights and allocates device memory; export_mef() needs neither, so it works before any call.

from max.driver import CPU
from max.dtype import DType
from max.experimental import compilation
from max.experimental.sharding import TensorLayout
from max.experimental.tensor import Tensor

def scale(x: Tensor) -> Tensor:
    return x * 2

spec = TensorLayout(DType.float32, [3], CPU())

run = compilation.compile(scale)(spec)  # compiles here
run.export_mef("scale.mef")             # no weights, no device memory
out = run(Tensor.ones([3], device=CPU()))  # [2.0, 2.0, 2.0]

execute_raw()

execute_raw(*buffers)

source

Executes the graph on raw buffers, appending the signal buffers.

Parameters:

buffers (Buffer) – One per graph input, a distributed argument expanded into one per shard.

Returns:

The result buffers, flat and in graph order.

Return type:

list[Buffer]

export_mef()

export_mef(path)

source

Writes the compiled graph to a MEF file at path.

MEF is the binary format the runtime executes. Writing one serializes the compiled graph directly, without binding weights or allocating device memory. Read it back with max.engine.read() to skip compiling again.

Parameters:

path (str | Path) – Where to write the file.

Return type:

None

weights

weights: Mapping[str, DLPackArray]

source

Data for the external constants the graph declares, keyed as the graph names them, one entry per shard of a distributed weight.