load adapter
Browse files- yuan-adaptors.pth → 3_Adaptor/adaptor.pth +0 -0
- 3_Adaptor/config.json +4 -0
- modeling_adaptor.py +15 -1
- modules.json +6 -0
yuan-adaptors.pth → 3_Adaptor/adaptor.pth
RENAMED
File without changes
|
3_Adaptor/config.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"num_adaptors": 5,
|
3 |
+
"hidden_dim": 1792
|
4 |
+
}
|
modeling_adaptor.py
CHANGED
@@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
1 |
import torch
|
2 |
import torch.nn as nn
|
3 |
import torch.nn.functional as F
|
@@ -85,5 +88,16 @@ class MixtureOfAdaptors(nn.Module):
|
|
85 |
reduce='sum'
|
86 |
)
|
87 |
return adaptor_cache
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
|
4 |
import torch
|
5 |
import torch.nn as nn
|
6 |
import torch.nn.functional as F
|
|
|
88 |
reduce='sum'
|
89 |
)
|
90 |
return adaptor_cache
|
91 |
+
|
92 |
+
@staticmethod
|
93 |
+
def load(input_path):
|
94 |
+
with open(os.path.join(input_path, "config.json")) as fIn:
|
95 |
+
config = json.load(fIn)
|
96 |
|
97 |
+
adaptor = MixtureOfAdaptors(**config)
|
98 |
+
adaptor.load_state_dict(
|
99 |
+
torch.load(
|
100 |
+
os.path.join(input_path, "adaptor.pth"), weights_only=True
|
101 |
+
)
|
102 |
+
)
|
103 |
+
return adaptor
|
modules.json
CHANGED
@@ -16,5 +16,11 @@
|
|
16 |
"name": "2",
|
17 |
"path": "2_Dense",
|
18 |
"type": "sentence_transformers.models.Dense"
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
}
|
20 |
]
|
|
|
16 |
"name": "2",
|
17 |
"path": "2_Dense",
|
18 |
"type": "sentence_transformers.models.Dense"
|
19 |
+
},
|
20 |
+
{
|
21 |
+
"idx": 3,
|
22 |
+
"name": "3",
|
23 |
+
"path": "3_Adaptor",
|
24 |
+
"type": "modeling_adaptor.MixtureOfAdaptors"
|
25 |
}
|
26 |
]
|