Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-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/Mistral-7B-v0.1'
|
24 |
+
save_path = '/tmp/yujiepan/mistral-tiny-random'
|
25 |
+
repo_id = 'yujiepan/mistral-tiny-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_hidden_layers = 2
|
32 |
+
config.num_key_value_heads = 2
|
33 |
+
print(config)
|
34 |
+
|
35 |
+
tokenizer = transformers.AutoTokenizer.from_pretrained(model_id)
|
36 |
+
tokenizer.save_pretrained(save_path)
|
37 |
+
|
38 |
+
model = transformers.AutoModelForCausalLM.from_config(config, torch_dtype=torch.float16)
|
39 |
+
model = model.half()
|
40 |
+
|
41 |
+
pipe = pipeline('text-generation', model=model, tokenizer=tokenizer, do_sample=False, device='cuda')
|
42 |
+
print(pipe('Hello World!'))
|
43 |
+
|
44 |
+
model.save_pretrained(save_path)
|
45 |
+
|
46 |
+
ovmodel = OVModelForCausalLM.from_pretrained(save_path, export=True)
|
47 |
+
ovmodel = ovmodel.half()
|
48 |
+
ovmodel.save_pretrained(save_path)
|
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 |
+
```
|
54 |
+
|
55 |
+
|