Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
---
|
3 |
+
pipeline_tag: text-generation
|
4 |
+
inference: true
|
5 |
+
widget:
|
6 |
+
- text: 'Hello!'
|
7 |
+
example_title: Hello world
|
8 |
+
group: Python
|
9 |
+
library_name: transformers
|
10 |
+
---
|
11 |
+
|
12 |
+
This model is randomly initialized, using the config from [mistralai/Mixtral-8x7B-v0.1](https://huggingface.co/mistralai/Mixtral-8x7B-v0.1) but with smaller size.
|
13 |
+
|
14 |
+
Codes:
|
15 |
+
```python
|
16 |
+
from optimum.intel.openvino import OVModelForCausalLM
|
17 |
+
from transformers import pipeline
|
18 |
+
from huggingface_hub import create_repo, upload_folder
|
19 |
+
import torch
|
20 |
+
import transformers
|
21 |
+
import os
|
22 |
+
|
23 |
+
model_id = 'mistralai/Mixtral-8x7B-v0.1'
|
24 |
+
save_path = '/tmp/yujiepan/mixtral-8xtiny-random'
|
25 |
+
repo_id = 'yujiepan/mixtral-8xtiny-random'
|
26 |
+
|
27 |
+
config = transformers.AutoConfig.from_pretrained(model_id)
|
28 |
+
config.hidden_size = 8
|
29 |
+
config.intermediate_size = 32
|
30 |
+
config.num_attention_heads = 4
|
31 |
+
config.num_experts_per_tok = 2
|
32 |
+
config.num_hidden_layers = 2
|
33 |
+
config.num_key_value_heads = 2
|
34 |
+
config.num_local_experts = 8
|
35 |
+
print(config)
|
36 |
+
|
37 |
+
tokenizer = transformers.AutoTokenizer.from_pretrained(model_id)
|
38 |
+
tokenizer.save_pretrained(save_path)
|
39 |
+
|
40 |
+
model = transformers.AutoModelForCausalLM.from_config(config, torch_dtype=torch.float16)
|
41 |
+
model = model.half()
|
42 |
+
|
43 |
+
pipe = pipeline('text-generation', model=model, tokenizer=tokenizer, do_sample=False, device='cuda')
|
44 |
+
print(pipe('Hello World!'))
|
45 |
+
|
46 |
+
model.save_pretrained(save_path)
|
47 |
+
|
48 |
+
# ovmodel = OVModelForCausalLM.from_pretrained(save_path, export=True)
|
49 |
+
# ovmodel = ovmodel.half()
|
50 |
+
# ovmodel.save_pretrained(save_path)
|
51 |
+
|
52 |
+
os.system(f'ls -alh /tmp/yujiepan/mixtral-8xtiny-random')
|
53 |
+
create_repo(repo_id, exist_ok=True)
|
54 |
+
upload_folder(repo_id=repo_id, folder_path=save_path)
|
55 |
+
```
|
56 |
+
|
57 |
+
|