xai-org/x-algorithm · error · ValueError
Cannot lower a compiled jit function.
Error message
Cannot lower a compiled jit function.
What it means
A small wrapper around jitted functions forbids calling lower() on an object that is already a Compiled executable: lowering is only valid on an uncompiled jit function. This guards the AOT pipeline from double-processing an already-compiled artifact.
Source
Thrown at phoenix/xrex/utils/aot.py:672
}
return compiled
metrics: Dict[str, Dict[str, float]] = {}
all_compiled = {n: _compile_or_load(n, t, metrics) for n, t in all_traced.items()}
return all_compiled, metrics
class JittedOrCompiled(Wrapped):
__slots__: tuple[str, ...] = ("jitted", "fun_name")
def __init__(self, jitted, name=None):
self.fun_name = name
self.jitted = jitted
def lower(self, *args, **kwargs):
if isinstance(self.jitted, Compiled):
raise ValueError("Cannot lower a compiled jit function.")
return self.jitted.lower(*args, **kwargs)
def trace(self, *args, **kwargs) -> Traced:
if isinstance(self.jitted, (Traced, Compiled)):
raise TypeError(f"Unsupported type: {type(self.jitted)}.")
return self.jitted.trace(*args, **kwargs)
def name(self):
if self.fun_name is not None:
return self.fun_name
if isinstance(self.jitted, Wrapped):
return getattr(self.jitted._fun, "__name__", str(self.jitted._fun))
raise TypeError(f"Unsupported type: {type(self.jitted)}.")
def __call__(self, *args, **kwargs):
return self.jitted(*args, **kwargs)
View on GitHub (pinned to 24c60942c5)
Solutions
- Only call lower() when the wrapped object is still a jit function; check isinstance(wrapped.jitted, Compiled) first
- Restructure the pipeline so loaded Compiled objects go straight to execution, not back through compile
Example fix
# before
lowered = wrapped.lower(*args) # wrapped.jitted is Compiled
# after
if isinstance(wrapped.jitted, Compiled):
compiled = wrapped.jitted
else:
lowered = wrapped.lower(*args) Defensive patterns
Strategy: type-guard
Validate before calling
from phoenix.xrex.utils.aot import Compiled
if isinstance(wrapped.jitted, Compiled):
use_directly = wrapped.jitted # skip lower() Type guard
def is_compiled(wrapped) -> bool:
from phoenix.xrex.utils.aot import Compiled
return isinstance(wrapped.jitted, Compiled) Prevention
- Check pipeline stage before calling lower(); don't re-enter compile on cache hits
- Keep clear state: raw jit -> Traced -> Lowered -> Compiled, never backwards
- Return loaded Compiled objects directly instead of re-wrapping into the compile path
When it happens
Trigger: Wrapping a Compiled object in Wrapped and calling .lower() — e.g. after loading from the AOT cache, the loaded Compiled is wrapped and someone re-enters the compile stage.
Common situations: Caching the wrapped object across pipeline stages and accidentally re-running compile_or_load on it; control flow that assumes lower() is idempotent.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Cannot remap XLA compile options device assignment: assignme
- Compilation does not support serialization
- AOT is not implemented for non-XLA lowerings.
- Unsupported type: {type(self.jitted)}.
- async_emb axis {axis!r} is not a mesh axis of {mesh}
AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28).
Data as JSON: /api/errors/a4afeb8c956927aa.
Report an issue: GitHub.