Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 [google/gemma-2-27b-it](https://huggingface.co/google/gemma-2-27b-it) but with smaller size.
|
12 |
+
|
13 |
+
Codes:
|
14 |
+
```python
|
15 |
+
from transformers import pipeline
|
16 |
+
from huggingface_hub import create_repo, upload_folder
|
17 |
+
import torch
|
18 |
+
import transformers
|
19 |
+
import os
|
20 |
+
|
21 |
+
model_id = 'google/gemma-2-27b-it'
|
22 |
+
save_path = '/tmp/yujiepan/gemma-2-tiny-random'
|
23 |
+
repo_id = 'yujiepan/gemma-2-tiny-random'
|
24 |
+
|
25 |
+
config = transformers.AutoConfig.from_pretrained(model_id)
|
26 |
+
config.hidden_size = 8
|
27 |
+
config.head_dim = 2
|
28 |
+
config.intermediate_size = 16
|
29 |
+
config.num_attention_heads = 4
|
30 |
+
config.num_hidden_layers = 2
|
31 |
+
config.num_key_value_heads = 2
|
32 |
+
|
33 |
+
tokenizer = transformers.AutoTokenizer.from_pretrained(model_id)
|
34 |
+
tokenizer.save_pretrained(save_path)
|
35 |
+
|
36 |
+
model = transformers.AutoModelForCausalLM.from_config(config, torch_dtype=torch.bfloat16)
|
37 |
+
model.generation_config = transformers.GenerationConfig.from_pretrained(model_id)
|
38 |
+
with torch.no_grad():
|
39 |
+
for p in model.parameters():
|
40 |
+
torch.nn.init.uniform_(p, -0.1, 0.1)
|
41 |
+
|
42 |
+
pipe = pipeline('text-generation', model=model, tokenizer=tokenizer, do_sample=False, device='cuda')
|
43 |
+
print(pipe('Hello World!'))
|
44 |
+
|
45 |
+
model.save_pretrained(save_path)
|
46 |
+
|
47 |
+
os.system(f'ls -alh {save_path}')
|
48 |
+
create_repo(repo_id, exist_ok=True)
|
49 |
+
upload_folder(repo_id=repo_id, folder_path=save_path)
|
50 |
+
```
|