lixinhao commited on
Commit
64feabb
·
verified ·
1 Parent(s): 2cc4ab3

Update vision_tower_builder.py

Browse files
Files changed (1) hide show
  1. vision_tower_builder.py +17 -4
vision_tower_builder.py CHANGED
@@ -24,9 +24,15 @@ import torch.utils.checkpoint as checkpoint
24
  from functools import partial
25
  try:
26
  from flash_attn import flash_attn_qkvpacked_func
 
27
  except:
28
- print("You need to install flash_attn")
29
- from timm.layers import drop_path, to_2tuple, trunc_normal_
 
 
 
 
 
30
 
31
 
32
 
@@ -67,6 +73,14 @@ class Attention(nn.Module):
67
  self, dim, num_heads=8, qkv_bias=False, qk_scale=None, attn_drop=0.,
68
  proj_drop=0., attn_head_dim=None,
69
  attn_type='flash_v2'):
 
 
 
 
 
 
 
 
70
  super().__init__()
71
  self.num_heads = num_heads
72
  head_dim = dim // num_heads
@@ -613,7 +627,6 @@ def build_vision_tower(vision_tower_cfg, **kwargs):
613
  if "umt-hd" in vision_tower:
614
  return UMTVisionTower(vision_tower, vision_tower_cfg=vision_tower_cfg, image_size=448, **kwargs)
615
  elif "umt" in vision_tower:
616
- raise NotImplementedError
617
  return UMTVisionTower(vision_tower, vision_tower_cfg=vision_tower_cfg, **kwargs)
618
 
619
- raise ValueError(f"Unknown vision tower: {vision_tower}")
 
24
  from functools import partial
25
  try:
26
  from flash_attn import flash_attn_qkvpacked_func
27
+ use_flash_attn = True
28
  except:
29
+ use_flash_attn = False
30
+ print("You need to install flash_attn to be faster!")
31
+
32
+ try:
33
+ from timm.layers import drop_path, to_2tuple, trunc_normal_
34
+ except:
35
+ from timm.models.layers import drop_path, trunc_normal_, to_2tuple
36
 
37
 
38
 
 
73
  self, dim, num_heads=8, qkv_bias=False, qk_scale=None, attn_drop=0.,
74
  proj_drop=0., attn_head_dim=None,
75
  attn_type='flash_v2'):
76
+
77
+ if use_flash_attn:
78
+ attn_type = attn_type
79
+ else:
80
+ attn_type = 'origin'
81
+
82
+ print(attn_type)
83
+
84
  super().__init__()
85
  self.num_heads = num_heads
86
  head_dim = dim // num_heads
 
627
  if "umt-hd" in vision_tower:
628
  return UMTVisionTower(vision_tower, vision_tower_cfg=vision_tower_cfg, image_size=448, **kwargs)
629
  elif "umt" in vision_tower:
 
630
  return UMTVisionTower(vision_tower, vision_tower_cfg=vision_tower_cfg, **kwargs)
631
 
632
+ raise ValueError(f"Unknown vision tower: {vision_tower}")