Skip to content

fix(data): support GLM-4.5V assistant masking - #5001

Merged
cuichenx merged 3 commits into
mainfrom
chcui/sage/fix-glm45v-assistant-mask
Jul 23, 2026
Merged

cuichenx merged 3 commits into
mainfrom
chcui/sage/fix-glm45v-assistant-mask

Conversation

@cuichenx

Copy link
Copy Markdown
Contributor

Summary

  • add explicit GLM-4.5V assistant and next-role boundaries for loss-mask construction
  • trim only the template's empty thinking prefix while preserving real reasoning and tool-call content
  • delimit the final assistant span with a temporary EOS sentinel that is removed before the mask is returned

NVBug 6468521

Root cause

GLM-4.5V's chat template has no Jinja generation block and ends its final assistant turn without a terminator. The boundary-based assistant-mask path therefore had neither a Hugging Face assistant mask nor a known marker configuration and failed on the first collated batch.

Validation

  • reproduced the failure with the stock 26.08 RC2 production collator on CORD-v2
  • verified the fixed collator on the same input: shape (1, 2227) and 786 assistant-loss tokens, matching the historical 26.06 control
  • uv run python -m pytest tests/unit_tests/data/collators/test_model_collators.py tests/unit_tests/data/test_conversation_processing.py — 131 passed
  • uv run pre-commit run --all-files
  • independent review completed on the exact final signed head

This PR intentionally targets main only. The 26.08 release branch has not been cut, so no mapped release label or cherry-pick PR is available.

AI assistance

This PR was authored by an AI coding agent under user direction and independently reviewed by a separate AI agent.

cuichenx added 2 commits July 21, 2026 14:58
Signed-off-by: Chen Cui <chcui@nvidia.com>
Signed-off-by: Chen Cui <chcui@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@cuichenx cuichenx added bug Something isn't working area:data Dataset builders, preprocessing, and samplers labels Jul 22, 2026
@cuichenx
cuichenx marked this pull request as ready for review July 22, 2026 00:44
@claude

claude Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

LGTM. GLM-4.5V-specific assistant loss masking is a focused, correct change.

Correctness

  • The virtual-EOS pattern in _build_glm4v_assistant_loss_mask is sound: EOS is appended to delimit the final assistant span, then the trailing element is trimmed so it is never returned or trained. The ValueError guard when eos_token_id is None is the right fail-fast behavior.
  • The old infer_assistant_mask_boundary_config import is fully removed with no dangling references in src or tests.
  • The trim_leading_token_sequences handling for the empty think prefix correctly guards against an empty tokenization result before wrapping in a tuple.

Tests: the new parametrized test exercises multi-turn masking, a sequence already ending in EOS, and an observation-role boundary, and the monkeypatch targets in the existing packing test were updated to the new private helper names.

Suggested test cases

  • test_glm4v_assistant_mask_uses_role_boundaries_and_virtual_final_terminator
  • test_glm4v_collate_packs_mm_token_type_ids_and_restores_padding

No perf tests impacted.

@yaoyu-33 yaoyu-33 added the ready-to-merge PR is approved, current, and only waiting for CI to pass before merge label Jul 22, 2026
Signed-off-by: Chen Cui <chcui@nvidia.com>
@cuichenx
cuichenx merged commit 600077b into main Jul 23, 2026
72 checks passed
@cuichenx
cuichenx deleted the chcui/sage/fix-glm45v-assistant-mask branch July 23, 2026 17:54

This branch was previously deployed

2 inactive deployments
public — c9a5b499 Deployed Jul 22, 2026 by copy-pr-bot[bot] via release / finalize / publish-docs #3167
test — c9a5b499 Deployed Jul 22, 2026 by copy-pr-bot[bot] via cicd-wait-in-queue #18541
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:data Dataset builders, preprocessing, and samplers bug Something isn't working ready-to-merge PR is approved, current, and only waiting for CI to pass before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants