Fix TensorFlow 'Check failed: work_element_count > 0' (gpu_launch_config.h:129)
Quick answer
This Check failed: work_element_count > 0 crash happens when a CUDA kernel is launched with zero or a negative number of elements, which usually means an empty or wrongly-shaped tensor reached a GPU op — commonly a batch of size 0, an empty dataset shard, or an integer overflow in a very large tensor dimension. Check for empty batches and validate tensor shapes before the failing op.
Check failed: work_element_count > 0 (-1018167296 vs. 0) from gpu_launch_config.h:129 looks like a low-level GPU crash, but it's really TensorFlow catching a bad tensor before it launches a kernel. Understanding the assertion tells you exactly where to look — and it isn't your GPU or drivers.
What the assertion means
Before TensorFlow runs a CUDA kernel, it calculates how many elements that kernel must process — work_element_count — and asserts the value is positive. It has to be: launching a kernel over zero or a negative number of elements is meaningless. When the assertion fails, some tensor reached a GPU op with no elements, or with an element count that computed to a garbage negative value. Either way, the real problem happened upstream, in your data or your shapes.
The value in the parentheses is a strong hint:
- A small non-positive number (0 or a small negative) → an empty tensor: a batch of size 0, an empty axis.
- A large negative number like
-1018167296→ an int32 overflow: the product of a tensor's dimensions exceeded 2³¹ (~2.1 billion) and wrapped around. Something is far larger than you intended.
Why it happens
- An empty batch reaches the GPU (most common). Your input pipeline yielded a batch of size 0 — an exhausted
tf.datadataset, afilter()that removed everything, an empty shard in a distributed setup, or an edge case arounddrop_remainder. The GPU op then has nothing to process. - Shape math collapsed a dimension to 0. A convolution or pooling layer whose input is smaller than its kernel/stride can produce an output dimension of 0. A
reshape,slice, orgathercan also produce an empty axis. The tensor is technically valid but has zero elements. - An int32 overflow on a huge tensor. A dimension computed much larger than intended (a bad multiplication, an off-by-a-lot batch or sequence length) pushes the total element count past 2³¹, and it wraps negative.
Diagnose it
Reproduce with a single batch, eagerly, and inspect what's flowing in:
import tensorflow as tf
# 1) Are any batches empty?
for i, (x, y) in enumerate(dataset.take(50)):
tf.debugging.assert_greater(tf.size(x), 0, message=f"empty batch at {i}")
if i < 3:
print("batch", i, "x.shape:", x.shape, "y.shape:", y.shape)
# 2) Does a layer collapse a dimension to 0 for your input size?
model.summary() # look for any output shape with a 0 dimensionFor the overflow case, check whether any tensor's total element count approaches 2³¹:
print(int(tf.size(x))) # if this is near or above 2_147_483_648, that's your overflowFix it
- Guarantee non-empty batches. Filter out empty samples before batching, handle the exhausted-dataset case, and be deliberate with
drop_remainder. In distributed training, make sure no replica gets an empty shard. - Fix the shape math. Pad inputs so conv/pool layers never see an input smaller than their kernel, and verify slices/reshapes can't produce an empty axis.
- Tame the overflow. If a tensor is genuinely enormous, reduce the batch size or sequence length, split the operation, or restructure so no single op processes more than ~2 billion elements.
Prevent it
- Assert batch shapes at the pipeline boundary (
tf.debugging.assert_greater(tf.size(x), 0)) so an empty batch fails loudly at the source instead of deep inside a kernel launch. - Print
model.summary()when you change input sizes and confirm no layer output has a 0 dimension. - Sanity-check dataset cardinality after filters and shards so you never feed the GPU an empty batch.
Trace the empty or oversized tensor, fix the data or shape that produced it, and this internal crash goes away — no CUDA reinstall required.
Key takeaways
- •It's an internal assertion: a GPU op received ≤ 0 elements to process, which should never happen for a valid tensor.
- •The huge negative number (e.g. -1018167296) is a tell-tale of int32 overflow — a tensor whose element count exceeded 2^31.
- •Most common real cause is an empty batch reaching the GPU: an exhausted dataset, an over-aggressive filter, or a size-0 shard.
- •Second cause is shape math collapsing a dimension to 0 — a conv/pool output smaller than its kernel, or a slice/reshape with an empty axis.
- •Fix it upstream by validating shapes and guaranteeing non-empty batches, not by touching CUDA or drivers.
Frequently asked questions
What does 'Check failed: work_element_count > 0' actually mean?
It's an internal TensorFlow assertion in gpu_launch_config.h. Before launching a CUDA kernel, TensorFlow computes how many elements it needs to process (work_element_count) and asserts it's positive. The crash means that count came out as zero or negative — so an empty or malformed tensor reached a GPU op. It's a symptom of a data or shape problem upstream, not a GPU fault.
Why is work_element_count a huge negative number like -1018167296?
That pattern is the signature of a 32-bit integer overflow. The element count is computed as an int, and when the product of a tensor's dimensions exceeds 2^31 (~2.1 billion), it wraps around to a negative value. It means a tensor somewhere is enormous — check for an accidentally huge dimension or a bad shape calculation.
How do I find which tensor is causing it?
Reproduce with a single batch and eager execution, and print the shapes feeding the failing op. Iterate your dataset and assert every batch has size > 0. Check any conv/pool layers for an output dimension that collapses to 0 given your input size. One of these will reveal an empty or oversized tensor.
Is this a GPU driver or CUDA installation problem?
Almost never. The libraries have already loaded and the kernel is being launched; the failure is that there's nothing valid to launch it on. Reinstalling CUDA or updating drivers won't help. Fix the data pipeline or the layer shapes that produced an empty or overflowed tensor.
Software Engineering Leader & Technical Author · Updated August 31, 2026