Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions slime/backends/megatron_utils/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def _allgather_cp_redistribute(
response_length,
dtype=ref_dtype,
device=ref_device,
requires_grad=True,
requires_grad=ref_value.requires_grad,
)
else:
resp_start = s - logit_global_start
Expand All @@ -213,7 +213,7 @@ def _allgather_cp_redistribute(
full_resps.append(full_resp)
seq_start += total_length

# Single differentiable all-reduce to gather full response from all CP ranks
# Single differentiable all-reduce to gather full response from all CP ranks.
all_cat = torch.cat(full_resps, dim=0)
all_cat = dist.nn.all_reduce(all_cat, group=cp_group)

Expand Down Expand Up @@ -444,9 +444,9 @@ def _extract_per_sample(
s = max(logit_global_start, chunk_start)
e = min(logit_global_end, chunk_end)
if e <= s:
log_probs_list.append(torch.zeros((0,), dtype=log_prob_full.dtype, device=log_prob_full.device))
log_probs_list.append(log_prob_full[:0])
if entropy_full is not None:
entropy_list.append(torch.zeros((0,), dtype=entropy_full.dtype, device=entropy_full.device))
entropy_list.append(entropy_full[:0])
else:
log_probs_list.append(log_prob_full[s - chunk_start : e - chunk_start])
if entropy_full is not None:
Expand Down Expand Up @@ -1073,7 +1073,8 @@ def policy_loss_function(
train_rollout_logprob_abs_diff = None
if "rollout_log_probs" in batch and batch["rollout_log_probs"]:
rollout_log_probs = torch.cat(batch["rollout_log_probs"], dim=0)
train_rollout_logprob_abs_diff = sum_of_sample_mean((old_log_probs - rollout_log_probs).abs())
log_probs_to_compare = log_probs if args.use_rollout_logprobs else old_log_probs
train_rollout_logprob_abs_diff = sum_of_sample_mean((log_probs_to_compare - rollout_log_probs).abs())

reported_loss = {
"loss": loss.clone().detach(),
Expand Down
Loading