yujiepan commited on
Commit
71743f3
1 Parent(s): 9d91b8b

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +59 -0
README.md ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 [THUDM/chatglm3-6b-128k](https://huggingface.co/THUDM/chatglm3-6b-128k/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 = 'THUDM/chatglm3-6b-128k'
22
+ tiny_random_name = 'chatglm3-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.ffn_hidden_size = 6
30
+ config.num_attention_heads = 4
31
+ config.kv_channels = 2
32
+ config.num_layers = 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')
48
+ # print(result)
49
+ model = model.cuda()
50
+ response, history = model.chat(tokenizer, "Hi", history=[], max_length=32)
51
+ print(response)
52
+
53
+ model.save_pretrained(save_path)
54
+ tokenizer.save_pretrained(save_path)
55
+
56
+ os.system(f'ls -alh {save_path}')
57
+ create_repo(repo_id, exist_ok=True)
58
+ upload_folder(repo_id=repo_id, folder_path=save_path)
59
+ ```