yujiepan commited on
Commit
97a2faf
1 Parent(s): 7829fe8

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +39 -1
README.md CHANGED
@@ -13,5 +13,43 @@ Note the model is in float16.
13
 
14
  Codes:
15
  ```python
16
- model.config
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  ```
 
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 = 'stabilityai/stablelm-2-1_6b'
22
+ save_path = '/tmp/yujiepan/stablelm-2-tiny-random'
23
+ repo_id = 'yujiepan/stablelm-2-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 = 6
29
+ config.num_attention_heads = 4
30
+ config.num_hidden_layers = 2
31
+ config.num_key_value_heads = 2
32
+ config.torch_dtype = torch.float16
33
+
34
+ model = transformers.AutoModelForCausalLM.from_config(
35
+ config, trust_remote_code=True, torch_dtype=torch.float16)
36
+ model = model.half()
37
+
38
+ tokenizer = transformers.AutoTokenizer.from_pretrained(
39
+ source_model_id, trust_remote_code=True)
40
+
41
+ result = transformers.pipelines.pipeline(
42
+ 'text-generation',
43
+ model=model, tokenizer=tokenizer,
44
+ device=0,
45
+ max_new_tokens=16,
46
+ )('Hello World!')
47
+ print(result)
48
+
49
+ model.save_pretrained(save_path)
50
+ tokenizer.save_pretrained(save_path)
51
+
52
+ os.system(f'ls -alh {save_path}')
53
+ create_repo(repo_id, exist_ok=True)
54
+ upload_folder(repo_id=repo_id, folder_path=save_path)
55
  ```