xai-org/x-algorithm · error · SemanticCheckFailure
type checking expression %s failed: invalid argument type: e
Error message
type checking expression %s failed: invalid argument type: expected a constant %s
What it means
XAI_ASSERT is an internal assertion macro in the async embedding CUDA library. It evaluates a condition at runtime and throws std::runtime_error composed of __FILE__:__LINE__ plus the supplied message when the condition is false. It is used to guard invariants such as valid tensor shapes, non-null device pointers, or supported dtype combinations before launching kernels.
Source
Thrown at botmaker/src/java/com/twitter/botmaker/ASTNode.java:160
for (ASTNode child : astNodeChildren) {
long childScope = child.getFingerprint().scope;
if (childScope == CacheLevel.Never.scope) {
return childScope;
} else if (childScope <= currentScope) {
scope = Math.max(scope, childScope);
} else {
scope = Math.max(scope, child.computeFingerprintScope(currentScope));
}
}
return scope;
}
public static void assertChildConstant(
String exprText, ImmutableList<ASTNode> children, int index) throws SemanticCheckFailure {
ASTNode node = children.get(index);
if (!Constant.class.isAssignableFrom(node.getClass())) {
throw new SemanticCheckFailure(String.format(
"type checking expression %s failed: invalid argument type: expected a constant %s",
exprText,
node.getReturnType().toString())
);
}
}
public static void assertChildrenSize(
String exprText, ImmutableList<ASTNode> children, int expected) throws SemanticCheckFailure {
if (children.size() != expected) {
throw new SemanticCheckFailure(String.format(
"ASTNode %s expected %d arguments, %d passed.", exprText, expected, children.size()));
}
}
public static void assertChildrenSize(
String exprText, ImmutableList<ASTNode> children,View on GitHub (pinned to 24c60942c5)
Solutions
- Read the file:line in the message to find the exact failing assertion and the invariant it checks
- Verify tensor device, dtype, and shape match what the async embedding op expects (especially innermost dim == embedding_dim)
- Ensure the embedding table handle was created on the same CUDA device as the inputs
- Check for None/nullptr arguments or zero-size tensors being passed through the FFI boundary
- Reproduce with a minimal input and compare against the library's own test fixtures to see which argument differs
Example fix
// before
emb_lookup(table_handle, indices_cpu, offsets, out) # indices on CPU
// after
indices_gpu = jax.device_put(indices, jax.devices('cuda')[0])
emb_lookup(table_handle, indices_gpu, offsets, out) # all buffers on same CUDA device Defensive patterns
Strategy: validation
Validate before calling
// Before calling the async embedding op: assert table_handle is not None assert indices.device.type == 'cuda' and indices.device == table_handle.device assert indices.shape[-1] == 0 or offsets.dtype == indices.dtype assert out is None or out.shape == expected_output_shape(indices, offsets, embedding_dim) assert indices.shape[-1] == embedding_dim # innermost dim must match table row size
Type guard
def _valid_emb_args(indices, offsets, table_dim, device) -> bool:
return (
indices is not None
and indices.device.type == 'cuda'
and indices.device == device
and indices.shape[-1] == table_dim
and indices.dtype in (np.int32, np.int64)
) Try / catch
try:
emb_lookup(handle, indices, offsets)
except RuntimeError as e:
if 'cuda_error_utils.hpp' in str(e): # XAI_ASSERT failure
raise ValueError(f'bad embedding arguments: {e}') from e
raise Prevention
- Always device_put every tensor to the same CUDA device as the embedding handle before the call
- Validate shapes/dtypes on the host before crossing the FFI boundary
- Pin library version so header-side assertion contracts match your caller code
- Wrap FFI entry points in tests covering empty tensors, wrong devices, and mismatched dims
When it happens
Trigger: Calling the async embedding FFI/binding APIs with arguments that violate internal preconditions: null or wrongly-typed device buffers, mismatched innermost dimension vs embedding table row stride, out-of-range indices configuration, or unsupported dtypes. Any call site in phoenix/xrex/cuda/async_emb that wraps a check in XAI_ASSERT(cond, msg) will raise this when cond evaluates false.
Common situations: Passing CPU tensors instead of CUDA tensors, embedding dimension not matching the table's row size, batch shapes that don't match index shapes, version mismatches where the host/JAX layer builds args the kernel no longer accepts, or initializing the embedding handle on a different device than the input data.
Related errors
- ASTNode %s expected %d to %d arguments, %d passed.
- type checking expression %s failed: invalid argument type: %
- the fused rowwise Adagrad update needs a row shard that divi
- ASTNode %s expected %d arguments, %d passed.
- type checking expression %s failed: expects %d arguments, %d
AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28).
Data as JSON: /api/errors/13e7c35955a85fc8.
Report an issue: GitHub.