matejpekar commited on
Commit
ece033b
·
verified ·
1 Parent(s): a3c236a

Upload model

Browse files
Files changed (2) hide show
  1. config.json +4 -0
  2. modeling.py +21 -1
config.json CHANGED
@@ -2,6 +2,10 @@
2
  "architectures": [
3
  "LSPDetrModel"
4
  ],
 
 
 
 
5
  "backbone": "microsoft/swinv2-tiny-patch4-window16-256",
6
  "backbone_config": null,
7
  "backbone_kwargs": {
 
2
  "architectures": [
3
  "LSPDetrModel"
4
  ],
5
+ "auto_map": {
6
+ "AutoConfig": "configuration.LSPDetrConfig",
7
+ "AutoModelForObjectDetection": "modeling.LSPDetrModel"
8
+ },
9
  "backbone": "microsoft/swinv2-tiny-patch4-window16-256",
10
  "backbone_config": null,
11
  "backbone_kwargs": {
modeling.py CHANGED
@@ -1,5 +1,6 @@
1
  import math
2
  from functools import lru_cache
 
3
 
4
  import torch
5
  import torch.nn.functional as F
@@ -11,13 +12,28 @@ from torch.nn.attention.flex_attention import (
11
  create_block_mask,
12
  flex_attention,
13
  )
14
- from torch.nn.utils.parametrizations import orthogonal
15
  from transformers.modeling_utils import PreTrainedModel
16
  from transformers.utils.backbone_utils import load_backbone
17
 
18
  from .configuration import LSPDetrConfig, STAConfig
19
 
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  flex_attention = torch.compile(flex_attention, dynamic=True)
22
 
23
 
@@ -514,3 +530,7 @@ class LSPDetrModel(PreTrainedModel):
514
  )
515
 
516
  return self.decode_head(tgt, ref_points, features, h, w)
 
 
 
 
 
1
  import math
2
  from functools import lru_cache
3
+ from unittest.mock import patch
4
 
5
  import torch
6
  import torch.nn.functional as F
 
12
  create_block_mask,
13
  flex_attention,
14
  )
15
+ from torch.nn.utils.parametrizations import _Orthogonal, orthogonal
16
  from transformers.modeling_utils import PreTrainedModel
17
  from transformers.utils.backbone_utils import load_backbone
18
 
19
  from .configuration import LSPDetrConfig, STAConfig
20
 
21
 
22
+ def _meta_safe_right_inverse(self, x: torch.Tensor) -> torch.Tensor:
23
+ if x.device.type == "meta":
24
+ # Skip validation; assume OK (unsafe but necessary for meta init)
25
+ return x
26
+
27
+ return _right_inverse(self, x)
28
+
29
+
30
+ _right_inverse = _Orthogonal.right_inverse
31
+ patch(
32
+ "torch.nn.utils.parametrizations._Orthogonal.right_inverse",
33
+ _meta_safe_right_inverse,
34
+ ).start()
35
+
36
+
37
  flex_attention = torch.compile(flex_attention, dynamic=True)
38
 
39
 
 
530
  )
531
 
532
  return self.decode_head(tgt, ref_points, features, h, w)
533
+
534
+
535
+ P = orthogonal(nn.Linear(10, 10, bias=False, device="cpu"), orthogonal_map="cayley")
536
+ P = orthogonal(nn.Linear(10, 10, bias=False, device="cpu"), orthogonal_map="cayley")