Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mcore_bridge/model/gpts/qwen3_next.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def forward(self, hidden_states: torch.Tensor, **kwargs):
hidden_states = new_hidden_states
else:
hidden_states = hidden_states.transpose(0, 1)
attention_mask = resolve_hf_attention_mask(kwargs)
attention_mask = resolve_gdn_attention_mask(kwargs)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The function resolve_gdn_attention_mask (called here and defined at line 62) has a potential logic error and runtime risk:

  1. Type Safety: At line 70, it uses the bitwise NOT operator ~ on attention_mask. If the mask is an integer tensor (common for HuggingFace masks), ~1 results in -2, which will cause the sum(...) > 0 check to behave unexpectedly. It should be explicitly cast to boolean: (~attention_mask.to(torch.bool)).
  2. Dimensionality: The function assumes a 4D input by using dim=(1, 2). If kwargs.get('attention_mask') returns a 2D tensor (standard HuggingFace format), this will raise an IndexError.

Since this function is now being used to resolve the attention mask, these issues should be addressed in its implementation to ensure robustness.

res = super().forward(hidden_states=hidden_states, attention_mask=attention_mask)
if thd_format:
res = res[attention_mask][:, None]
Expand Down
Loading