Skip to content

fix(training): exclude dropped anchor blocks from the DSpark loss and metrics - #2

Closed
khazic wants to merge 1 commit into
khazic/feat/dspark-corefrom
khazic/fix/dspark-block-keep-mask
Closed

khazic wants to merge 1 commit into
khazic/feat/dspark-corefrom
khazic/fix/dspark-block-keep-mask

Conversation

@khazic

@khazic khazic commented Aug 2, 2026

Copy link
Copy Markdown
Owner

What

block_keep_mask was consumed only by the tau diagnostic. The loss weight was built from eval_mask alone, so a dropped anchor block (keep = 0) whose eval prefix was still set received full CE/TV/confidence gradient, and its positions were averaged into accept_rate, biasing both the objective and the diagnostics.

Fix

Define the supervised-position mask once in dspark_loss (supervised = eval_mask * block_keep_mask.unsqueeze(-1)), derive the decayed loss weight from it, and pass it into _acceptance_metrics (now keyword-only per the repo style rule on same-type parameters). One mask drives the loss weight, accept_rate, and the tau block validity, so the three sites cannot drift.

Tests

Two new unit tests: dropped blocks produce exactly zero gradient and the loss equals the eval-mask-zeroed equivalent; accept_rate/tau ignore a dropped block that deliberately mismatches the teacher. Both fail on the parent commit and pass here. All 18 dspark unit tests pass; ruff is clean.

Merge note

khazic/fix/dspark-masked-input-robustness sanitizes padded inputs keyed on eval_mask alone. Whichever of the two branches merges into khazic/feat/dspark-core second should rebase that sanitization onto the combined supervised mask (one-line change: build supervised first and use supervised.bool() as the scrub mask), so that positions of dropped anchors are scrubbed as well as zero-weighted.

… metrics

Signed-off-by: khazic <khazzz1c@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c4dae9188c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +146 to +147
supervised = outputs.eval_mask.to(torch.float32) * outputs.block_keep_mask.to(torch.float32).unsqueeze(-1)
weight = _loss_weight_mask(supervised, block_size, loss_decay_gamma) # [B, N, L]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Sanitize dropped positions before evaluating token losses

When a dropped block contains padded out-of-range target IDs or non-finite draft/teacher logits, constructing a zero supervised weight does not actually exclude it: cross-entropy and softmax/BCE still evaluate every position before weighting, so CE can raise on the discarded label and NaN * 0 can poison the loss, gradients, and metrics. Select or replace unsupervised inputs with safe values before these nonlinear operations rather than relying only on post-hoc multiplication.

Useful? React with 👍 / 👎.

Comment on lines +60 to +61
block_keep_mask: Kept-anchor mask ``[batch, num_blocks]``; dropped anchors
are excluded from the loss and the acceptance metrics.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add the required DCO sign-off trailer

The reviewed commit has no Signed-off-by trailer, so it violates the repository's mandatory signed-commit policy and can be rejected by the DCO gate; recreate the commit using git commit -s before merging.

AGENTS.md reference: AGENTS.md:L39-L43

Useful? React with 👍 / 👎.

@khazic

khazic commented Aug 2, 2026

Copy link
Copy Markdown
Owner Author

Superseded by the upstream PRs (NVIDIA-NeMo/Megatron-Bridge NVIDIA-NeMo#5241 NVIDIA-NeMo#5242 NVIDIA-NeMo#5243 NVIDIA-NeMo#5244).

@khazic khazic closed this Aug 2, 2026
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