[BugFix] Unwrap AttentionMask wrapper for transformers 5.9 in sequence parallel#206
Merged
Conversation
- Add kernelize_model integration to ep_fsdp2_lora and fsdp2 examples - Support model parameter in apply_npu_patch for FLA instance patching - Implement NPU-accelerated packed MoE experts with weight caching - Add Qwen3.5 SparseMoeBlock forward with dual Transformers version support - Support partial RoPE and gated RMSNorm with FP32 mode option - Add MindSpeed Triton FLA backend integration for Qwen3.5 - Add environment variable controls for patch toggles - Add dynamic model discovery for unknown model families
- Skip weight cache when requires_grad=True to preserve autograd graph - Resolve underlying PyTorch model from TransformersModel wrapper in FLA patch
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the sdpa_mask function to support padding_mask when it is provided as an AttentionMask wrapper instead of a raw PyTorch Tensor. The feedback suggests using torch.is_tensor instead of isinstance to maintain style consistency with the rest of the codebase.
tastelikefeet
approved these changes
May 28, 2026
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
Description
In
transformers = 5.9,masking_utils.sdpa_maskreceivespadding_maskas anAttentionMaskdataclass instead of a rawtorch.Tensor. The downstream_ignore_causal_mask_sdpacalls.all()on it, which raisesAttributeErrorand breaks sequence-parallel training.Changes
twinkle/model/transformers/strategy/sequence_parallel/__init__.pysdpa_maskto unwrapAttentionMaskvia.to_tensor()or.maskbefore forwarding toorigin_sdpa.Experiment results
Verified on 2 × A3 NPU with Qwen3.5-27B,
dp=2, fsdp=2, sp=2