multimodalart HF Staff commited on
Commit
01ef7f9
·
verified ·
1 Parent(s): 218daec

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. uniar/modeling_uniar.py +10 -0
uniar/modeling_uniar.py CHANGED
@@ -143,6 +143,16 @@ class UniARForConditionalGeneration(Qwen3VLForConditionalGeneration):
143
  if attention_mask is None:
144
  attention_mask = torch.ones_like(hidden_states[..., 0]).long()
145
 
 
 
 
 
 
 
 
 
 
 
146
  language_model = self.model.language_model
147
  position_embeddings = language_model.rotary_emb(hidden_states, position_ids)
148
 
 
143
  if attention_mask is None:
144
  attention_mask = torch.ones_like(hidden_states[..., 0]).long()
145
 
146
+ # Convert 2D [batch, seq] attention mask to 4D [batch, 1, seq, seq]
147
+ # expected by SDPA attention in transformers 4.57.0.
148
+ if attention_mask.dim() == 2:
149
+ batch, seq = attention_mask.shape
150
+ causal = torch.tril(
151
+ torch.ones(seq, seq, device=attention_mask.device, dtype=attention_mask.dtype)
152
+ )
153
+ attn_4d = attention_mask[:, None, None, :] * causal[None, None, :, :]
154
+ attention_mask = attn_4d
155
+
156
  language_model = self.model.language_model
157
  position_embeddings = language_model.rotary_emb(hidden_states, position_ids)
158