Skip to content

Comments

[fsdp] fix: make GDN work correctly when using ulysses and varlen sequence#5346

Open
nono-Sang wants to merge 1 commit intoverl-project:mainfrom
nono-Sang:gdn_fix
Open

[fsdp] fix: make GDN work correctly when using ulysses and varlen sequence#5346
nono-Sang wants to merge 1 commit intoverl-project:mainfrom
nono-Sang:gdn_fix

Conversation

@nono-Sang
Copy link

What does this PR do?

For the qwen3-next model, the original SFT implementation has the following issues:

  1. Because the computation of GatedDeltaNet is cross-tokens, sequence parallelism cannot be directly used.
  2. GatedDeltaNet in transformers does not take into account varlen sequence.

Therefore, I made the following fixes through the monkey patch:

  1. Support varlen input by adding the cu_seqlens parameter to GatedDeltaNet.
  2. Obtain the complete sequence before entering GatedDeltaNet, and obtain the corresponding fragments after completing the calculation. This ensures that GatedDeltaNet can work correctly when ulysses and use_remove_padding is turned on.

Checklist Before Starting

  • Search for similar PRs. Paste at least one query link here: ...
  • Format the PR title as [{modules}] {type}: {description} (This will be checked by the CI)
    • {modules} include fsdp, megatron, veomni, sglang, vllm, rollout, trainer, ci, training_utils, recipe, hardware, deployment, ray, worker, single_controller, misc, perf, model, algo, env, tool, ckpt, doc, data, cfg, reward
    • If this PR involves multiple modules, separate them with , like [megatron, fsdp, doc]
    • {type} is in feat, fix, refactor, chore, test
    • If this PR breaks any API (CLI arguments, config, function signature, etc.), add [BREAKING] to the beginning of the title.
    • Example: [BREAKING][fsdp, megatron] feat: dynamic batching

Test

For changes that can not be tested by CI (e.g., algorithm implementation, new model support), validate by experiment(s) and show results like training curve plots, evaluation results, etc.

API and Usage Example

Demonstrate how the API changes if any, and provide usage example(s) if possible.

# Add code snippet or script demonstrating how to use this

Design & Code Changes

Demonstrate the high-level design if this PR is complex, and list the specific changes.

Checklist Before Submitting

Important

Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces monkey patches for the qwen3-next model to make GatedDeltaNet compatible with Ulysses sequence parallelism and variable-length sequences. The changes involve gathering the full sequence within the patched GatedDeltaNet when sequence parallelism is used, and passing cu_seqlens to handle variable-length inputs. The trainer code is also updated to conditionally handle the validation dataset. The core logic for monkey-patching and handling sequence parallelism appears correct. However, I've identified a critical issue in the trainer logic that could lead to a crash during validation if a validation dataset is not provided but validation frequency is configured.


# early exit or validation step
if is_last_step or (self.config.trainer.test_freq > 0 and is_valid_step):
if self.config.trainer.test_freq > 0 and (is_last_step or is_valid_step):
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

There is a potential TypeError here. If self.config.trainer.test_freq > 0 but no validation dataset is provided (self.val_dataloader will be None), the code will enter this if block and then fail at the loop for val_data in self.val_dataloader:. This can happen if config.trainer.test_freq > 0 is set in the configuration but config.data.val_files is None. To prevent this crash, you should add a check to ensure self.val_dataloader is not None before attempting to iterate over it.

Suggested change
if self.config.trainer.test_freq > 0 and (is_last_step or is_valid_step):
if self.config.trainer.test_freq > 0 and self.val_dataloader is not None and (is_last_step or is_valid_step):

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