Open
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request significantly enhances sequence parallelism support by implementing ZigZag Ring Attention for long-sequence training and Ulysses-style sequence parallelism for Qwen3.5 linear attention. It also introduces multimodal deepstack patching for Qwen3-VL and refactors the SequenceParallel strategy to better handle complex device meshes and packed/varlen inputs. Feedback focuses on improving code maintainability and robustness, specifically by grouping attributes in the SequenceParallel constructor, removing redundant logic and unused imports, replacing deprecated inspection methods, and centralizing duplicated loss-gathering logic.
Comment on lines
+37
to
53
| self.seq_world_size = None | ||
| self.sp_world_size = None | ||
| self.rp_world_size = None | ||
| self.dp_world_size = None | ||
| self.world_size = None | ||
| self.attn_implementation = None | ||
| self.model_dtype = None | ||
| self.tokenizer = None | ||
| self.device_mesh = None | ||
| self._sp_group = None | ||
| self._rp_group = None | ||
| self._data_rank_group = None | ||
| self._sp_rank = 0 | ||
| self._rp_rank = 0 | ||
| self.num_heads = None | ||
| self.causal_mask_func = None | ||
| self.extra_kwargs = {} |
Contributor
Comment on lines
+236
to
+239
| if query.shape[2] != total_tokens: | ||
| raise ValueError('Packed/varlen flash_attention_2 expects query sequence length to match ' | ||
| f'cu_seqlens total tokens, got query_seq_len={query.shape[2]} ' | ||
| f'and cu_seqlens_total={total_tokens}.') |
Contributor
Comment on lines
+481
to
+484
| if self.rp_world_size > 1: | ||
| attn_impl = getattr(model.config, '_attn_implementation', None) | ||
| if attn_impl != 'flash_attention_2': | ||
| raise NotImplementedError('Derived ring attention only supports flash_attention_2 backend.') |
Contributor
| @@ -0,0 +1,283 @@ | |||
| import os | |||
Contributor
Comment on lines
+115
to
+123
| @cache | ||
| def _get_default_args(func): | ||
| spec = inspect.getfullargspec(func) | ||
| defaults = spec.defaults if spec.defaults is not None else () | ||
| padded_defaults = (None, ) * (len(spec.args) - len(defaults)) + defaults | ||
| args = dict(zip(spec.args, padded_defaults)) | ||
| if 'softcap' in args: | ||
| args['softcap'] = 0.0 | ||
| return args |
Contributor
Comment on lines
+490
to
+491
| if self.sp_strategy is not None: | ||
| loss_inputs, loss_outputs = self.sp_strategy.gather_loss_tensors(inputs, outputs) |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR type
PR information
This PR adds context parallel and Qwen3.5 Gated DeltaNet sequence parallel support to the transformers stack, and refactors sequence parallel into a package-based implementation.
Main changes:
sequence_parallel.pyintosequence_parallel/and add shared utilities.linear_attention_sp.py;Ring attention is not supported for this path yet.sp_fsdp_dense.tests/moe/test_expert_parallel_qwen3_fsdp_sp.py.Experiment results