kylesayrs commited on
Commit
36531b2
·
verified ·
1 Parent(s): 4027911

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ base_model:
4
+ - Qwen/Qwen3.8-2.4T-A95B
5
+ library_name: transformers
6
+ ---
7
+
8
+ # Qwen3.8-1.0B-A0.6B
9
+
10
+ This is a tiny version of [Qwen/Qwen3.8-2.4T-A95B](https://huggingface.co/Qwen/Qwen3.8-2.4T-A95B) created for testing and development.
11
+
12
+ ## Model Details
13
+
14
+ - **Base Model**: Qwen/Qwen3.8-2.4T-A95B
15
+ - **Architecture**: qwen3_5_moe_text (Qwen3_5MoeForCausalLM)
16
+ - **Total Parameters**: 0.97B
17
+ - **Activated Parameters**: ~0.6B
18
+
19
+ ## Configuration Changes
20
+
21
+ The following parameters were reduced from the original model:
22
+
23
+ | Parameter | Original | Tiny |
24
+ |---|---|---|
25
+ | num_hidden_layers | 92 | 8 |
26
+ | hidden_size | 8192 | 1024 |
27
+ | num_attention_heads | 64 | 8 |
28
+ | num_key_value_heads | 4 | 2 |
29
+ | head_dim | 256 | 128 |
30
+ | num_experts | 512 | 16 |
31
+ | num_experts_per_tok | 10 | 2 |
32
+ | moe_intermediate_size | 2048 | 1024 |
33
+ | shared_expert_intermediate_size | 2048 | 1024 |
34
+ | linear_key_head_dim | 128 | 64 |
35
+ | linear_num_key_heads | 16 | 4 |
36
+ | linear_num_value_heads | 128 | 16 |
37
+ | linear_value_head_dim | 128 | 64 |
38
+ | mtp_num_hidden_layers | 1 | 0 |
39
+
40
+ ## Checkpoint Structure
41
+
42
+ Single safetensors file with packed expert format (`experts.gate_up_proj`, `experts.down_proj`) matching the original checkpoint structure. Layer types follow the [linear, linear, linear, full] x 2 pattern from the original.
43
+
44
+ ## Usage
45
+
46
+ ```python
47
+ from transformers import AutoModelForCausalLM, AutoTokenizer
48
+
49
+ model = AutoModelForCausalLM.from_pretrained("Qwen3.8-1.0B-A0.6B", device_map="auto")
50
+ tokenizer = AutoTokenizer.from_pretrained("Qwen3.8-1.0B-A0.6B")
51
+
52
+ input_ids = tokenizer("According to all known laws", return_tensors="pt").input_ids.to(model.device)
53
+ output = model.generate(input_ids, max_new_tokens=20)
54
+ print(tokenizer.decode(output[0]))
55
+ ```
56
+
57
+ ## Creation Process
58
+
59
+ This model was created using the llm-compressor `create-tiny-model` claude skill.
60
+
61
+ 1. Inspected the original 2.4T parameter MoE model configuration
62
+ 2. Reduced all dimensions to create a ~1B parameter model while preserving the hybrid linear/full attention architecture
63
+ 3. Fine-tuned on a toy dataset to achieve perplexity ~1.0
64
+ 4. Converted checkpoint format to match the original (packed experts, correct tensor naming)
65
+ 5. Validated model loading and generation
66
+
67
+ ## Notes
68
+
69
+ - The model preserves the hybrid attention pattern: 6 linear attention layers and 2 full attention layers in a [linear, linear, linear, full] x 2 pattern
70
+ - MTP (multi-token prediction) layers are removed (mtp_num_hidden_layers=0) as they are not needed for the tiny model
71
+ - Expert weights use the packed format (gate_up_proj fused, stacked across experts) matching the original checkpoint
chat_template.jinja ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- macro render_content(content) %}
2
+ {%- if content is string %}
3
+ {{- content }}
4
+ {%- elif content is iterable and content is not mapping %}
5
+ {%- for item in content %}
6
+ {%- if 'text' in item %}
7
+ {{- item.text }}
8
+ {%- else %}
9
+ {{- raise_exception('Unexpected item type in content.') }}
10
+ {%- endif %}
11
+ {%- endfor %}
12
+ {%- elif content is none or content is undefined %}
13
+ {{- '' }}
14
+ {%- else %}
15
+ {{- raise_exception('Unexpected content type.') }}
16
+ {%- endif %}
17
+ {%- endmacro %}
18
+ {%- if not messages %}
19
+ {{- raise_exception('No messages provided.') }}
20
+ {%- endif %}
21
+ {%- if enable_thinking is defined and enable_thinking is false %}
22
+ {{- raise_exception('Disabling thinking is not supported.') }}
23
+ {%- endif %}
24
+ {%- set reasoning_instructions = '' %}
25
+ {%- set resolved_reasoning_effort = reasoning_effort|default('xhigh') %}
26
+ {%- if resolved_reasoning_effort not in ('xhigh', 'medium', 'low') %}
27
+ {{- raise_exception('Unexpected reasoning effort ' ~ reasoning_effort ~ '. Supported types are xhigh (default), medium, and low.') }}
28
+ {%- endif %}
29
+ {%- if resolved_reasoning_effort == 'xhigh' %}
30
+ {%- set reasoning_instructions = 'Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.' %}
31
+ {%- elif resolved_reasoning_effort == 'low' %}
32
+ {%- set reasoning_instructions = 'Reasoning effort is set to low. Keep your thinking brief and focused, moving directly to the conclusion without unnecessary elaboration.' %}
33
+ {%- endif %}
34
+ {%- if tools and tools is iterable and tools is not mapping %}
35
+ {{- '<|im_start|>system\n' }}
36
+ {%- if reasoning_instructions %}
37
+ {{- reasoning_instructions + '\n\n' }}
38
+ {%- endif %}
39
+ {{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }}
40
+ {%- for tool in tools %}
41
+ {{- "\n" }}
42
+ {{- tool | tojson }}
43
+ {%- endfor %}
44
+ {{- "\n</tools>" }}
45
+ {{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>' }}
46
+ {%- if messages[0].role == 'system' %}
47
+ {%- set content = render_content(messages[0].content)|trim %}
48
+ {%- if content %}
49
+ {{- '\n\n' + content }}
50
+ {%- endif %}
51
+ {%- endif %}
52
+ {{- '<|im_end|>\n' }}
53
+ {%- else %}
54
+ {%- if messages[0].role == 'system' %}
55
+ {%- set content = render_content(messages[0].content)|trim %}
56
+ {%- if content %}
57
+ {{- '<|im_start|>system\n' + (reasoning_instructions + '\n\n' if reasoning_instructions else '') + content + '<|im_end|>\n' }}
58
+ {%- elif reasoning_instructions %}
59
+ {{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }}
60
+ {%- endif %}
61
+ {%- elif reasoning_instructions %}
62
+ {{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }}
63
+ {%- endif %}
64
+ {%- endif %}
65
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
66
+ {%- for message in messages[::-1] %}
67
+ {%- set index = (messages|length - 1) - loop.index0 %}
68
+ {%- if ns.multi_step_tool and message.role == "user" %}
69
+ {%- set content = render_content(message.content)|trim %}
70
+ {%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}
71
+ {%- set ns.multi_step_tool = false %}
72
+ {%- set ns.last_query_index = index %}
73
+ {%- endif %}
74
+ {%- endif %}
75
+ {%- endfor %}
76
+ {%- if ns.multi_step_tool %}
77
+ {{- raise_exception('No user query found in messages.') }}
78
+ {%- endif %}
79
+ {%- for message in messages %}
80
+ {%- set content = render_content(message.content)|trim %}
81
+ {%- if message.role == "system" %}
82
+ {%- if not loop.first %}
83
+ {{- raise_exception('System message must be at the beginning.') }}
84
+ {%- endif %}
85
+ {%- elif message.role == "user" %}
86
+ {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
87
+ {%- elif message.role == "assistant" %}
88
+ {%- set reasoning_content = '' %}
89
+ {%- if message.reasoning_content is string %}
90
+ {%- set reasoning_content = message.reasoning_content %}
91
+ {%- endif %}
92
+ {%- set reasoning_content = reasoning_content|trim %}
93
+ {%- if preserve_thinking is undefined or preserve_thinking is true or loop.index0 > ns.last_query_index %}
94
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
95
+ {%- else %}
96
+ {{- '<|im_start|>' + message.role + '\n' + content }}
97
+ {%- endif %}
98
+ {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
99
+ {%- for tool_call in message.tool_calls %}
100
+ {%- if tool_call.function is defined %}
101
+ {%- set tool_call = tool_call.function %}
102
+ {%- endif %}
103
+ {%- if loop.first %}
104
+ {%- if content|trim %}
105
+ {{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
106
+ {%- else %}
107
+ {{- '<tool_call>\n<function=' + tool_call.name + '>\n' }}
108
+ {%- endif %}
109
+ {%- else %}
110
+ {{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
111
+ {%- endif %}
112
+ {%- if tool_call.arguments is defined and tool_call.arguments != '' %}
113
+ {%- for args_name, args_value in tool_call.arguments|items %}
114
+ {{- '<parameter=' + args_name + '>\n' }}
115
+ {%- set args_value = args_value | string if args_value is string else args_value | tojson | safe %}
116
+ {{- args_value }}
117
+ {{- '\n</parameter>\n' }}
118
+ {%- endfor %}
119
+ {%- endif %}
120
+ {{- '</function>\n</tool_call>' }}
121
+ {%- endfor %}
122
+ {%- endif %}
123
+ {{- '<|im_end|>\n' }}
124
+ {%- elif message.role == "tool" %}
125
+ {%- if loop.previtem and loop.previtem.role != "tool" %}
126
+ {{- '<|im_start|>user' }}
127
+ {%- endif %}
128
+ {{- '\n<tool_response>\n' }}
129
+ {{- content }}
130
+ {{- '\n</tool_response>' }}
131
+ {%- if not loop.last and loop.nextitem.role != "tool" %}
132
+ {{- '<|im_end|>\n' }}
133
+ {%- elif loop.last %}
134
+ {{- '<|im_end|>\n' }}
135
+ {%- endif %}
136
+ {%- else %}
137
+ {{- raise_exception('Unexpected message role.') }}
138
+ {%- endif %}
139
+ {%- endfor %}
140
+ {%- if add_generation_prompt %}
141
+ {{- '<|im_start|>assistant\n<think>\n' }}
142
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen3_5MoeForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "attn_output_gate": true,
8
+ "bos_token_id": 248044,
9
+ "dtype": "bfloat16",
10
+ "eos_token_id": 248044,
11
+ "full_attention_interval": 4,
12
+ "head_dim": 128,
13
+ "hidden_act": "silu",
14
+ "hidden_size": 1024,
15
+ "initializer_range": 0.02,
16
+ "layer_types": [
17
+ "linear_attention",
18
+ "linear_attention",
19
+ "linear_attention",
20
+ "full_attention",
21
+ "linear_attention",
22
+ "linear_attention",
23
+ "linear_attention",
24
+ "full_attention"
25
+ ],
26
+ "linear_conv_kernel_dim": 4,
27
+ "linear_key_head_dim": 64,
28
+ "linear_num_key_heads": 4,
29
+ "linear_num_value_heads": 16,
30
+ "linear_value_head_dim": 64,
31
+ "mamba_ssm_dtype": "float32",
32
+ "max_position_embeddings": 262144,
33
+ "model_type": "qwen3_5_moe_text",
34
+ "moe_intermediate_size": 1024,
35
+ "mtp_num_hidden_layers": 0,
36
+ "mtp_use_dedicated_embeddings": false,
37
+ "num_attention_heads": 8,
38
+ "num_experts": 16,
39
+ "num_experts_per_tok": 2,
40
+ "num_hidden_layers": 8,
41
+ "num_key_value_heads": 2,
42
+ "output_gate_type": "swish",
43
+ "output_router_logits": false,
44
+ "pad_token_id": null,
45
+ "partial_rotary_factor": 0.25,
46
+ "rms_norm_eps": 1e-06,
47
+ "rope_parameters": {
48
+ "partial_rotary_factor": 0.25,
49
+ "rope_theta": 10000000,
50
+ "rope_type": "default"
51
+ },
52
+ "router_aux_loss_coef": 0.001,
53
+ "shared_expert_intermediate_size": 1024,
54
+ "tie_word_embeddings": false,
55
+ "transformers_version": "5.16.0.dev0",
56
+ "use_cache": false,
57
+ "vocab_size": 248320
58
+ }
generation_config.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 248044,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 248046,
6
+ 248044
7
+ ],
8
+ "pad_token_id": 248044,
9
+ "temperature": 1.0,
10
+ "top_k": 20,
11
+ "top_p": 0.95,
12
+ "transformers_version": "5.16.0.dev0"
13
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5773d6e41575364b17ec9f6a5fe14130d7550caf011bcbcbafa2e81c6177e63f
3
+ size 1932276024
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:92b95cc075eb3b4ad8454383694d3e4189ebca27abc944d0a51dfa4e1d57024d
3
+ size 19989603
tokenizer_config.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "audio_bos_token": "<|audio_start|>",
4
+ "audio_eos_token": "<|audio_end|>",
5
+ "audio_token": "<|audio_pad|>",
6
+ "backend": "tokenizers",
7
+ "bos_token": null,
8
+ "clean_up_tokenization_spaces": false,
9
+ "eos_token": "<|im_end|>",
10
+ "errors": "replace",
11
+ "image_token": "<|image_pad|>",
12
+ "is_local": true,
13
+ "local_files_only": false,
14
+ "model_max_length": 262144,
15
+ "model_specific_special_tokens": {
16
+ "audio_bos_token": "<|audio_start|>",
17
+ "audio_eos_token": "<|audio_end|>",
18
+ "audio_token": "<|audio_pad|>",
19
+ "image_token": "<|image_pad|>",
20
+ "video_token": "<|video_pad|>",
21
+ "vision_bos_token": "<|vision_start|>",
22
+ "vision_eos_token": "<|vision_end|>"
23
+ },
24
+ "pad_token": "<|endoftext|>",
25
+ "pretokenize_regex": "(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\\r\\n\\p{L}\\p{N}]?[\\p{L}\\p{M}]+|\\p{N}| ?[^\\s\\p{L}\\p{M}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+",
26
+ "split_special_tokens": false,
27
+ "tokenizer_class": "Qwen2Tokenizer",
28
+ "unk_token": null,
29
+ "video_token": "<|video_pad|>",
30
+ "vision_bos_token": "<|vision_start|>",
31
+ "vision_eos_token": "<|vision_end|>"
32
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ef3c28452853be57cc7a98256773bea178871fd831abc6b79a5df0cf957888b5
3
+ size 5201