Skip to content

RF mask_nested: dim sizes on the mask device under static tracing - #2017

Draft
albertz wants to merge 2 commits into
masterfrom
albert-rf-mask-nested-static-device
Draft

albertz wants to merge 2 commits into
masterfrom
albert-rf-mask-nested-static-device

Conversation

@albertz

@albertz albertz commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

For #2014.

rf.nested.mask_nested merging two dims read both sizes at the default dim-size device (CPU).
Under static tracing that is a device-to-host copy, which copy_to_device rejects
(illegal under CUDA graph capture).
Now the sizes are read on the device of the mask then; the capacity of the merged dim is kept as before.
Eager is unchanged.

Hit in the beam search under static tracing: the per-hypothesis KV history dims are merged by mask_nested.

Tests in tests/test_rf_array.py, both on two nested states, each a bounded per-hypothesis history dim
and a KV tensor over it (masked lengths, the masked KV refers to the merged dim):

  • test_mask_nested_kv_states_static_traceable_cuda (CUDA only, skipped in CI):
    under static tracing, the lengths stay on the device and the capacity is kept.
  • test_mask_nested_kv_states_eager_cpu: an ordinary eager CPU caller.

RZ H100, torch 2.12: both pass, together with the existing mask_nested test.
On master the CUDA one fails with copy_to_device: device-to-host copy of Tensor{'a', ['batch'(3)], dtype='int32'} under static traceable,
the CPU one passes (unchanged behavior).

Merging two dims read both sizes at the default dim-size device (CPU),
which under static tracing is a device-to-host copy (copy_to_device raises, illegal under CUDA graph capture).
Now the sizes are read on the device of the mask then.
Eager is unchanged.
Two nested states, each a bounded per-hypothesis history dim and a KV tensor over it:
masked lengths, the masked KV refers to the merged dim,
and under static tracing on CUDA the lengths stay on the device and the capacity is kept.
Same check for an ordinary eager CPU caller.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant