xai-org/x-algorithm · error · SemanticCheckFailure
type checking expression %s failed: expects %d arguments, %d
Error message
type checking expression %s failed: expects %d arguments, %d passed
What it means
ThrustAllocator adapts a scratch allocator for Thrust/CUB algorithms used inside XLA GPU utilities: Thrust calls allocate(n) for temporary storage, and the adapter forwards the request to scratch_allocator_->Allocate(n). If the underlying scratch allocator returns an empty optional (cannot satisfy the request), the adapter throws std::runtime_error('Failed to allocate memory'), which propagates out of the Thrust algorithm.
Source
Thrown at botmaker/src/java/com/twitter/botmaker/ASTNode.java:264
buildGenericTypeIdToTypeMapping(
genericTypeParams.get(i),
concreteTypeParams.get(i),
recordMap
);
}
}
}
}
private void validateSignature() throws SemanticCheckFailure {
int minArgs = signature.paramTypes.size();
int maxArgs = signature.paramTypes.size() + signature.optParamTypes.size();
if (signature.varargsType == null) {
if (astNodeChildren.size() < minArgs
|| astNodeChildren.size() > maxArgs) {
if (minArgs == maxArgs) {
throw new SemanticCheckFailure(String.format(
"type checking expression %s failed: expects %d arguments, %d passed",
exprText,
minArgs,
astNodeChildren.size()
));
} else {
throw new SemanticCheckFailure(String.format(
"type checking expression %s failed: expects %d arguments to %d arguments, %d passed",
exprText,
minArgs,
maxArgs,
astNodeChildren.size()
));
}
}
} else {
if (astNodeChildren.size() < minArgs) {
throw new SemanticCheckFailure(String.format(View on GitHub (pinned to 24c60942c5)
Solutions
- Free unused GPU tensors/caches before invoking the operation to give the scratch allocator room
- Increase the scratch allocator's pool size / growth policy if configurable via handle or environment settings
- Process data in smaller chunks so Thrust temporaries fit within the scratch budget
- Set a device memory limit or reserve headroom so scratch allocations can succeed; consider cudaMallocAsync-backed allocators if available
- If it happens intermittently under concurrency, serialize scratch-heavy ops or give each stream its own allocator
Example fix
// before
char* allocate(std::ptrdiff_t n) {
auto result = scratch_allocator_->Allocate(n);
if (!result.has_value()) {
throw std::runtime_error("Failed to allocate memory");
}
return static_cast<char*>(result.value());
}
// after
char* allocate(std::ptrdiff_t n) {
auto result = scratch_allocator_->Allocate(n);
if (!result.has_value()) {
// fall back to the CUDA allocator for oversized temporaries
void* p = nullptr;
XAI_CUDA_CHECK(cudaMalloc(&p, n));
return static_cast<char*>(p);
}
return static_cast<char*>(result.value());
} Defensive patterns
Strategy: fallback
Validate before calling
// Before Thrust-heavy ops:
size_t free = 0, total = 0;
cudaMemGetInfo(&free, &total);
size_t thrust_temp_upper = 2 * n * sizeof(KeyT); // conservative sort estimate
if (thrust_temp_upper > free) { /* free memory or chunk input */ } Type guard
template <typename Alloc>
bool allocator_can_satisfy(Alloc& a, std::ptrdiff_t n) {
auto probe = a.Allocate(n);
return probe.has_value();
} Try / catch
try {
thrust::sort(thrust::cuda::par(ThrustAllocator(pool)), begin, end);
} catch (const std::runtime_error& e) {
if (std::string(e.what()) == "Failed to allocate memory") {
// fallback: smaller chunks, sync+free caches, or cudaMalloc-backed allocator
sort_in_chunks(begin, end, chunk);
} else {
throw;
}
} Prevention
- Reserve GPU headroom (e.g. 10-20%) for Thrust temporaries when sizing batches
- Pre-grow scratch pools to cover worst-case sort/scan sizes at startup
- Use stream-ordered cudaMallocAsync allocators so temporary memory recycles promptly
- Free intermediate tensors promptly and avoid holding results while launching new Thrust ops
When it happens
Trigger: Running any Thrust/CUB-based operation (sort, scan, reduce, unique) in phoenix/xrex/cuda/xla_utils where the temporary storage request exceeds the scratch allocator's remaining capacity or per-allocation limit; scratch arena exhausted by prior ops in the same stream/compilation; or GPU-wide memory pressure making the underlying allocation fail.
Common situations: Large sorts or scans requesting big temporaries, shared scratch buffers sized conservatively for typical workloads, memory fragmentation in long-lived processes, concurrent CUDA streams each holding scratch, or running near the GPU memory limit with a large model resident.
Related errors
- ASTNode %s expected %d arguments, %d passed.
- type checking expression %s failed: invalid argument type: e
- ASTNode %s expected %d to %d arguments, %d passed.
- type checking expression %s failed: invalid argument type: %
- no compiled async_emb binding: xrex.cuda.async_emb.src has n
AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28).
Data as JSON: /api/errors/5057d4836c502efe.
Report an issue: GitHub.