Remap dense layer parameter naming
Browse files- 2_Dense/pytorch_model.bin +2 -2
- convert.py +25 -0
2_Dense/pytorch_model.bin
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:97720d328d1a1a4168acac9f3d3c19c1809def87e67f2438fc06cd0235d7a5b0
|
| 3 |
+
size 9438013
|
convert.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
|
| 3 |
+
import sys
|
| 4 |
+
from collections import OrderedDict
|
| 5 |
+
|
| 6 |
+
import torch
|
| 7 |
+
|
| 8 |
+
# Load and keep backup
|
| 9 |
+
m_input = torch.load("2_Dense/pytorch_model.bin")
|
| 10 |
+
torch.save(m_input, "2_Dense/pytorch_model.bin.bak")
|
| 11 |
+
|
| 12 |
+
# Mappings
|
| 13 |
+
rename = {"layer.weight": "linear.weight"}
|
| 14 |
+
|
| 15 |
+
# Output
|
| 16 |
+
m_output = OrderedDict()
|
| 17 |
+
for key, params in m_input.items():
|
| 18 |
+
dst = key
|
| 19 |
+
if key in rename:
|
| 20 |
+
print(f"Mapping {key} to {rename[key]}", file=sys.stderr)
|
| 21 |
+
dst = rename[key]
|
| 22 |
+
|
| 23 |
+
m_output[dst] = params
|
| 24 |
+
|
| 25 |
+
torch.save(m_output, "2_Dense/pytorch_model.bin")
|