File size: 3,746 Bytes
a8dc9da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
diff --git a/lingbotvla/models/vla/pi0/modeling_lingbot_vla.py b/lingbotvla/models/vla/pi0/modeling_lingbot_vla.py
index 4e40980..7473ada 100644
--- a/lingbotvla/models/vla/pi0/modeling_lingbot_vla.py
+++ b/lingbotvla/models/vla/pi0/modeling_lingbot_vla.py
@@ -1097,13 +1097,21 @@ class QwenvlWithExpertModel(PreTrainedModel):
         if self.config.vocab_size != 0 and self.config.vocab_size != 257152 and vlm_config.vocab_size != self.config.vocab_size:
             vlm_config.vocab_size = self.config.vocab_size
         
-        vlm_config._attn_implementation = 'flash_attention_2'
-        self.qwenvl = Qwen2_5_VLForConditionalGeneration._from_config(vlm_config, use_flash_attention_2=True)
+        # PATCH: flash-attn unusable on Katana (GLIBC 2.28 vs wheel's 2.32). Force sdpa.
+        _attn_impl = getattr(self.config, "_attn_implementation", "sdpa")
+        vlm_config._attn_implementation = _attn_impl
+        self.qwenvl = Qwen2_5_VLForConditionalGeneration._from_config(
+            vlm_config, use_flash_attention_2=(_attn_impl == "flash_attention_2")
+        )
         if self.config.use_lm_head:
             self.qwenvl.tie_weights()
         self.config.qwen_expert_config.norm_qkv = self.config.norm_qkv
-        self.config.qwen_expert_config._attn_implementation = 'flash_attention_2'
-        self.qwen_expert = Qwen2ForCausalLM._from_config(self.config.qwen_expert_config, use_flash_attention_2=True, eval=eval)
+        self.config.qwen_expert_config._attn_implementation = _attn_impl
+        self.qwen_expert = Qwen2ForCausalLM._from_config(
+            self.config.qwen_expert_config,
+            use_flash_attention_2=(_attn_impl == "flash_attention_2"),
+            eval=eval,
+        )
 
         self.rotary_pos_emb = None
         self.window_index = None
diff --git a/lingbotvla/models/vla/pi0/qwenvl_in_vla.py b/lingbotvla/models/vla/pi0/qwenvl_in_vla.py
index 661aa21..24cf92f 100644
--- a/lingbotvla/models/vla/pi0/qwenvl_in_vla.py
+++ b/lingbotvla/models/vla/pi0/qwenvl_in_vla.py
@@ -28,6 +28,15 @@ from transformers.modeling_attn_mask_utils import AttentionMaskConverter
 from transformers.modeling_flash_attention_utils import FlashAttentionKwargs, flash_attn_supports_top_left_mask, is_flash_attn_available
 from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS, dynamic_rope_update
 from transformers.processing_utils import Unpack
+
+
+# PATCH: rotate_half is used by apply_rotary_pos_emb_vision below but never imported.
+# Copying from modeling_lingbot_vla.py:80 (identical body).
+def rotate_half(x):
+    """Rotates half the hidden dims of the input."""
+    x1 = x[..., : x.shape[-1] // 2]
+    x2 = x[..., x.shape[-1] // 2 :]
+    return torch.cat((-x2, x1), dim=-1)
 import torch.distributed._tensor as dt
 
 if is_flash_attn_available():
@@ -1322,7 +1331,13 @@ class Qwen2_5_VLForConditionalGeneration(Qwen2_5_VLPreTrainedModel, GenerationMi
 
     def __init__(self, config, **kwargs):
         super().__init__(config)
-        self.visual = Qwen2_5_VisionTransformerPretrainedModel._from_config(config.vision_config, use_flash_attention_2=True)
+        # PATCH: hardcoded flash-attn unusable on Rocky 8 (GLIBC 2.28 vs wheel's 2.32 requirement).
+        # Honor config._attn_implementation so users can pick sdpa/eager.
+        _vision_attn = getattr(config, "_attn_implementation", "sdpa")
+        self.visual = Qwen2_5_VisionTransformerPretrainedModel._from_config(
+            config.vision_config,
+            use_flash_attention_2=(_vision_attn == "flash_attention_2"),
+        )
         self.model = Qwen2_5_VLModel(config)
         self.vocab_size = config.vocab_size
         self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)