Diagnose Compile failures
A compiled callable passes through capture, the pass pipeline, preparation, lowering, linking, and execution; an exported callable adds export and load. Each stage raises its own error or records its outcome in compiled.stats(). Identify the stage before changing the computation, its CKKS state, or its keys.
Prerequisites
Keep the full exception, the source of the compiled function, and representative input metadata (device, depth, scale, domain, component count). Record material symbols without printing secret payloads.
1. Locate the stage
| Stage | Evidence | First action |
|---|---|---|
| Capture | fhelium.compile.CaptureError, or a TypeError raised while the source runs on traced values | Rewrite the reported construct (step 2). |
| Pass pipeline | An MLIR diagnostic naming the failing pass and operation | Inspect the module before that pass (step 3). |
| Lowering and linking | KeyError or ValueError from fhelium.compile.mlir._link or the implementation registry | Compare the lowered operations with the Backend registry (step 4). |
| Call | SpecializationMiss | Prepare the admitted signatures (step 5). |
| Export or load | ExportError, key-matching, identity, or rank errors | Adjust the exported callable or the loading environment (step 6). |
| Persistent cache | stats()["cache"] reason | The call still compiles; adjust the source to restore capture-free reuse (step 7). |
| Graph execution | fallback_reason in stats()["graphs"] | The call runs directly; remove the reported condition when Graphs are required. |
Preparation errors propagate from the call or from compiled.prepare(*args), which reproduces a failure without returning a result.
2. Resolve capture errors
Capture runs the Python body with traced ciphertexts. Engine operations append operations to the module; Python control flow, Python scalars, and public Tensor values are evaluated during capture.
| Message | Cause and repair |
|---|---|
compiled functions take at least one Ciphertext argument | Pass at least one ciphertext as an argument. Plaintexts, keys, and Tensors alone become materials. |
compile found <n> Engines reachable from the source and its arguments; select one with engine= | Several Engines are reachable from the function's arguments, closure, globals, defaults, or bound instance. Pass engine=. |
captured outputs must be traced values, got <type> | The function returns a Python scalar, a Tensor, or a value it did not compute from its arguments. Return ciphertexts or plaintexts, alone or in tuples and lists. |
cannot bind <type> as a material | The function passes an object to an Engine operation that is neither a key, a Tensor, a CKKS value, nor a process group. Pass one of those types. |
cannot record ATen argument of type <type> | A PyTorch operator on a Tensor that an Engine operation consumes has an argument capture cannot record. Compute the Tensor before the call and pass it as an argument. |
An AttributeError or TypeError on a traced value | The body reads ciphertext residues, branches on a ciphertext, or calls an Engine method whose Eager definition reads residues. Express the computation with Engine operations, or call that method between compiled calls. |
A branch on public Tensor contents is evaluated at capture and is not part of the call signature; a later call with other Tensor contents reuses the captured path. Compute such decisions outside the compiled function and pass them as Python scalars, which select a specialization.
3. Inspect the module
from fhelium import compile as fc
captured = fc.capture(function, engine, (x,))
print(captured.to_text())
fc.Pipeline(fc.default_pipeline().passes[:2]).run(captured)
print(captured.to_text())2
3
4
5
6
Run the pipeline prefix up to the failing pass and print the module at the last successful stage; fc.compile then runs fhelium-outline-preparation, rotation hoisting, lowering, and fusion, which can be appended by name in the same way. fhelium.compile.mlir.execute(captured, engine, (x,), check_types=True) runs the captured function through the Engine and raises StateMismatch at the first result whose Eager state differs from its type. Inspect compiled IR describes the printed types.
A scale assignment error reports an add or subtract of two different assigned scales or an add_plaintext whose plaintext scale differs from the ciphertext scale. Align the operands in the source as Eager requires, for example with reinterpret_at_scale or a rescale on the other operand.
4. Resolve lowering and implementation errors
A lowered operation resolves its implementation by MLIR name through the Backend registry. ValueError: Operation operation '<name>' has <n> available implementations; selection is required reports an operation with no default implementation or with several; inventory backend.registry.available(name) and set requires_request on alternative implementations, as described in Choose operation implementations. KeyError: no table provider for <kind> reports a table description that the Backend cannot build. Device-specific failures usually come from the installed native library or from an operand or key on another device; selecting a Backend does not move them.
5. Handle specialization misses
A call prepares a new specialization when an argument's dtype, device, layout, CKKS state, or a Python scalar value differs from every prepared specialization. With on_miss="error", such a call raises SpecializationMiss; prepare each admitted signature during setup. A loaded artifact raises SpecializationMiss("No specialization stored in the artifact matches these arguments") for a call outside the exported signatures; export another example call for it. Changing ciphertext or Tensor contents never misses. After changing Python constants that the function reads, call compiled.clear().
6. Resolve export and load errors
| Error | Cause and repair |
|---|---|
ExportError: Schedules with Python calls cannot be exported: ... | A linked schedule runs a Python implementation. Replace the listed operation with one that lowers to native operations, or keep that callable in-process. |
ExportError: the examples use Engines of different CKKS configurations | Use one configuration per exported callable. |
ValueError: a call cannot run on declared keys; prepare or export it, then bind keys of the same layouts | A first call of a signature reads keys from engine.declare_key. Use prepare or fc.export for declared keys, and call with generated keys of the same layouts. |
ValueError: the specialization reads declared keys without data; bind keys of the same layouts in the call first | A call matched a specialization prepared with declared keys and still reads them. Supply the generated keys in the arguments or objects the function reads. |
ExportError: material <symbol> is a compact key; export expanded keys | The example calls read a compact key. Export with expanded keys; the loader expands compact keys it binds. |
ValueError: No supplied key matches artifact keys <symbol> (<role>) | The loading process lacks a key with the recorded role and layout. Supply the key with the same prime and digit layout and, for rotations, the same step. |
supply the process group for artifact group <symbol> | The artifact runs a collective on a group other than the default group. Pass groups={symbol: group} to fc.load; the symbol world defaults to the default group. |
Artifact identity mismatch: <field> ... | The loading library differs from the exporting library in FHElium version, operator schema hash, Torch ABI, or CUDA runtime. Export again with the deployed build. |
Unsupported artifact schema version in <path> | The file comes from another FHElium version. Export again. |
the artifact was captured for process rank <r>; this process has rank <s> | The source read the process rank during capture; load the file on that rank. |
7. Restore capture-free cache reuse
stats()["cache"] reports why the source is not identified before capture, for example {'ineligible': 'custom implementation registry'} or a construct outside the statically checked subset of Python. Such a callable still uses the trace key, which skips lowering and linking but captures in each process. The reason refers to the first construct found in the function or in a function it calls; Choose compile boundaries lists the subset.
Verify the repair
Repeat the failing call or export with the same input conditions, inspect stats(), and compare decoded outputs with the clear-message reference. Use Diagnose a value-state mismatch for CKKS state errors in the source computation.