t29mato Claude Opus 4.6 commited on
Commit
dac41e5
·
1 Parent(s): 875a4a2

Register MultiScaleDeformableAttention in mmcv ATTENTION registry

Browse files

The stub class needs to be registered with @ATTENTION .register_module()
so that BaseTransformerLayer can find it when building the model.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. setup_mmcv_shim.py +29 -2
setup_mmcv_shim.py CHANGED
@@ -164,8 +164,35 @@ class ConcatCell:
164
  def __init__(self, *args, **kwargs): raise NotImplementedError
165
  ''')
166
 
167
- # Create multi_scale_deform_attn stub
168
  with open(os.path.join(ops_dir, 'multi_scale_deform_attn.py'), 'w') as f:
169
- f.write('class MultiScaleDeformableAttention: pass\n')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
 
171
  print('mmcv.ops shim created successfully')
 
164
  def __init__(self, *args, **kwargs): raise NotImplementedError
165
  ''')
166
 
167
+ # Create multi_scale_deform_attn stub with registry registration
168
  with open(os.path.join(ops_dir, 'multi_scale_deform_attn.py'), 'w') as f:
169
+ f.write('''import warnings
170
+ import torch
171
+ import torch.nn as nn
172
+ from mmcv.cnn.bricks.registry import ATTENTION
173
+ from mmcv.runner import BaseModule
174
+
175
+ @ATTENTION.register_module()
176
+ class MultiScaleDeformableAttention(BaseModule):
177
+ def __init__(self, embed_dims=256, num_heads=8, num_levels=4, num_points=4,
178
+ im2col_step=64, dropout=0.1, batch_first=False, norm_cfg=None,
179
+ init_cfg=None, **kwargs):
180
+ super().__init__(init_cfg)
181
+ self.embed_dims = embed_dims
182
+ self.num_heads = num_heads
183
+ self.num_levels = num_levels
184
+ self.num_points = num_points
185
+ self.batch_first = batch_first
186
+ self.sampling_offsets = nn.Linear(embed_dims, num_heads * num_levels * num_points * 2)
187
+ self.attention_weights = nn.Linear(embed_dims, num_heads * num_levels * num_points)
188
+ self.value_proj = nn.Linear(embed_dims, embed_dims)
189
+ self.output_proj = nn.Linear(embed_dims, embed_dims)
190
+ self.dropout = nn.Dropout(dropout)
191
+
192
+ def forward(self, query, key=None, value=None, identity=None,
193
+ query_pos=None, key_padding_mask=None, reference_points=None,
194
+ spatial_shapes=None, level_start_index=None, **kwargs):
195
+ raise NotImplementedError("MultiScaleDeformableAttention CPU shim - forward not implemented")
196
+ ''')
197
 
198
  print('mmcv.ops shim created successfully')