Possibly, but we never proved it. A Human3R multi-person worker on RunPod GPUs once got an all-False img_mask on an input that had worked on the run before. Our main suspect was DUSt3R's to_gpu(), which sends cloned CPU tensors to the GPU with non_blocking=True. We made those copies synchronous, synced after inference, moved postprocessing to CPU and added one retry.

This postmortem covers what we saw, why the obvious root-cause story is weaker than it looks once you read the CUDA contract, and why we fixed four things instead of one. If you run DUSt3R-family models (DUSt3R, CUT3R, Human3R) in a serverless GPU worker, this is how we handle a failure we can't reproduce on demand.

What did the failure actually look like?

One request on a RunPod serverless GPU worker failed with img_mask all-False, which tells the model there are no valid input images. The same input with the same code had just succeeded on the run before. Every mask is built as True on the CPU, so all-False is impossible on paper.

The worker takes a video, extracts frames with ffmpeg and feeds them into Human3R (CUT3R plus Multi-HMR) to get per-person SMPL-X motion in world coordinates. It's one stage of the markerless motion-capture pipeline we also wrote about in why did our SMPL-X export make a hand hover over the head?. Our wrapper calls the repo's own prepare_input() with img_mask=[True] * len(img_paths). Nothing in our code ever writes False.

So the input was right on the CPU and wrong by the time the model read it. That points at the CPU-to-GPU handoff. It does not point at the model, the checkpoint or the video.

Where does img_mask cross from CPU to GPU in DUSt3R/Human3R?

Every input view is a dict of small CPU tensors, including a one-element bool img_mask. During the recurrent forward pass, upstream to_gpu() clones each tensor and copies it to the device with non_blocking=True. That clone is a short-lived pageable temporary, and the async copy reads from it.

Here is the relevant part of src/dust3r/utils/device.py at the Human3R commit we pin:

# upstream dust3r/utils/device.py (abridged)
def to_gpu(_view, device):
    view = {}
    for name in _view.keys():
        if name in ignore_keys:
            continue
        if isinstance(_view[name], (tuple, list)):
            view[name] = [x.clone().to(device, non_blocking=True) for x in _view[name]]
        else:
            view[name] = _view[name].clone().to(device, non_blocking=True)
    return view

The .clone() result has no other owner. The temp can be freed as soon as the expression ends, possibly before the async copy has read it. Our commit message said exactly that: a pending async copy from a freed pageable temp can race. It's the obvious theory. It's also only partly supported by the docs.

Is non_blocking=True from pageable memory actually unsafe?

On paper, no. The PyTorch guide to non_blocking and pin_memory says a host-to-device copy from pageable memory is safe without an explicit sync, even if the source changes after the copy is queued. The documented danger runs the other way: reading GPU results on the host before an async copy has finished.

The CUDA runtime's API synchronization rules explain why. A copy between pageable host memory and the device "might be synchronous with respect to host". When the driver has to stage pageable memory, it syncs with the stream and copies the data into a pinned buffer first. Once the call returns, the pageable source is no longer needed, so freeing the temp should be harmless.

Read strictly, then, the "freed pageable temp" story describes a hazard the documented contract says doesn't exist for host-to-device copies. Our honest status: one bad run, a suspect that matches the symptom, and documentation that mostly clears that suspect. At that point you can keep digging indefinitely, or ship a fix that works whichever theory is right.

There are still ways the theory could hold in practice. "Might be synchronous" is not a promise, behaviour varies by driver and allocator, and the docs describe CUDA's guarantees, not every layer between a Python tensor and the DMA engine. The device-to-host direction is a documented hazard and was also on our path. All-False is also exactly what a zero-filled bool buffer looks like. We couldn't reproduce it on demand, so we couldn't tell these apart.

Why did we fix four things instead of one?

We couldn't trigger the failure on demand, so a narrow fix would have been unfalsifiable. Instead we removed every async boundary between input building and numpy output: synchronous host-to-device copies, a sync after inference, postprocessing moved to CPU with explicit .detach().cpu(), and one in-process retry for anything left.

