Update README.md
Browse files
README.md
CHANGED
|
@@ -13,34 +13,15 @@ This is useful for researchers who want to play with training the model (not tun
|
|
| 13 |
Generated via the github repo [Model Architecture Generator](https://github.com/ivanhe123/Model-Architecture-Generator)
|
| 14 |
|
| 15 |
## Use
|
| 16 |
-
First go into the directory of the model
|
|
|
|
|
|
|
| 17 |
```
|
| 18 |
-
from transformers import AutoModel, AutoTokenizer
|
| 19 |
-
import torch
|
| 20 |
-
import os
|
| 21 |
-
import argparse
|
| 22 |
-
|
| 23 |
-
# Use the provided paths for input and output
|
| 24 |
-
model_name = "./gpt2-large-architecture"
|
| 25 |
-
output_dir = "./gpt2-large-reset"
|
| 26 |
-
|
| 27 |
-
model = AutoModel.from_pretrained(model_name)
|
| 28 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 29 |
-
|
| 30 |
-
for name, param in model.named_parameters():
|
| 31 |
-
if param.dim() > 1:
|
| 32 |
-
torch.nn.init.xavier_uniform_(param)
|
| 33 |
-
else:
|
| 34 |
-
torch.nn.init.zeros_(param)
|
| 35 |
-
|
| 36 |
-
if not os.path.exists(output_dir):
|
| 37 |
-
os.makedirs(output_dir)
|
| 38 |
-
|
| 39 |
-
model.save_pretrained(output_dir)
|
| 40 |
-
tokenizer.save_pretrained(output_dir)
|
| 41 |
-
|
| 42 |
-
print(f"Model with randomized parameters saved to: {output_dir}")
|
| 43 |
|
| 44 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
|
|
|
|
| 13 |
Generated via the github repo [Model Architecture Generator](https://github.com/ivanhe123/Model-Architecture-Generator)
|
| 14 |
|
| 15 |
## Use
|
| 16 |
+
First go into the directory of the model,
|
| 17 |
+
```
|
| 18 |
+
git clone https://github.com/ivanhe123/Model-Architecture-Generator
|
| 19 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
```
|
| 22 |
+
python -m randomnize_params -in "./gpt2-large-architecture" -out path_model_out
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
path_model_out is just the output path of the newly randomnized model.
|
| 26 |
|
| 27 |
|