#2006·warp

UnboundLocalError on a zero-size launch recorded on a tape with verify_autograd_array_access

Author: v0ropaevCreated Sep 28, 2026Updated Sep 28, 2026

Bug Description

A kernel launch with a zero-size grid, recorded on a tape with wp.config.verify_autograd_array_access on, raises UnboundLocalError.

launch() builds fwd_args inside if total_dim_size > 0: (warp/_src/context.py:11581-11582), and the tape block below reads it unconditionally:

python
    if runtime.tape and record_tape:
        ...
        # detect illegal inter-kernel read/write access patterns if verification flag is set
        if warp.config.verify_autograd_array_access:
            runtime.tape._check_kernel_array_access(kernel, fwd_args)

_normalize_launch_dim only rejects negative extents, so a zero extent reaches the guard and skips the assignment, and there is no early return for the zero case.

I hit this in a pipeline where the launch dimension comes from the number of items in a batch, and a batch can legitimately be empty. Turning the verification flag on to chase a gradient problem then turned every empty batch into a crash, which is the opposite of what a debug flag should do: the run dies for a launch that would not have done anything.

Repro (CPU, no GPU needed):

python
import warp as wp

wp.config.verify_autograd_array_access = True
wp.init()


@wp.kernel
def square_kernel(x: wp.array(dtype=float), y: wp.array(dtype=float)):
    tid = wp.tid()
    y[tid] = x[tid] * x[tid]


a = wp.zeros(0, dtype=float, requires_grad=True)
b = wp.zeros(0, dtype=float, requires_grad=True)

tape = wp.Tape()
with tape:
    wp.launch(square_kernel, dim=0, inputs=[a], outputs=[b])
UnboundLocalError: cannot access local variable 'fwd_args' where it is not associated with a value

All three conditions are needed: dim=0, an active tape, and the flag. Drop any one and it runs.

A launch of no threads reads and writes nothing, so there is nothing for _check_kernel_array_access to check. Guarding the call on total_dim_size > 0 is a one-line fix and I have it ready with a test in warp/tests/test_overwrite.py; I will open a PR against this issue.

System Information

Warp 1.17.0 (pip) and current main (13f9a110), Python 3.12, macOS 27.0 arm64, CPU device. The relevant code is the same on both: on main the assignment is at context.py:11582 inside the guard spanning 11581-11902, and the only read outside it is at 11915.