yujiepan commited on
Commit
ab6ffa2
·
verified ·
1 Parent(s): eb54e16

Upload folder using huggingface_hub

Browse files
Files changed (7) hide show
  1. .meta.json +4 -0
  2. README.md +155 -0
  3. config.json +40 -0
  4. generation_config.json +10 -0
  5. model.safetensors +3 -0
  6. tokenizer.json +0 -0
  7. tokenizer_config.json +12 -0
.meta.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "torch": "2.10.0+cu128",
3
+ "transformers": "5.9.0"
4
+ }
README.md ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ base_model:
4
+ - sapientinc/HRM-Text-1B
5
+ ---
6
+
7
+ This tiny model is intended for debugging. It is randomly initialized using the configuration adapted from [sapientinc/HRM-Text-1B](https://huggingface.co/sapientinc/HRM-Text-1B).
8
+
9
+ | File path | Size |
10
+ |------|------|
11
+ | model.safetensors | 2.3MB |
12
+
13
+
14
+ ### Example usage:
15
+
16
+ ```python
17
+ from transformers import pipeline
18
+
19
+ model_id = "yujiepan/hrm-text-tiny-random"
20
+ pipe = pipeline(
21
+ "text-generation", model=model_id, device="cuda",
22
+ trust_remote_code=True, max_new_tokens=16,
23
+ )
24
+ print(pipe("Hello World!"))
25
+ ```
26
+
27
+ ### Codes to create this repo:
28
+
29
+ <details>
30
+ <summary>Click to expand</summary>
31
+
32
+ ```python
33
+ import json
34
+
35
+ import torch
36
+
37
+ from huggingface_hub import file_exists, hf_hub_download
38
+ from transformers import (
39
+ AutoConfig,
40
+ AutoModelForCausalLM,
41
+ AutoTokenizer,
42
+ GenerationConfig,
43
+ pipeline,
44
+ set_seed,
45
+ )
46
+
47
+ source_model_id = "sapientinc/HRM-Text-1B"
48
+ save_folder = "/tmp/yujiepan/hrm-text-tiny-random"
49
+ tokenizer = AutoTokenizer.from_pretrained(
50
+ source_model_id, trust_remote_code=True,
51
+ )
52
+ tokenizer.save_pretrained(save_folder)
53
+
54
+ with open(hf_hub_download(source_model_id, filename='config.json', repo_type='model'), 'r', encoding='utf-8') as f:
55
+ config_json: dict = json.load(f)
56
+ config_json.update({
57
+ "hidden_size": 8,
58
+ "intermediate_size": 64,
59
+ "num_attention_heads": 4,
60
+ "num_key_value_heads": 4,
61
+ "head_dim": 32,
62
+ "num_hidden_layers": 8,
63
+ })
64
+ with open(f"{save_folder}/config.json", "w", encoding='utf-8') as f:
65
+ json.dump(config_json, f, indent=2)
66
+
67
+ config = AutoConfig.from_pretrained(
68
+ save_folder,
69
+ trust_remote_code=True,
70
+ )
71
+
72
+ model = AutoModelForCausalLM.from_config(
73
+ config,
74
+ dtype=torch.bfloat16,
75
+ trust_remote_code=True,
76
+ )
77
+ if file_exists(filename="generation_config.json", repo_id=source_model_id, repo_type='model'):
78
+ model.generation_config = GenerationConfig.from_pretrained(
79
+ source_model_id, trust_remote_code=True,
80
+ )
81
+ set_seed(42)
82
+ model = model.cpu()
83
+ with torch.no_grad():
84
+ for name, p in sorted(model.named_parameters()):
85
+ torch.nn.init.normal_(p, 0, 0.2)
86
+ print(name, p.shape)
87
+ model.save_pretrained(save_folder)
88
+ ```
89
+
90
+ </details>
91
+
92
+ ### Printing the model:
93
+
94
+ <details><summary>Click to expand</summary>
95
+
96
+ ```text
97
+ HrmTextForCausalLM(
98
+ (model): HrmTextModel(
99
+ (embed_tokens): Embedding(65536, 8, padding_idx=5)
100
+ (rotary_emb): HrmTextRotaryEmbedding()
101
+ (L_module): HrmTextStack(
102
+ (layers): ModuleList(
103
+ (0-7): 8 x HrmTextDecoderLayer(
104
+ (self_attn): HrmTextAttention(
105
+ (q_proj): Linear(in_features=8, out_features=128, bias=False)
106
+ (k_proj): Linear(in_features=8, out_features=128, bias=False)
107
+ (v_proj): Linear(in_features=8, out_features=128, bias=False)
108
+ (o_proj): Linear(in_features=128, out_features=8, bias=False)
109
+ (gate_proj): Linear(in_features=8, out_features=128, bias=False)
110
+ )
111
+ (mlp): HrmTextMLP(
112
+ (gate_proj): Linear(in_features=8, out_features=64, bias=False)
113
+ (up_proj): Linear(in_features=8, out_features=64, bias=False)
114
+ (down_proj): Linear(in_features=64, out_features=8, bias=False)
115
+ (act_fn): SiLUActivation()
116
+ )
117
+ (input_layernorm): HrmTextRMSNorm(eps=1e-06)
118
+ (post_attention_layernorm): HrmTextRMSNorm(eps=1e-06)
119
+ )
120
+ )
121
+ (final_norm): HrmTextRMSNorm(eps=1e-06)
122
+ )
123
+ (H_module): HrmTextStack(
124
+ (layers): ModuleList(
125
+ (0-7): 8 x HrmTextDecoderLayer(
126
+ (self_attn): HrmTextAttention(
127
+ (q_proj): Linear(in_features=8, out_features=128, bias=False)
128
+ (k_proj): Linear(in_features=8, out_features=128, bias=False)
129
+ (v_proj): Linear(in_features=8, out_features=128, bias=False)
130
+ (o_proj): Linear(in_features=128, out_features=8, bias=False)
131
+ (gate_proj): Linear(in_features=8, out_features=128, bias=False)
132
+ )
133
+ (mlp): HrmTextMLP(
134
+ (gate_proj): Linear(in_features=8, out_features=64, bias=False)
135
+ (up_proj): Linear(in_features=8, out_features=64, bias=False)
136
+ (down_proj): Linear(in_features=64, out_features=8, bias=False)
137
+ (act_fn): SiLUActivation()
138
+ )
139
+ (input_layernorm): HrmTextRMSNorm(eps=1e-06)
140
+ (post_attention_layernorm): HrmTextRMSNorm(eps=1e-06)
141
+ )
142
+ )
143
+ (final_norm): HrmTextRMSNorm(eps=1e-06)
144
+ )
145
+ )
146
+ (lm_head): Linear(in_features=8, out_features=65536, bias=False)
147
+ )
148
+ ```
149
+
150
+ </details>
151
+
152
+ ### Test environment:
153
+
154
+ - torch: 2.10.0+cu128
155
+ - transformers: 5.9.0
config.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "H_cycles": 2,
3
+ "L_bp_cycles": [
4
+ 0,
5
+ 3
6
+ ],
7
+ "L_cycles": 3,
8
+ "architectures": [
9
+ "HrmTextForCausalLM"
10
+ ],
11
+ "attention_bias": false,
12
+ "attention_dropout": 0.0,
13
+ "bos_token_id": 6,
14
+ "dtype": "bfloat16",
15
+ "embedding_scale": 39.191835884530846,
16
+ "eos_token_id": 11,
17
+ "head_dim": 32,
18
+ "hidden_act": "silu",
19
+ "hidden_size": 8,
20
+ "initializer_range": 0.025515518153991442,
21
+ "intermediate_size": 64,
22
+ "max_position_embeddings": 4096,
23
+ "mlp_bias": false,
24
+ "model_type": "hrm_text",
25
+ "num_attention_heads": 4,
26
+ "num_hidden_layers": 64,
27
+ "num_key_value_heads": 4,
28
+ "num_layers_per_stack": 8,
29
+ "pad_token_id": 5,
30
+ "prefix_lm": true,
31
+ "rms_norm_eps": 1e-06,
32
+ "rope_parameters": {
33
+ "rope_theta": 10000.0,
34
+ "rope_type": "default"
35
+ },
36
+ "tie_word_embeddings": false,
37
+ "transformers_version": "5.9.0",
38
+ "use_cache": true,
39
+ "vocab_size": 65536
40
+ }
generation_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 6,
4
+ "eos_token_id": 11,
5
+ "output_attentions": false,
6
+ "output_hidden_states": false,
7
+ "pad_token_id": 5,
8
+ "transformers_version": "5.9.0",
9
+ "use_cache": true
10
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b349522f88714cebdf254463c9760e8681db04d80dd7b813efccf2487779c438
3
+ size 2317704
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": null,
3
+ "backend": "tokenizers",
4
+ "bos_token": "<|im_start|>",
5
+ "eos_token": "<|box_end|>",
6
+ "is_local": false,
7
+ "local_files_only": false,
8
+ "model_max_length": 1000000000000000019884624838656,
9
+ "pad_token": "<|endoftext|>",
10
+ "tokenizer_class": "Qwen2Tokenizer",
11
+ "unk_token": "<|endoftext|>"
12
+ }