Python class
Model
Model
class max.engine.Model
Bases: object
A loaded model that you can execute.
Do not instantiate this class directly. Instead, create it with
InferenceSession.
capture()
capture(graph_keys, *inputs)
Capture execution into a device graph for caller-provided key.
Capture is best-effort and model-dependent. If the model issues capture-unsafe operations (for example, host-device synchronization), graph capture may fail. Callers should choose capture-safe execution paths.
debug_verify_replay()
debug_verify_replay(graph_keys, *inputs)
Execute eagerly and verify the launch trace matches the captured graph.
This method validates that graph capture correctly represents eager execution by running the model and comparing kernel launch sequences against a previously captured device graph.
-
Parameters:
-
Raises:
-
- TypeError – If
graph_keysis neither an int nor a sequence of ints. - ValueError – If any key in
graph_keysis out of uint64 range. - ValueError – If no input buffers are provided.
- RuntimeError – If no graph has been captured for
graph_keys. - RuntimeError – If the eager execution trace doesn’t match the captured graph.
- TypeError – If
-
Return type:
-
None
Example:
>>> model.capture([1, 1], input_tensor)
>>> model.debug_verify_replay([1, 1], input_tensor) # Validates capture
>>> model.replay([1, 1], input_tensor) # Safe to use optimized replaydevices
property devices
Returns the device objects used in the Model.
execute()
execute(*args)
input_devices
property input_devices
Devices of the model’s input tensors, as a list of Device objects.
input_metadata
property input_metadata
Metadata about the model’s input tensors, as a list of TensorSpec objects.
For example, you can print the input tensor names, shapes, and dtypes:
for tensor in model.input_metadata:
print(f'name: {tensor.name}, shape: {tensor.shape}, dtype: {tensor.dtype}')kernel_summaries
property kernel_summaries
Kernel fusion summaries from the compiled model.
Returns a list of strings, one per mgp.generic.execute kernel in
the compiled graph. Each string describes the fused kernel composition,
e.g. "Epilogue(custom__kv_rope, custom__kv_cache_store)".
output_devices
property output_devices
Devices of the model’s output tensors, as a list of Device objects.
output_metadata
property output_metadata
Metadata about the model’s output tensors, as a list of TensorSpec objects.
For example, you can print the output tensor names, shapes, and dtypes:
for tensor in model.output_metadata:
print(f'name: {tensor.name}, shape: {tensor.shape}, dtype: {tensor.dtype}')reload()
Reload weights into this compiled model in-place.
Reuses the compiled graph and replaces the weight buffers in-place.
-
Parameters:
-
weights_registry – Model weight names mapped to their new values.
replay()
replay(graph_keys, *inputs)
Replay the captured device graph for a caller-provided key.
signature
property signature: Signature
Get input signature for model.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!