yujiepan commited on
Commit
ac64f5c
1 Parent(s): 34ce28c

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +66 -0
README.md ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ pipeline_tag: text-generation
4
+ inference: true
5
+ widget:
6
+ - text: Hello!
7
+ example_title: Hello world
8
+ group: Python
9
+ ---
10
+
11
+ This model is randomly initialized, using the config from [deepseek-ai/DeepSeek-V2-Chat](https://huggingface.co/deepseek-ai/DeepSeek-V2-Chat) but with smaller size.
12
+ **Note the model is in bfloat16**.
13
+
14
+ Codes:
15
+ ```python
16
+ import transformers
17
+ import torch
18
+ import os
19
+ from huggingface_hub import create_repo, upload_folder
20
+ import accelerate
21
+
22
+ source_model_id = 'deepseek-ai/DeepSeek-V2-Chat'
23
+ save_path = '/tmp/yujiepan/deepseek-v2-tiny-random'
24
+ repo_id = 'yujiepan/deepseek-v2-tiny-random'
25
+
26
+ os.system(f'rm -rf {save_path}')
27
+
28
+ config = transformers.AutoConfig.from_pretrained(
29
+ source_model_id,
30
+ trust_remote_code=True,
31
+ )
32
+ config._name_or_path = source_model_id
33
+ config.hidden_size = 8
34
+ config.intermediate_size = 16
35
+ config.moe_intermediate_size = 4
36
+ config.num_attention_heads = 2
37
+ config.num_key_value_heads = 2
38
+ config.num_hidden_layers = 2
39
+ config.kv_lora_rank = 2
40
+ config.q_lora_rank = 2
41
+ config.v_head_dim = 2
42
+ config.qk_nope_head_dim = 2
43
+ config.qk_rope_head_dim = 2
44
+ config.torch_dtype = "bfloat16"
45
+
46
+ model = transformers.AutoModelForCausalLM.from_config(
47
+ config,
48
+ trust_remote_code=True,
49
+ )
50
+ model.generation_config = transformers.GenerationConfig.from_pretrained(source_model_id)
51
+ model = model.to(torch.bfloat16)
52
+ model.save_pretrained(save_path)
53
+
54
+ tokenizer = transformers.AutoTokenizer.from_pretrained(
55
+ source_model_id,
56
+ trust_remote_code=True,
57
+ )
58
+ tokenizer.save_pretrained(save_path)
59
+
60
+ print(model.float().generate(torch.tensor([[1, 2, 3]]).long(), max_length=16))
61
+
62
+ os.system(f'ls -alh {save_path}')
63
+ # os.system(f'rm -rf {save_path}/model.safetensors')
64
+ create_repo(repo_id, exist_ok=True)
65
+ upload_folder(repo_id=repo_id, folder_path=save_path)
66
+ ```