Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
pipeline_tag: text-generation
|
3 |
+
inference: true
|
4 |
+
widget:
|
5 |
+
- text: 'Hello!'
|
6 |
+
example_title: Hello world
|
7 |
+
group: Python
|
8 |
+
library_name: transformers
|
9 |
+
---
|
10 |
+
|
11 |
+
This model is randomly initialized, using the config from [keyfan/grok-1-hf](https://huggingface.co/keyfan/grok-1-hf) but with smaller size.
|
12 |
+
Note the model is in float16.
|
13 |
+
|
14 |
+
Codes:
|
15 |
+
```python
|
16 |
+
import transformers
|
17 |
+
import torch
|
18 |
+
import os
|
19 |
+
from huggingface_hub import create_repo, upload_folder
|
20 |
+
|
21 |
+
source_model_id = 'keyfan/grok-1-hf'
|
22 |
+
save_path = '/tmp/yujiepan/grok-1-tiny-random'
|
23 |
+
repo_id = 'yujiepan/grok-1-tiny-random'
|
24 |
+
|
25 |
+
config = transformers.AutoConfig.from_pretrained(
|
26 |
+
source_model_id, trust_remote_code=True)
|
27 |
+
config.hidden_size = 4
|
28 |
+
config.intermediate_size = 8
|
29 |
+
config.num_attention_heads = 4
|
30 |
+
config.num_experts_per_tok = 2
|
31 |
+
config.num_hidden_layers = 2
|
32 |
+
config.num_key_value_heads = 2
|
33 |
+
config.num_local_experts = 8
|
34 |
+
config.torch_dtype = torch.float16
|
35 |
+
|
36 |
+
model = transformers.AutoModelForCausalLM.from_config(
|
37 |
+
config, trust_remote_code=True)
|
38 |
+
model = model.half()
|
39 |
+
model.save_pretrained(save_path)
|
40 |
+
|
41 |
+
tokenizer = transformers.AutoTokenizer.from_pretrained(
|
42 |
+
source_model_id, trust_remote_code=True)
|
43 |
+
tokenizer.save_pretrained(save_path)
|
44 |
+
|
45 |
+
result = transformers.pipelines.pipeline(
|
46 |
+
'text-generation',
|
47 |
+
model=model.float(), tokenizer=tokenizer)('Hello')
|
48 |
+
print(result)
|
49 |
+
|
50 |
+
os.system(f'ls -alh {save_path}')
|
51 |
+
create_repo(repo_id, exist_ok=True)
|
52 |
+
upload_folder(repo_id=repo_id, folder_path=save_path)
|
53 |
+
```
|