yujiepan commited on
Commit
34bf872
1 Parent(s): 2de543f

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +52 -0
README.md ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 [microsoft/Phi-3-mini-128k-instruct](https://huggingface.co/microsoft/Phi-3-mini-128k-instruct) 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 = 'microsoft/Phi-3-mini-128k-instruct'
22
+ save_path = '/tmp/yujiepan/phi-3-tiny-random'
23
+ repo_id = 'yujiepan/phi-3-tiny-random'
24
+
25
+ config = transformers.AutoConfig.from_pretrained(
26
+ source_model_id, trust_remote_code=True)
27
+ config.hidden_size = 16
28
+ config.intermediate_size = 32
29
+ config.num_attention_heads = 4
30
+ config.num_hidden_layers = 2
31
+ config.num_key_value_heads = 4
32
+ config.rope_scaling['long_factor'] = [1.0299, 1.0499]
33
+ config.rope_scaling['short_factor'] = [1.05, 1.05]
34
+
35
+ model = transformers.AutoModelForCausalLM.from_config(
36
+ config, trust_remote_code=True)
37
+ model = model.to(torch.float16)
38
+ model.save_pretrained(save_path)
39
+
40
+ tokenizer = transformers.AutoTokenizer.from_pretrained(
41
+ source_model_id, trust_remote_code=True)
42
+ tokenizer.save_pretrained(save_path)
43
+
44
+ result = transformers.pipelines.pipeline(
45
+ 'text-generation',
46
+ model=model.float(), tokenizer=tokenizer)('Hello')
47
+ print(result)
48
+
49
+ os.system(f'ls -alh {save_path}')
50
+ create_repo(repo_id, exist_ok=True)
51
+ upload_folder(repo_id=repo_id, folder_path=save_path)
52
+ ```