The four changes, each aimed at a different failure path:

  • Synchronous input copies. A build-time patch rewrites both non_blocking=True calls in to_gpu() to non_blocking=False. This kills the suspect regardless of whether the docs clear it. The per-view tensors are small, so a blocking copy is negligible next to the forward pass.
  • A sync after inference. torch.cuda.synchronize() before the outputs leave the inference stage, so no queued kernel or copy can still be writing while we read.
  • CPU postprocessing. The postprocess step (focal estimation, SMPL-X layer, rotation conversion) is a small workload. We force it onto the CPU and call .detach().cpu() on every predicted tensor first. Every device-to-host transfer is then blocking, which closes the direction the PyTorch docs do warn about.
  • One retry. If the forward pass throws, log the full traceback, empty the CUDA cache and run it once more in the same process.

The patch is deliberately strict. It asserts each target string appears exactly once in the upstream file before replacing it, so a Human3R version bump that moves the code fails the Docker build instead of silently shipping unpatched:

# build-time patch (simplified)
src = read("src/dust3r/utils/device.py")
for line in TARGET_LINES:                 # the two to_gpu() copy lines
    assert src.count(line) == 1           # upstream moved? fail the build, don't guess
    src = src.replace(line, line.replace("non_blocking=True", "non_blocking=False"))
write("src/dust3r/utils/device.py", src)

We considered pinning the CPU tensors and keeping the copies async, which is the textbook way to get real overlap. We ruled it out: these are bool and scalar tensors with nothing to overlap, and pinned memory brings its own reuse-before-copy-completes hazard. Overlap only pays when the transfer is big enough to hide.

Why exactly one in-process retry?

Because on serverless GPUs the cold start is the expensive part, and a flaky forward pass isn't. Retrying in the same process reuses the model that's already loaded in GPU memory. Failing the job hands the retry to the queue, which may land on a cold worker that has to load a multi-gigabyte checkpoint first.

Our Human3R image bakes in a checkpoint of over 4 GB (the Docker build asserts the size), plus body models and a DINOv2 backbone. On RunPod, cold starts on GPU workers took minutes, as we covered in RunPod serverless gotchas: 409 "Endpoint is paused", 3–9 minute cold starts, and bad GPU workers. A second forward pass costs a fraction of that.

We stopped at one retry on purpose. A transient fault should clear on the second try. A deterministic bug, or a GPU worker that's actually broken, will fail twice, and then we want the job to fail loudly with both tracebacks in the timing payload instead of burning GPU time on a loop. Each attempt's error goes into the job's timing dict, so a retried success is visible in the output, not hidden.

What should you check if you see an all-False mask on GPU?

First confirm the mask is True on the CPU right before the model call. If it is, audit every non_blocking=True on the path in both directions, add a sync after the forward pass, and move small postprocessing to CPU. Check whether the bad runs cluster on particular GPU workers before blaming the code.

  • Grep upstream for non_blocking=True. In research codebases it's often copied from training loops where pinned DataLoader memory made it worthwhile. In a single-request inference worker it rarely buys anything.
  • Look for device-to-host reads with no sync. Any .to("cpu", non_blocking=True) followed by numpy or Python reads is a documented hazard, not a theoretical one.
  • Log which worker ran each request. On shared serverless GPUs, a bad host can look like a flaky model. If failures follow a worker ID, the fix is routing, not code.
  • Keep the retry outcome visible. A retry that hides the first failure loses your only evidence. Record it in the response.

So was it a non_blocking race?

Maybe, but we couldn't prove it, and the CUDA and PyTorch docs say the host-to-device version shouldn't happen. What we know for sure: an all-False img_mask showed up once on input that is True by construction, the async copies in upstream to_gpu() were the obvious suspect, and making them synchronous costs next to nothing next to the forward pass.

The lesson is about method more than CUDA. When a GPU failure won't reproduce, don't bet the fix on your favourite theory. Remove every async boundary that doesn't earn its keep, make CPU-to-GPU handoffs blocking where the tensors are small, retry once in the warm process, and keep the evidence in the job output. Production inference workers are not training loops, and code written for training throughput is a frequent source of this kind of risk.