Skip to content
fn

load_compiled

→object
load_compiled(path: str)

Load a previously-saved compiled executable into a thin wrapper.

Returns an object exposing __call__(*args) that runs the saved executable directly. The executable expects every feed in feed order — that includes both model parameters and runtime inputs. This is the raw artifact level: there is no automatic parameter re-binding, because the saved package does not carry the parameter values (only the graph structure + I/O ids).

For a smoother AOT workflow that re-binds parameters from a live model, build a thin caller-side helper around load_compiled that stitches model.parameters() onto the executable's feed list before invocation.

Parameters

pathstr
Filesystem prefix matching a previous save_compiled call. Expects both <path>.mpsgraphpackage and <path>.meta to exist.

Returns

object

A callable wrapper. Attributes:

  • num_inputs: total feed count the executable expects.
  • input_ids: ordered trace ids (debug / introspection).
  • __call__(*feeds): run with feeds in input_ids order.

Raises

FileNotFoundError
Either .mpsgraphpackage or .meta is missing.
RuntimeError
The .meta sidecar is corrupted, the SDK ABI mismatches, or the saved executable references engine internals that no longer exist. Calling the wrapper raises the engine's FirstRunTimeout when MPSGraph's first run outlasts LUCID_COMPILE_FIRST_RUN_TIMEOUT_S (120 s), with no eager path.

Examples

>>> import lucid
>>> import lucid.compile as lc
>>> cm = lc.compile(lambda a, b: a * b + 1.0)
>>> a = lucid.randn(2, 8).to("metal")
>>> b = lucid.randn(2, 8).to("metal")
>>> _ = cm(a, b)                              # populate cache
>>> lc.save_compiled(cm, "/tmp/my_graph")
True
>>> step = lc.load_compiled("/tmp/my_graph")
>>> step.num_inputs                           # a and b, in first-read order
2
>>> out = step(a, b)
>>> bool(lucid.allclose(out.to("cpu"), (a * b + 1.0).to("cpu")))
True