Now I understand the issue. Let me analyze it:
-
In compute_forward_kl_topk in /verl/verl/trainer/distillation/megatron/losses.py, when data_format == "bshd", it calls preprocess_bshd_engine on teacher_topk_log_probs and teacher_topk_ids.
-
Both teacher_topk_log_probs and teacher_topk_ids are nested tensors (as confirmed by the assertion assert teacher_topk_log_probs.is_nested and teacher_topk_ids.is_nested).
-
The docstring says teacher_topk_log_probs has shape (bsz, seqlen, topk), which is a nested tensor.
-
The issue is that preprocess_bshd_engine expects a nested tensor with shape [n, length] (1D jagged per batch element), but teacher_topk_log_probs has shape [bsz, length, topk] - it has 3 dimensions (batch, sequence, topk).
-
Inside preprocess_bshd_engine, it calls input_ids.offsets().diff() to get the sequence lengths, which works on nested tensors. But the function then expects each element in the nested tensor to be 1D (just the sequence tokens), not 3D with [length, topk].
-
The preprocess_thd_engine function also uses input_ids.offsets().diff() but it has this code:
shape = list(input_ids.shape[1:]) # Get shape excluding batch dimension
shape[0] = sum(seqlens_in_batch_padded_cpu) // cp_size # Adjust first dim
This preserves any trailing dimensions after the first dimension.
Let me compare the two functions more carefully. The preprocess_thd_engine function handles multi-dimensional data (it preserves trailing dimensions), while preprocess_bshd_engine seems to only work with 2D data.
Looking at preprocess_bshd_engine:
batch_size = input_ids.shape[0]
seqlens_in_batch = input_ids.offsets().diff()
For a nested tensor with shape [bsz, length, topk], offsets().diff() should give [bsz] sequence lengths. But then the function assumes input_ids[i] is 1D:
input_ids_bshd[i, :seqlen_i] = input_ids[i]
This would fail because input_ids[i] is [seqlen, topk], not [seqlen].
So the fix should be to modify preprocess_bshd_engine to handle multi-dimensional nested tensors like preprocess_thd_engine does. Or, alternatively, we could reshape the 3D tensor before passing it to preprocess_bshd_engine.
Let me look at how preprocess_thd_engine handles this:
shape = list(input_ids.shape[1:]) # This gets [seqlen, topk] for a 3D nested tensor
shape[0] = sum(seqlens_in_batch_padded_cpu) // cp_size
So it preserves the trailing dimensions. The preprocess_bshd_engine function needs similar handling.
Looking at the code more carefully, in preprocess_bshd_engine:
input_ids_bshd[i, :seqlen_i] = input_ids[i]
This should be:
input_ids_bshd[i, :seqlen_i] = input_ids[i] # This works if input_ids[i] is [seqlen, ...]
But the issue is that input_ids_bshd is created as:
shape = list(input_ids.shape) # [batch_size, seq_len,...]
seq_len = seq_lens.max().item()
shape[1] = seq_len
if sequence_parallel:
...
shape[1] = seq_len
For a nested tensor with shape [bsz, length, topk], the input_ids.shape might not work the same way since nested tensors have jagged shapes.
Let me check what happens with nested tensors. For a nested tensor:
input_ids.shape returns torch.Size([bsz, seqlen, topk]) (but seqlen is the max)
input_ids.offsets().diff() returns [seqlen_0, seqlen_1, ...]
So for a nested tensor with shape [bsz, length, topk] where length is jagged:
input_ids.shape[0] = batch_size
input_ids.shape[1:] = [length, topk]
In preprocess_bshd_engine:
batch_size = input_ids.shape[0]
seqlens_in_batch = input_ids.offsets().diff() # [bsz] with jagged lengths
But then:
shape = list(input_ids.shape) # [batch_size, max_seq_len, topk]
shape[0] = sum(seqlens_in_batch_padded_cpu) // cp_size # This changes batch dimension incorrectly
This is the bug! The function is designed for 2D tensors (batch, seqlen) and doesn't handle the extra trailing dimensions properly.
Wait, I need to reconsider. Let me look at how the function works for 2D input vs 3D input.
For a 2D nested tensor [bsz, seqlen]:
input_ids.shape = [bsz, seqlen] (approximately)
shape = list(input_ids.shape) = [bsz, seqlen]
- After:
shape[0] = sum(seqlens_in_batch_padded_cpu) // cp_size
- So
shape = [packed_len, seqlen] where packed_len is the total packed sequence length
But wait, that doesn't make sense. Let me re-read the function more carefully...
Actually, I think the issue is that preprocess_bshd_engine is designed to work with nested tensors where each element is a 1D sequence (e.g., token IDs). When given a nested tensor where each element is a 2D tensor (e.g., [seqlen, topk]), the function fails because it doesn't account for the trailing dimensions.
Let me trace through what happens for a 3D nested tensor [bsz, seqlen, topk]:
batch_size = input_ids.shape[0] → works fine
seqlens_in_batch = input_ids.offsets().diff() → returns [seqlen_0, seqlen_1, ...]
max_seqlen = seqlens_in_batch.max().item() → works fine
input_ids_bshd = torch.zeros(batch_size, local_max_seqlen, dtype=input_ids.dtype, device=input_ids.device) → This is 2D [batch_size, local_max_seqlen], but it should be 3D [batch_size, local_max_seqlen, topk]
This is the root cause! The function creates a 2D output tensor but the input is 3D.
Similarly for preprocess_thd_engine:
shape = list(input_ids.shape[1:]) # For 3D: [seqlen, topk]
shape[0] = sum(seqlens_in_batch_padded_cpu) // cp_size # Adjust first dim
This correctly preserves the trailing dimensions.
So the fix for preprocess_bshd_engine should be to handle trailing dimensions properly. Let me modify the function to support multi-dimensional nested tensors.
Actually wait, let me check what input_ids.shape returns for a nested tensor more carefully...
For a nested tensor created via torch.nested.as_nested_tensor:
nested_tensor.shape returns the jagged shape, which includes all dimensions.
- For
as_nested_tensor([seq0, seq1, ...]) where each seq is 2D, the shape would be [n, seqlen, dim] (with seqlen being the max).
So for teacher_topk_log_probs which is a nested tensor with shape [bsz, seqlen, topk]:
input_ids.shape[0] = batch_size
input_ids.shape[1] = max_seqlen (approximately)
input_ids.shape[2] = topk
The fix should modify preprocess_bshd_engine to handle multi-dimensional nested tensors by preserving trailing dimensions.
Let me write the fix. I need to:
- Save the trailing dimensions
- Create the output tensor with the correct trailing dimensions
- Handle the data copying correctly
Here's my plan:
In preprocess_bshd_engine, after getting the batch_size and seqlens:
- Get the trailing shape:
trailing_shape = input_ids.shape[1:] which for 3D would be [max_seqlen, topk]
- Create
input_ids_bshd with shape [batch_size, local_max_seqlen] + trailing_shape[1:]
Actually, I realize the issue is more subtle. Let me look at the code path for CP > 1:
if cp_size > 1:
seq = input_ids[i]
if seqlen_i < max_seqlen:
seq_padded = torch.zeros(max_seqlen, dtype=seq.dtype, device=seq.device)
seq_padded[:seqlen_i] = seq
seq = seq_padded
chunk_len = max_seqlen // (2 * cp_size)
first_start = cp_rank * chunk_len
second_start = (2 * cp_size - cp_rank - 1) * chunk_len
first_chunk = seq[first_start : first_start + chunk_len]
second_chunk = seq[second_start : second_start + chunk_len]
local_seq = torch.cat((first_chunk, second_chunk), dim=0)
For a 2D nested tensor where input_ids[i] is [seqlen, topk]:
seq = input_ids[i] is [seqlen, topk]
seq_padded[:seqlen_i] = seq works for 2D
seq[first_start : first_start + chunk_len] - this slices along the first dimension only, which is correct for 2D
But the output tensor input_ids_bshd is 2D [batch_size, local_max_seqlen], so when we do:
input_ids_bshd[i] = local_seq
It fails because local_seq is 2D [2*chunk_len, topk] but input_ids_bshd[i] is 1D [local_max_seqlen].
So the fix needs to:
- Change
input_ids_bshd to be 3D: [batch_size, local_max_seqlen, topk]
- Change
input_ids_bshd[i] = local_seq to work with 3D
Let me also check the position_ids handling:
position_ids = torch.arange(local_max_seqlen, dtype=torch.long, device=input_ids.device)
position_ids = position_ids.unsqueeze(0).expand_as(input_ids_bshd)
For 2D input_ids_bshd, this would be [batch_size, local_max_seqlen]. For 3D, we'd need [batch_size, local_max_seqlen, topk] which is correct with expand_as.
OK so the fix is:
- Detect if input is multi-dimensional nested tensor
- If so, preserve the trailing dimensions in the output
Let me now look at the preprocess_thd_engine to see how it handles this:
shape = list(input_ids.shape[1:])
shape[0] = sum(seqlens_in_batch_padded_cpu) // cp_size
if pre_process:
input_ids_rmpad = torch.zeros(shape, dtype=input_ids.dtype, device=input_ids.device)
for i in range(batch_size):
seqlen_i = int(seqlens_in_batch_cpu[i])
if cp_size <= 1:
...
input_ids_rmpad[start_idx : start_idx + seqlen_i] = input_ids[i]
continue
# CP case...
So preprocess_thd_engine uses input_ids.shape[1:] to get the trailing dimensions. The same approach should work for preprocess_bshd_engine.
Now let me write the fix for preprocess_bshd_engine:
def preprocess_bshd_engine(
input_ids: torch.Tensor, pre_process: bool = True, need_roll: bool = False, use_fp8_padding: bool = False
):
"""
Preprocess bshd sequences
return "input_ids, attention_mask, position_ids"
"""
cp_size = mpu.get_context_parallel_world_size()
cp_rank = mpu.get_context_parallel_rank()
batch_size = input_ids.shape[0]
seqlens_in_batch = input_ids.offsets().diff()
max_seqlen = seqlens_in_batch.max().item()
tp_size = mpu.get_tensor_model_parallel_world_size()
# ... alignment code ...
# Get trailing dimensions (e.g., topk for [bsz, seqlen, topk])
trailing_shape = input_ids.shape[1:] # For 3D: [max_seqlen, topk]
local_max_seqlen = max_seqlen // cp_size if cp_size > 1 else max_seqlen
attention_mask = torch.zeros(batch_size, local_max_seqlen, dtype=torch.bool, device=input_ids.device)
# Change: add trailing dimensions
input_ids_bshd = torch.zeros(batch_size, local_max_seqlen, *trailing_shape[1:], dtype=input_ids.dtype, device=input_ids.device)
Wait, but trailing_shape would be [max_seqlen, topk] for a 3D nested tensor. So trailing_shape[1:] would be [topk]. So the output shape would be [batch_size, local_max_seqlen, topk].
But there's a problem: max_seqlen is the jagged max, not local_max_seqlen. We need to handle the slicing correctly.
Actually, looking at the function more carefully, I see that for the CP case:
seq = input_ids[i] # [seqlen_i, topk]
if seqlen_i < max_seqlen:
seq_padded = torch.zeros(max_seqlen, dtype=seq.dtype, device=seq.device)
seq_padded[:seqlen_i] = seq
seq = seq_padded # [max_seqlen, topk]
For a 2D tensor (each seq element is 2D with shape [seqlen, topk]):
seq_padded[:seqlen_i] = seq works because both are 2D
seq[first_start : first_start + chunk_len] slices the first dim
And:
input_ids_bshd[i] = local_seq # Should be [local_max_seqlen, topk]
So I need to change input_ids_bshd to be 3D. Let me check if this works with input_ids_bshd[i, :seq_len]:
input_ids_bshd[i, :seqlen_i] = input_ids[i]
If input_ids_bshd is [batch_size, local_max_seqlen, topk], then input_ids_bshd[i, :seqlen_i] is [seqlen_i, topk], which matches input_ids[i] when input_ids[i] is [seqlen_i, topk].
So the fix is to change:
input_ids_bshd = torch.zeros(batch_size, local_max_seqlen, dtype=input_ids.dtype, device=input_ids.device)
to:
# Get trailing dimensions (e.g., for [bsz, seqlen, topk], trailing is [max_seqlen, topk])
trailing_shape = input_ids.shape[1:]
input_ids_bshd = torch.zeros(batch_size, local_max_seqlen, *trailing_shape[1:], dtype=input_ids.dtype, device=input_ids.device)
And similarly for the CP case where we create seq_padded:
seq_padded = torch.zeros(max_seqlen, dtype=seq.dtype, device=seq.device)
This needs to preserve trailing dimensions:
seq_padded = torch.zeros(max_seqlen, *trailing_shape[1:], dtype=seq.dtype, device=seq.device)
Let me write the complete fix now.
Actually, let me double-check by looking at how input_ids[i] works for nested tensors:
For a nested tensor nt = torch.nested.as_nested_tensor([seq0, seq1, ...]) where each seq is 2D:
nt.shape returns [n, seqlen, dim] (with seqlen being jagged)
nt[0] returns the first sequence as a 2D tensor with shape [seqlen_0, dim]
So input_ids[i] for a 3D nested tensor would be [seqlen_i, topk]. This confirms my analysis.
Now let me write the fix. I need to modify preprocess_bshd_engine in /verl/verl/models/mcore/util.py.
Wait, but the issue says the problem is in /verl/verl/trainer/distillation/megatron/losses.py. Let me reconsider. Maybe the fix should be in the losses.py file instead, by converting the nested tensor to a different format before passing it to preprocess_bshd_engine.
Looking at the FSDP version:
teacher_topk_log_probs = teacher_topk_log_probs.values().unsqueeze(0) # (1, total_nnz, topk)
teacher_topk_ids = teacher_topk_ids.values().unsqueeze(0) # (1, total_nnz, topk)
The FSDP version converts the nested tensor to a dense tensor. Maybe the Megatron version should do something similar?
But wait, the Megatron version uses preprocess_bshd_engine for the "bshd" format, which is designed for packed sequences. The preprocess_thd_engine is also designed for packed sequences. So both functions expect nested tensor inputs.
The issue is that preprocess_bshd_engine was written to handle only 2D nested tensors (token IDs), but teacher_topk_log_probs is a 3D nested tensor (log probs for top-k tokens).
So the fix should be in preprocess_bshd_engine to handle 3D (or more) nested tensors.
Let me create the fix now.
Actually, wait. Let me check what input_ids.shape returns for a nested tensor. I want to make sure I understand the shape correctly.
For torch.nested.as_nested_tensor:
nt = torch.nested.as_nested_tensor([torch.randn(3, 5), torch.randn(4, 5)])
print(nt.shape) # torch.Size([2, 4, 5]) # max length is 4
So for a nested tensor with shape [bsz, seqlen, topk]:
nt.shape[0] = bsz
nt.shape[1] = max(seqlen) across batch = max_seqlen
nt.shape[2] = topk
But nt.shape is jagged, so nt.shape[1] might not be the actual sequence length for any element.
Let me verify by looking at how preprocess_thd_engine handles this:
shape = list(input_ids.shape[1:]) # For 3D: [max_seqlen, topk]
shape[0] = sum(seqlens_in_batch_padded_cpu) // cp_size
So preprocess_thd_engine uses input_ids.shape[1:] to get the trailing dimensions. For a 3D nested tensor, this would be [max_seqlen, topk].
Now, in preprocess_bshd_engine:
shape = list(input_ids.shape) # [batch_size, max_seqlen, topk]
seq_len = seq_lens.max().item() # max_seqlen
shape[0] = sum(seqlens_in_batch_padded_cpu) // cp_size
This gives shape = [packed_len, max_seqlen, topk], which is wrong because:
- The first dimension should be the total packed length (not batch_size)
- The second dimension should be the local sequence length per CP rank (not max_seqlen)
Actually wait, I'm confusing myself. Let me re-read the function:
batch_size = input_ids.shape[0]
seqlens_in_batch = input_ids.offsets().diff()
max_seqlen = seqlens_in_batch.max().item()
...
shape = list(input_ids.shape) # [batch_size, max_seqlen, topk]
seq_len = seq_lens.max().item() # This is redundant with max_seqlen
if sequence_parallel:
...
shape[1] = seq_len
Hmm, seq_len = seq_lens.max().item() is redundant since max_seqlen already captures that. But seq_lens might be a different tensor (from attention_mask.sum(dim=1)).
OK so for a 3D nested tensor [bsz, max_seqlen, topk]:
shape = list(input_ids.shape) = [bsz, max_seqlen, topk]
Then:
shape[0] = sum(seqlens_in_batch_padded_cpu) // cp_size # For pre_process, this changes to packed_len
So after this, shape = [packed_len, max_seqlen, topk]. This is the shape of the output tensor when pre_process=True.
But then the output is:
input_ids_bshd = torch.zeros(batch_size, local_max_seqlen, dtype=input_ids.dtype, device=input_ids.device)
Wait, this line creates a tensor with shape [batch_size, local_max_seqlen], not [packed_len, ...]. But the comment says "For pre_process". I'm confused.
Let me re-read the function more carefully:
local_max_seqlen = max_seqlen // cp_size if cp_size > 1 else max_seqlen
attention_mask = torch.zeros(batch_size, local_max_seqlen, dtype=torch.bool, device=input_ids.device)
input_ids_bshd = torch.zeros(batch_size, local_max_seqlen, dtype=input_ids.dtype, device=input_ids.device)
So input_ids_bshd has shape [batch_size, local_max_seqlen] regardless of whether we're in pre_process mode.
OK so the function is designed for 2D input [batch_size, seqlen] and outputs [batch_size, local_max_seqlen]. For 3D input [batch_size, seqlen, topk], we need to output [batch_size, local_max_seqlen, topk].
Actually wait, I see now that for pre_process=True, the function returns the preprocessed tensor, and for pre_process=False, it returns the original tensor. Let me look at the return statements:
if pre_process:
return input_ids_bshd, attention_mask, position_ids
So for pre_process=True, the function creates new tensors with the preprocessed shapes.
For 2D input [batch_size, seqlen]:
input_ids_bshd has shape [batch_size, local_max_seqlen]
attention_mask has shape [batch_size, local_max_seqlen]
For 3D input [batch_size, seqlen, topk]:
input_ids_bshd should have shape [batch_size, local_max_seqlen, topk]
attention_mask should have shape [batch_size, local_max_seqlen] (still 2D)
And then the slicing operations:
input_ids_bshd[i, :seqlen_i] = input_ids[i]
For 2D: input_ids_bshd[i, :seqlen_i] is [seqlen_i], input_ids[i] is [seqlen_i]. ✓
For 3D: input_ids_bshd[i, :seqlen_i] is [seqlen_i, topk], input_ids[i] is [seqlen_i, topk]. ✓
So the fix is just to change the shape of input_ids_bshd to preserve trailing dimensions.
Let me also check the CP case:
seq = input_ids[i] # [seqlen_i, topk] for 3D
seq_padded = torch.zeros(max_seqlen, dtype=seq.dtype, device=seq.device) # [max_seqlen] for 2D
seq_padded[:seqlen_i] = seq # Works for 1D, fails for 2D
For 2D: seq is [seqlen_i], seq_padded is [max_seqlen]. ✓
For 3D: seq is [seqlen_i, topk], seq_padded is [max_seqlen]. ✗
So we need to change seq_padded to preserve trailing dimensions:
trailing_shape = input_ids.shape[1:] # [max_seqlen, topk] for 3D
seq_padded = torch.zeros(max_seqlen, *trailing_shape[1:], dtype=seq.dtype, device=seq.device) # [max_seqlen, topk]
And similarly for local_seq:
local_seq = torch.cat((first_chunk, second_chunk), dim=0) # [2*chunk_len, topk] for 3D
input_ids_bshd[i] = local_seq # Should assign to [local_max_seqlen, topk]
For this to work, input_ids_bshd[i] should be [local_max_seqlen, topk].
OK, I think I have a clear understanding now. Let me write the fix.
Actually, let me look at the whole function more carefully to make sure I don't miss anything:
def preprocess_bshd_engine(
input_ids: torch.Tensor, pre_process: bool = True, need_roll: bool = False, use_fp8_padding: bool = False
):
cp_size = mpu.get_context_parallel_world_size()
cp_rank = mpu.get_context_parallel_rank()
batch_size = input_ids.shape[0]
seqlens_in_batch = input_ids.offsets().diff()
max_seqlen = seqlens_in_batch.max().item()
tp_size = mpu.get_tensor_model_parallel_world_size()
align_size = tp_size * cp_size * 2 if cp_size > 1 else tp_size
if align_size > 1:
pad_size = (align_size - max_seqlen % align_size) % align_size
max_seqlen += pad_size
if use_fp8_padding:
# ... FP8 padding code ...
local_max_seqlen = max_seqlen // cp_size if cp_size > 1 else max_seqlen
attention_mask = torch.zeros(batch_size, local_max_seqlen, dtype=torch.bool, device=input_ids.device)
input_ids_bshd = torch.zeros(batch_size, local_max_seqlen, dtype=input_ids.dtype, device=input_ids.device)
seqlens_in_batch_cpu: list[int] = seqlens_in_batch.tolist()
for i in range(batch_size):
seqlen_i = int(seqlens_in_batch_cpu[i])
if cp_size <= 1:
attention_mask[i, :seqlen_i] = True
input_ids_bshd[i, :seqlen_i] = input_ids[i]
continue
seq = input_ids[i]
if seqlen_i < max_seqlen:
seq_padded = torch.zeros(max_seqlen, dtype=seq.dtype, device=seq.device)
seq_padded[:seqlen_i] = seq
seq = seq_padded
chunk_len = max_seqlen // (2 * cp_size)
first_start = cp_rank * chunk_len
second_start = (2 * cp_size - cp_rank - 1) * chunk_len
first_chunk = seq[first_start : first_start + chunk_len]
second_chunk = seq[second_start : second_start + chunk_len]
local_seq = torch.cat((first_chunk, second_chunk), dim=0)
if need_roll:
local_pos = torch.cat(
(
torch.arange(first_start, first_start + chunk_len, dtype=torch.long, device=seq.device),
torch.arange(second_start, second_start + chunk_len, dtype=torch.long, device=seq.device),
),
dim=0,
)
local_seq = seq[(local_pos + 1) % max_seqlen]
input_ids_bshd[i] = local_seq
valid_first = max(0, min(seqlen_i - first_start, chunk_len))
valid_second = max(0, min(seqlen_i - second_start, chunk_len))
if valid_first > 0:
attention_mask[i, :valid_first] = True
if valid_second > 0:
attention_mask[i, chunk_len : chunk_len + valid_second] = True
if cp_size <= 1:
position_ids = torch.arange(local_max_seqlen, dtype=torch.long, device=input_ids.device)
position_ids = position_ids.unsqueeze(0).expand_as(input_ids_bshd)
else:
chunk_len = max_seqlen // (2 * cp_size)
first_pos = torch.arange(
cp_rank * chunk_len, (cp_rank + 1) * chunk_len, dtype=torch.long, device=input_ids.device
)
second_pos = torch.arange(
max_seqlen - (cp_rank + 1) * chunk_len,
max_seqlen - cp_rank * chunk_len,
dtype=torch.long,
device=input_ids.device,
)
position_ids = torch.cat((first_pos, second_pos), dim=0).unsqueeze(0).expand_as(input_ids_bshd)
if need_roll and cp_size <= 1:
input_ids_bshd = torch.roll(input_ids_bshd, shifts=-1, dims=1)
if is_npu_available:
attention_mask = _build_npu_attn_mask(attention_mask)
return input_ids_bshd, attention_mask, position_ids
Now I need to identify all the places where trailing dimensions need to be preserved:
input_ids_bshd creation: torch.zeros(batch_size, local_max_seqlen, ...) → torch.zeros(batch_size, local_max_seqlen, *trailing_dims)
seq_padded creation: torch.zeros(max_seqlen, ...) → torch.zeros(max_seqlen, *trailing_dims)
- The
need_roll case: local_seq = seq[(local_pos + 1) % max_seqlen] - this might need special handling
For need_roll, the current code does:
local_seq = seq[(local_pos + 1) % max_seqlen]
For a 1D tensor, this works fine. For a 2D tensor [seqlen, topk], this would index the first dimension only and preserve the second dimension. So this should work.
Wait, let me check. local_pos is [2*chunk_len]. seq is [max_seqlen, topk]. local_pos + 1 % max_seqlen is [2*chunk_len]. seq[indices] would be [2*chunk_len, topk]. Yes, this works for 2D.
But wait, seq in the need_roll case might be the padded seq. Let me check:
if need_roll:
local_pos = torch.cat((...))
local_seq = seq[(local_pos + 1) % max_seqlen]
Here seq is either:
input_ids[i] if seqlen_i >= max_seqlen (not padded)
seq_padded if seqlen_i < max_seqlen (padded)
For a 2D nested tensor, both are [seqlen_or_max_seqlen, topk]. So seq[local_pos] would be [2*chunk_len, topk]. ✓
OK so the fix is straightforward. Let me write it now.
Let me now verify by checking if there are any tests I can run:
<tool_call>
<function=bash_terminal>
<parameter=command>
find /verl/tests -name "*.py" | xargs grep -l "preprocess_bshd_engine|megatron.*loss|compute_forward_kl_topk" 2>/dev/null
</tool_call>