nemo_rl.models.megatron.draft.block_plan#
Module Contents#
Classes#
Immutable tensor plan for anchored DFlash blocks. |
Functions#
Build a deterministic, device-resident DFlash anchor schedule. |
Data#
API#
- nemo_rl.models.megatron.draft.block_plan._HASH_MODULUS#
2147483647
- nemo_rl.models.megatron.draft.block_plan._HASH_MULTIPLIER#
73244475
- nemo_rl.models.megatron.draft.block_plan._mix_anchor_ids(anchor_ids: torch.Tensor) torch.Tensor#
- class nemo_rl.models.megatron.draft.block_plan.DFlashBatchPlan#
Immutable tensor plan for anchored DFlash blocks.
- batch_size: int#
None
- sequence_length: int#
None
- anchors_per_sample: int#
None
- gamma: int#
None
- block_size: int#
None
- token_valid_mask: torch.Tensor#
None
- sample_rows: torch.Tensor#
None
- anchor_positions: torch.Tensor#
None
- query_positions: torch.Tensor#
None
- label_positions: torch.Tensor#
None
- slot_valid: torch.Tensor#
None
- loss_mask: torch.Tensor#
None
- nemo_rl.models.megatron.draft.block_plan.build_dflash_batch_plan(
- token_valid_mask: torch.Tensor,
- sample_ids: torch.Tensor,
- *,
- anchors_per_sample: int,
- gamma: int,
- optimizer_step: int,
- seed: int,
Build a deterministic, device-resident DFlash anchor schedule.
Called by DFlashSpeculator.prepare_batch in PR #3757.
The schedule for a row depends only on
sample_ids[row],optimizer_step,seedand the anchor slot. It does not depend on the row position, the microbatch split or the data-parallel rank. Thus, a permuted or sliced batch keeps the same anchors for each sample.Rows with the same
sample_idget the same schedule. This is intentional. Give each rollout row a unique ID, for example from the group ID and the index in the group. Do not use one ID for all rollouts of a prompt. This function does not check uniqueness, because a check needs a host synchronization.