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
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)
Executes the graph on raw buffers, appending the signal buffers.
export_mef()
export_mef(path)
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]
Data for the external constants the graph declares, keyed as the graph names them, one entry per shard of a distributed weight.