Skip to content

fix: align channel loss with sequence parallel labels - #9977

Merged
hjh0119 merged 1 commit into
modelscope:mainfrom
taking-lying-flat:fix/issue-9973-channel-loss-sp
Sep 7, 2026
Merged

fix: align channel loss with sequence parallel labels#9977
hjh0119 merged 1 commit into
modelscope:mainfrom
taking-lying-flat:fix/issue-9973-channel-loss-sp

Conversation

@taking-lying-flat

@taking-lying-flat taking-lying-flat commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

PR type

  • Bug Fix
  • New Feature
  • Document Updates
  • More Models or Datasets Support

PR information

Fixes #9973.

When sequence parallelism is enabled, per_token_loss_func_sp gathers the per-token loss into the full-sequence layout, while channel-loss metrics still use labels from the local sequence shard. This causes an IndexError and applies the causal label shift twice.

This PR:

  • preserves the gathered labels returned by GatherLoss;
  • removes SP padding from the gathered loss and labels using the same mask;
  • reuses the already-shifted SP labels for channel masking;
  • flattens the aligned full-sequence loss and mask before channel slicing;
  • keeps packing/padding-free channel boundaries aligned with the full-sequence cu_seqlens;
  • preserves upstream SP loss_scale gathering and padding removal, so channel metrics use the same scaled full-sequence loss.

@taking-lying-flat
taking-lying-flat force-pushed the fix/issue-9973-channel-loss-sp branch from cc5b50d to 3e06621 Compare August 24, 2026 12:04
@hjh0119 hjh0119 self-assigned this Sep 2, 2026
@hjh0119

hjh0119 commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

thanks, can you resolve the conflicts?

@taking-lying-flat

Copy link
Copy Markdown
Contributor Author

thanks, can you resolve the conflicts?

just go home

@taking-lying-flat
taking-lying-flat force-pushed the fix/issue-9973-channel-loss-sp branch from 3e06621 to a394f7d Compare September 7, 2026 12:18
@hjh0119
hjh0119 merged commit 1ac8cc0 into modelscope:main Sep 7, 2026
3 checks passed
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.

enable_channel_loss crashes with IndexError when combined with sequence parallelism (sequence_parallel_size > 1)

2 participants