yujiepan commited on
Commit
443c532
1 Parent(s): 698c3e5

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +55 -0
README.md ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 [meta-llama/Meta-Llama-3-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct) 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
+
21
+ source_model_id = 'meta-llama/Meta-Llama-3-8B-Instruct'
22
+ save_path = '/tmp/yujiepan/meta-llama-3-tiny-random'
23
+ repo_id = 'yujiepan/meta-llama-3-tiny-random'
24
+
25
+ config = transformers.AutoConfig.from_pretrained(
26
+ source_model_id,
27
+ trust_remote_code=True,
28
+ )
29
+ config._name_or_path = source_model_id
30
+ config.hidden_size = 4
31
+ config.intermediate_size = 14
32
+ config.num_attention_heads = 2
33
+ config.num_key_value_heads = 1
34
+ config.num_hidden_layers = 2
35
+ config.torch_dtype = "bfloat16"
36
+
37
+ model = transformers.AutoModelForCausalLM.from_config(
38
+ config,
39
+ trust_remote_code=True,
40
+ )
41
+ model = model.to(torch.bfloat16)
42
+ model.save_pretrained(save_path)
43
+
44
+ tokenizer = transformers.AutoTokenizer.from_pretrained(
45
+ source_model_id,
46
+ trust_remote_code=True,
47
+ )
48
+ tokenizer.save_pretrained(save_path)
49
+
50
+ model.float().generate(torch.tensor([[1, 2, 3]]).long(), max_length=16)
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
+ ```