Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
library_name: transformers
|
3 |
+
pipeline_tag: text-generation
|
4 |
+
inference: true
|
5 |
+
widget:
|
6 |
+
- text: Hello!
|
7 |
+
example_title: Hello world
|
8 |
+
group: Python
|
9 |
+
---
|
10 |
+
|
11 |
+
This model is randomly initialized, using the config from [Qwen/Qwen2-72B-Instruct](https://huggingface.co/Qwen/Qwen2-72B-Instruct) but with smaller size.
|
12 |
+
|
13 |
+
Codes:
|
14 |
+
```python
|
15 |
+
import transformers
|
16 |
+
import torch
|
17 |
+
import os
|
18 |
+
from huggingface_hub import create_repo, upload_folder
|
19 |
+
import accelerate
|
20 |
+
|
21 |
+
source_model_id = 'Qwen/Qwen2-72B-Instruct'
|
22 |
+
save_path = '/tmp/yujiepan/qwen2-tiny-random'
|
23 |
+
repo_id = 'yujiepan/qwen2-tiny-random'
|
24 |
+
|
25 |
+
os.system(f'rm -rf {save_path}')
|
26 |
+
|
27 |
+
config = transformers.AutoConfig.from_pretrained(
|
28 |
+
source_model_id,
|
29 |
+
trust_remote_code=True,
|
30 |
+
)
|
31 |
+
config._name_or_path = source_model_id
|
32 |
+
config.hidden_size = 8
|
33 |
+
config.intermediate_size = 16
|
34 |
+
config.num_key_value_heads = 2
|
35 |
+
config.num_attention_heads = 4
|
36 |
+
config.num_hidden_layers = 2
|
37 |
+
config.max_window_layers = 1
|
38 |
+
|
39 |
+
model = transformers.AutoModelForCausalLM.from_config(
|
40 |
+
config,
|
41 |
+
trust_remote_code=True,
|
42 |
+
)
|
43 |
+
model.generation_config = transformers.GenerationConfig.from_pretrained(source_model_id)
|
44 |
+
model = model.to(torch.bfloat16)
|
45 |
+
|
46 |
+
with torch.no_grad():
|
47 |
+
for p in model.parameters():
|
48 |
+
torch.nn.init.normal_(p)
|
49 |
+
|
50 |
+
model.save_pretrained(save_path)
|
51 |
+
|
52 |
+
tokenizer = transformers.AutoTokenizer.from_pretrained(
|
53 |
+
source_model_id,
|
54 |
+
trust_remote_code=True,
|
55 |
+
)
|
56 |
+
tokenizer.save_pretrained(save_path)
|
57 |
+
|
58 |
+
output = model.float().generate(torch.tensor([[1, 2, 3]]).long(), max_length=16, do_sample=True)
|
59 |
+
|
60 |
+
os.system(f'ls -alh {save_path}')
|
61 |
+
# os.system(f'rm -rf {save_path}/model.safetensors')
|
62 |
+
create_repo(repo_id, exist_ok=True)
|
63 |
+
upload_folder(repo_id=repo_id, folder_path=save_path)
|
64 |
+
|
65 |
+
```
|