yujiepan commited on
Commit
e8c0ac7
1 Parent(s): 400f0ee

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +56 -0
README.md ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 [Qwen/Qwen1.5-72B-Chat](https://huggingface.co/Qwen/Qwen1.5-72B-Chat/blob/main/config.json) 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 = 'Qwen/Qwen1.5-72B-Chat'
22
+ tiny_random_name = 'qwen1.5-tiny-random'
23
+ save_path = f'/tmp/yujiepan/{tiny_random_name}'
24
+ repo_id = f'yujiepan/{tiny_random_name}'
25
+
26
+ config = transformers.AutoConfig.from_pretrained(
27
+ source_model_id, trust_remote_code=True)
28
+ config.hidden_size = 4
29
+ config.intermediate_size = 6
30
+ config.num_attention_heads = 4
31
+ config.num_hidden_layers = 2
32
+ config.num_key_value_heads = 2
33
+ config.torch_dtype = torch.float16
34
+
35
+ model = transformers.AutoModelForCausalLM.from_config(
36
+ config, trust_remote_code=True, torch_dtype=torch.float16)
37
+ model = model.half()
38
+
39
+ tokenizer = transformers.AutoTokenizer.from_pretrained(
40
+ source_model_id, trust_remote_code=True)
41
+
42
+ result = transformers.pipelines.pipeline(
43
+ 'text-generation',
44
+ model=model, tokenizer=tokenizer,
45
+ device=0,
46
+ max_new_tokens=16,
47
+ )('Hello World!')
48
+ print(result)
49
+
50
+ model.save_pretrained(save_path)
51
+ tokenizer.save_pretrained(save_path)
52
+
53
+ os.system(f'ls -alh {save_path}')
54
+ create_repo(repo_id, exist_ok=True)
55
+ upload_folder(repo_id=repo_id, folder_path=save_path)
56
+ ```