Add files using upload-large-folder tool
Browse files- audio_tokenizer/chat_template.jinja +120 -0
- audio_tokenizer/config.json +68 -0
- audio_tokenizer/generation_config.json +9 -0
- audio_tokenizer/tokenizer_config.json +267 -0
- config.json +369 -0
- configuration_mimo_v2.py +212 -0
- dflash/config.json +48 -0
- dflash/dflash.py +379 -0
- dflash/done_mtp +1 -0
- dflash/mask_embedding.pt +3 -0
- dflash/model.safetensors.index.json +70 -0
- generation_config.json +9 -0
- merges.txt +0 -0
- model.safetensors.index.json +0 -0
- preprocessor_config.json +19 -0
- tokenizer.json +0 -0
- tokenizer_config.json +293 -0
- vocab.json +0 -0
audio_tokenizer/chat_template.jinja
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- if tools %}
|
| 2 |
+
{{- '<|im_start|>system\n' }}
|
| 3 |
+
{%- if messages[0].role == 'system' %}
|
| 4 |
+
{%- if messages[0].content is string %}
|
| 5 |
+
{{- messages[0].content }}
|
| 6 |
+
{%- else %}
|
| 7 |
+
{%- for content in messages[0].content %}
|
| 8 |
+
{%- if content.type == 'audio' %}
|
| 9 |
+
{{- ("<|sosp|>" + (content.meta | tojson) + "<|eosp|>") }}
|
| 10 |
+
{%- elif content.type == 'text' %}
|
| 11 |
+
{{- content.text }}
|
| 12 |
+
{%- endif %}
|
| 13 |
+
{%- endfor %}
|
| 14 |
+
{%- endif %}
|
| 15 |
+
{%- endif %}
|
| 16 |
+
{{- '\n\n' }}
|
| 17 |
+
{{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
|
| 18 |
+
{%- for tool in tools %}
|
| 19 |
+
{{- "\n" }}
|
| 20 |
+
{{- tool | tojson }}
|
| 21 |
+
{%- endfor %}
|
| 22 |
+
{{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
|
| 23 |
+
{%- else %}
|
| 24 |
+
{%- if messages[0].role == 'system' %}
|
| 25 |
+
{{- '<|im_start|>system\n' }}
|
| 26 |
+
{%- if messages[0].content is string %}
|
| 27 |
+
{{- messages[0].content }}
|
| 28 |
+
{%- else %}
|
| 29 |
+
{%- for content in messages[0].content %}
|
| 30 |
+
{%- if content.type == 'audio' %}
|
| 31 |
+
{{- ("<|sosp|>" + (content.meta | tojson) + "<|eosp|>") }}
|
| 32 |
+
{%- elif content.type == 'text' %}
|
| 33 |
+
{{- content.text }}
|
| 34 |
+
{%- endif %}
|
| 35 |
+
{%- endfor %}
|
| 36 |
+
{%- endif %}
|
| 37 |
+
{{- '\n<|im_end|>\n' }}
|
| 38 |
+
{%- endif %}
|
| 39 |
+
{%- endif %}
|
| 40 |
+
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1, assistant_is_last=false) %}
|
| 41 |
+
{%- for message in messages[::-1] %}
|
| 42 |
+
{%- set index = (messages|length - 1) - loop.index0 %}
|
| 43 |
+
{%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
|
| 44 |
+
{%- set ns.multi_step_tool = false %}
|
| 45 |
+
{%- set ns.last_query_index = index %}
|
| 46 |
+
{%- endif %}
|
| 47 |
+
{%- endfor %}
|
| 48 |
+
{%- for message in messages %}
|
| 49 |
+
{%- if message.content is string %}
|
| 50 |
+
{%- set content = message.content %}
|
| 51 |
+
{%- else %}
|
| 52 |
+
{%- set content = namespace(text="") %}
|
| 53 |
+
{%- for mcontent in message.content %}
|
| 54 |
+
{%- if mcontent.type == 'audio' %}
|
| 55 |
+
{%- set content.text = content.text~("<|sosp|>" + (mcontent.meta | tojson) + "<|eosp|>") %}
|
| 56 |
+
{%- elif mcontent.type == 'text' %}
|
| 57 |
+
{%- set content.text = content.text~mcontent.text %}
|
| 58 |
+
{%- endif %}
|
| 59 |
+
{%- endfor %}
|
| 60 |
+
{%- set content = content.text %}
|
| 61 |
+
{%- endif %}
|
| 62 |
+
{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
|
| 63 |
+
{{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
|
| 64 |
+
{%- elif message.role == "assistant" %}
|
| 65 |
+
{%- set reasoning_content = "" %}
|
| 66 |
+
{%- if message.reasoning_content is string %}
|
| 67 |
+
{%- set reasoning_content = message.reasoning_content %}
|
| 68 |
+
{%- else %}
|
| 69 |
+
{%- if '</think>' in content %}
|
| 70 |
+
{%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
|
| 71 |
+
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
|
| 72 |
+
{%- endif %}
|
| 73 |
+
{%- endif %}
|
| 74 |
+
{%- if loop.index0 > ns.last_query_index %}
|
| 75 |
+
{%- if loop.last or (not loop.last and reasoning_content) %}
|
| 76 |
+
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip("\n") + '\n</think>\n\n' + content.lstrip('\n') }}
|
| 77 |
+
{%- else %}
|
| 78 |
+
{{- '<|im_start|>' + message.role + '\n' + content }}
|
| 79 |
+
{%- endif %}
|
| 80 |
+
{%- else %}
|
| 81 |
+
{{- '<|im_start|>' + message.role + '\n' + content }}
|
| 82 |
+
{%- endif %}
|
| 83 |
+
{%- if message.tool_calls %}
|
| 84 |
+
{%- for tool_call in message.tool_calls %}
|
| 85 |
+
{%- if (loop.first and content) or (not loop.first) %}{{- '\n' }}{%- endif %}
|
| 86 |
+
{%- if tool_call.function %}
|
| 87 |
+
{%- set tool_call = tool_call.function %}
|
| 88 |
+
{%- endif %}
|
| 89 |
+
{{- '<tool_call>\n{"name": "' }}
|
| 90 |
+
{{- tool_call.name }}
|
| 91 |
+
{{- '", "arguments": ' }}
|
| 92 |
+
{%- if tool_call.arguments is string %}
|
| 93 |
+
{{- tool_call.arguments }}
|
| 94 |
+
{%- else %}
|
| 95 |
+
{{- tool_call.arguments | tojson }}
|
| 96 |
+
{%- endif %}
|
| 97 |
+
{{- '}\n</tool_call>' }}
|
| 98 |
+
{%- endfor %}
|
| 99 |
+
{%- endif %}
|
| 100 |
+
{%- if loop.last %}
|
| 101 |
+
{%- set ns.assistant_is_last = true %}
|
| 102 |
+
{%- else %}
|
| 103 |
+
{{- '<|im_end|>\n' }}
|
| 104 |
+
{%- endif %}
|
| 105 |
+
{%- elif message.role == "tool" %}
|
| 106 |
+
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}{{- '<|im_start|>user' }}{%- endif %}
|
| 107 |
+
{{- '\n<tool_response>\n' }}
|
| 108 |
+
{{- content }}
|
| 109 |
+
{{- '\n</tool_response>' }}
|
| 110 |
+
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}{{- '<|im_end|>\n' }}{%- endif %}
|
| 111 |
+
{%- endif %}
|
| 112 |
+
{%- endfor %}
|
| 113 |
+
{%- if add_generation_prompt and not ns.assistant_is_last %}
|
| 114 |
+
{{- '<|im_start|>assistant\n' }}
|
| 115 |
+
{%- if audio_output %}
|
| 116 |
+
{{- '<|sostm|>'}}
|
| 117 |
+
{%- elif not enable_thinking %}
|
| 118 |
+
{{- '<think>\n\n</think>\n' }}
|
| 119 |
+
{%- endif %}
|
| 120 |
+
{%- endif %}
|
audio_tokenizer/config.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"max_audio_seconds": 300,
|
| 3 |
+
"stride_size": 2,
|
| 4 |
+
"avg_pooler": 2,
|
| 5 |
+
"d_model": 1024,
|
| 6 |
+
"scale_embedding": false,
|
| 7 |
+
"kernel_size": 3,
|
| 8 |
+
"activation_function": "gelu",
|
| 9 |
+
"encoder_layers": 24,
|
| 10 |
+
"encoder_skip_layer_id": 3,
|
| 11 |
+
"encoder_attention_heads": 16,
|
| 12 |
+
"encoder_ffn_dim": 4096,
|
| 13 |
+
"encoder_causal": true,
|
| 14 |
+
"encoder_attn_window_size": [
|
| 15 |
+
128,
|
| 16 |
+
0
|
| 17 |
+
],
|
| 18 |
+
"decoder_layers": 24,
|
| 19 |
+
"decoder_attention_heads": 16,
|
| 20 |
+
"decoder_ffn_dim": 4096,
|
| 21 |
+
"decoder_kernel_size": 3,
|
| 22 |
+
"decoder_stride_size": 2,
|
| 23 |
+
"decoder_causal": true,
|
| 24 |
+
"decoder_attn_window_size": [
|
| 25 |
+
128,
|
| 26 |
+
0
|
| 27 |
+
],
|
| 28 |
+
"nfft": 960,
|
| 29 |
+
"n_mels": 128,
|
| 30 |
+
"sampling_rate": 24000,
|
| 31 |
+
"hop_length": 240,
|
| 32 |
+
"window_size": 960,
|
| 33 |
+
"vocoder_padding": "same",
|
| 34 |
+
"fmin": 0,
|
| 35 |
+
"fmax": null,
|
| 36 |
+
"num_quantizers": 20,
|
| 37 |
+
"codebook_size": [
|
| 38 |
+
1024,
|
| 39 |
+
1024,
|
| 40 |
+
256,
|
| 41 |
+
128,
|
| 42 |
+
128,
|
| 43 |
+
128,
|
| 44 |
+
128,
|
| 45 |
+
128,
|
| 46 |
+
128,
|
| 47 |
+
128,
|
| 48 |
+
128,
|
| 49 |
+
128,
|
| 50 |
+
128,
|
| 51 |
+
128,
|
| 52 |
+
128,
|
| 53 |
+
128,
|
| 54 |
+
128,
|
| 55 |
+
128,
|
| 56 |
+
128,
|
| 57 |
+
128
|
| 58 |
+
],
|
| 59 |
+
"threshold_ema_dead_code": 2,
|
| 60 |
+
"position_embedding_type": "rope",
|
| 61 |
+
"rope_theta": 10000,
|
| 62 |
+
"rope_type": "default",
|
| 63 |
+
"ln_type": "LayerNorm",
|
| 64 |
+
"use_istft_only": true,
|
| 65 |
+
"hybrid_attention": true,
|
| 66 |
+
"hybrid_block_size": 8,
|
| 67 |
+
"swa_per_block": 2
|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oftext|>",
|
| 7 |
+
"lstrip": false,
|
| 8 |
+
"normalized": false,
|
| 9 |
+
"rstrip": false,
|
| 10 |
+
"single_word": false,
|
| 11 |
+
"special": true
|
| 12 |
+
},
|
| 13 |
+
"151644": {
|
| 14 |
+
"content": "<|im_start|>",
|
| 15 |
+
"lstrip": false,
|
| 16 |
+
"normalized": false,
|
| 17 |
+
"rstrip": false,
|
| 18 |
+
"single_word": false,
|
| 19 |
+
"special": true
|
| 20 |
+
},
|
| 21 |
+
"151645": {
|
| 22 |
+
"content": "<|im_end|>",
|
| 23 |
+
"lstrip": false,
|
| 24 |
+
"normalized": false,
|
| 25 |
+
"rstrip": false,
|
| 26 |
+
"single_word": false,
|
| 27 |
+
"special": true
|
| 28 |
+
},
|
| 29 |
+
"151646": {
|
| 30 |
+
"content": "<|object_ref_start|>",
|
| 31 |
+
"lstrip": false,
|
| 32 |
+
"normalized": false,
|
| 33 |
+
"rstrip": false,
|
| 34 |
+
"single_word": false,
|
| 35 |
+
"special": true
|
| 36 |
+
},
|
| 37 |
+
"151647": {
|
| 38 |
+
"content": "<|object_ref_end|>",
|
| 39 |
+
"lstrip": false,
|
| 40 |
+
"normalized": false,
|
| 41 |
+
"rstrip": false,
|
| 42 |
+
"single_word": false,
|
| 43 |
+
"special": true
|
| 44 |
+
},
|
| 45 |
+
"151648": {
|
| 46 |
+
"content": "<|box_start|>",
|
| 47 |
+
"lstrip": false,
|
| 48 |
+
"normalized": false,
|
| 49 |
+
"rstrip": false,
|
| 50 |
+
"single_word": false,
|
| 51 |
+
"special": true
|
| 52 |
+
},
|
| 53 |
+
"151649": {
|
| 54 |
+
"content": "<|box_end|>",
|
| 55 |
+
"lstrip": false,
|
| 56 |
+
"normalized": false,
|
| 57 |
+
"rstrip": false,
|
| 58 |
+
"single_word": false,
|
| 59 |
+
"special": true
|
| 60 |
+
},
|
| 61 |
+
"151650": {
|
| 62 |
+
"content": "<|quad_start|>",
|
| 63 |
+
"lstrip": false,
|
| 64 |
+
"normalized": false,
|
| 65 |
+
"rstrip": false,
|
| 66 |
+
"single_word": false,
|
| 67 |
+
"special": true
|
| 68 |
+
},
|
| 69 |
+
"151651": {
|
| 70 |
+
"content": "<|quad_end|>",
|
| 71 |
+
"lstrip": false,
|
| 72 |
+
"normalized": false,
|
| 73 |
+
"rstrip": false,
|
| 74 |
+
"single_word": false,
|
| 75 |
+
"special": true
|
| 76 |
+
},
|
| 77 |
+
"151652": {
|
| 78 |
+
"content": "<|vision_start|>",
|
| 79 |
+
"lstrip": false,
|
| 80 |
+
"normalized": false,
|
| 81 |
+
"rstrip": false,
|
| 82 |
+
"single_word": false,
|
| 83 |
+
"special": true
|
| 84 |
+
},
|
| 85 |
+
"151653": {
|
| 86 |
+
"content": "<|vision_end|>",
|
| 87 |
+
"lstrip": false,
|
| 88 |
+
"normalized": false,
|
| 89 |
+
"rstrip": false,
|
| 90 |
+
"single_word": false,
|
| 91 |
+
"special": true
|
| 92 |
+
},
|
| 93 |
+
"151654": {
|
| 94 |
+
"content": "<|vision_pad|>",
|
| 95 |
+
"lstrip": false,
|
| 96 |
+
"normalized": false,
|
| 97 |
+
"rstrip": false,
|
| 98 |
+
"single_word": false,
|
| 99 |
+
"special": true
|
| 100 |
+
},
|
| 101 |
+
"151655": {
|
| 102 |
+
"content": "<|image_pad|>",
|
| 103 |
+
"lstrip": false,
|
| 104 |
+
"normalized": false,
|
| 105 |
+
"rstrip": false,
|
| 106 |
+
"single_word": false,
|
| 107 |
+
"special": true
|
| 108 |
+
},
|
| 109 |
+
"151656": {
|
| 110 |
+
"content": "<|video_pad|>",
|
| 111 |
+
"lstrip": false,
|
| 112 |
+
"normalized": false,
|
| 113 |
+
"rstrip": false,
|
| 114 |
+
"single_word": false,
|
| 115 |
+
"special": true
|
| 116 |
+
},
|
| 117 |
+
"151657": {
|
| 118 |
+
"content": "<tool_call>",
|
| 119 |
+
"lstrip": false,
|
| 120 |
+
"normalized": false,
|
| 121 |
+
"rstrip": false,
|
| 122 |
+
"single_word": false,
|
| 123 |
+
"special": false
|
| 124 |
+
},
|
| 125 |
+
"151658": {
|
| 126 |
+
"content": "</tool_call>",
|
| 127 |
+
"lstrip": false,
|
| 128 |
+
"normalized": false,
|
| 129 |
+
"rstrip": false,
|
| 130 |
+
"single_word": false,
|
| 131 |
+
"special": false
|
| 132 |
+
},
|
| 133 |
+
"151659": {
|
| 134 |
+
"content": "<|fim_prefix|>",
|
| 135 |
+
"lstrip": false,
|
| 136 |
+
"normalized": false,
|
| 137 |
+
"rstrip": false,
|
| 138 |
+
"single_word": false,
|
| 139 |
+
"special": false
|
| 140 |
+
},
|
| 141 |
+
"151660": {
|
| 142 |
+
"content": "<|fim_middle|>",
|
| 143 |
+
"lstrip": false,
|
| 144 |
+
"normalized": false,
|
| 145 |
+
"rstrip": false,
|
| 146 |
+
"single_word": false,
|
| 147 |
+
"special": false
|
| 148 |
+
},
|
| 149 |
+
"151661": {
|
| 150 |
+
"content": "<|fim_suffix|>",
|
| 151 |
+
"lstrip": false,
|
| 152 |
+
"normalized": false,
|
| 153 |
+
"rstrip": false,
|
| 154 |
+
"single_word": false,
|
| 155 |
+
"special": false
|
| 156 |
+
},
|
| 157 |
+
"151662": {
|
| 158 |
+
"content": "<|fim_pad|>",
|
| 159 |
+
"lstrip": false,
|
| 160 |
+
"normalized": false,
|
| 161 |
+
"rstrip": false,
|
| 162 |
+
"single_word": false,
|
| 163 |
+
"special": false
|
| 164 |
+
},
|
| 165 |
+
"151663": {
|
| 166 |
+
"content": "<|repo_name|>",
|
| 167 |
+
"lstrip": false,
|
| 168 |
+
"normalized": false,
|
| 169 |
+
"rstrip": false,
|
| 170 |
+
"single_word": false,
|
| 171 |
+
"special": false
|
| 172 |
+
},
|
| 173 |
+
"151664": {
|
| 174 |
+
"content": "<|file_sep|>",
|
| 175 |
+
"lstrip": false,
|
| 176 |
+
"normalized": false,
|
| 177 |
+
"rstrip": false,
|
| 178 |
+
"single_word": false,
|
| 179 |
+
"special": false
|
| 180 |
+
},
|
| 181 |
+
"151665": {
|
| 182 |
+
"content": "<|mimo_audio_start|>",
|
| 183 |
+
"lstrip": false,
|
| 184 |
+
"normalized": false,
|
| 185 |
+
"rstrip": false,
|
| 186 |
+
"single_word": false,
|
| 187 |
+
"special": true
|
| 188 |
+
},
|
| 189 |
+
"151666": {
|
| 190 |
+
"content": "<|mimo_audio_end|>",
|
| 191 |
+
"lstrip": false,
|
| 192 |
+
"normalized": false,
|
| 193 |
+
"rstrip": false,
|
| 194 |
+
"single_word": false,
|
| 195 |
+
"special": true
|
| 196 |
+
},
|
| 197 |
+
"151667": {
|
| 198 |
+
"content": "<think>",
|
| 199 |
+
"lstrip": false,
|
| 200 |
+
"normalized": false,
|
| 201 |
+
"rstrip": false,
|
| 202 |
+
"single_word": false,
|
| 203 |
+
"special": false
|
| 204 |
+
},
|
| 205 |
+
"151668": {
|
| 206 |
+
"content": "</think>",
|
| 207 |
+
"lstrip": false,
|
| 208 |
+
"normalized": false,
|
| 209 |
+
"rstrip": false,
|
| 210 |
+
"single_word": false,
|
| 211 |
+
"special": false
|
| 212 |
+
},
|
| 213 |
+
"151669": {
|
| 214 |
+
"content": "<|audio_pad|>",
|
| 215 |
+
"lstrip": false,
|
| 216 |
+
"normalized": false,
|
| 217 |
+
"rstrip": false,
|
| 218 |
+
"single_word": false,
|
| 219 |
+
"special": true
|
| 220 |
+
},
|
| 221 |
+
"151670": {
|
| 222 |
+
"content": "<|mimo_video_start|>",
|
| 223 |
+
"lstrip": false,
|
| 224 |
+
"normalized": false,
|
| 225 |
+
"rstrip": false,
|
| 226 |
+
"single_word": false,
|
| 227 |
+
"special": true
|
| 228 |
+
},
|
| 229 |
+
"151671": {
|
| 230 |
+
"content": "<|mimo_video_end|>",
|
| 231 |
+
"lstrip": false,
|
| 232 |
+
"normalized": false,
|
| 233 |
+
"rstrip": false,
|
| 234 |
+
"single_word": false,
|
| 235 |
+
"special": true
|
| 236 |
+
}
|
| 237 |
+
},
|
| 238 |
+
"additional_special_tokens": [
|
| 239 |
+
"<|im_start|>",
|
| 240 |
+
"<|im_end|>",
|
| 241 |
+
"<|object_ref_start|>",
|
| 242 |
+
"<|object_ref_end|>",
|
| 243 |
+
"<|box_start|>",
|
| 244 |
+
"<|box_end|>",
|
| 245 |
+
"<|quad_start|>",
|
| 246 |
+
"<|quad_end|>",
|
| 247 |
+
"<|vision_start|>",
|
| 248 |
+
"<|vision_end|>",
|
| 249 |
+
"<|vision_pad|>",
|
| 250 |
+
"<|image_pad|>",
|
| 251 |
+
"<|video_pad|>",
|
| 252 |
+
"<|audio_pad|>",
|
| 253 |
+
"<|mimo_audio_start|>",
|
| 254 |
+
"<|mimo_audio_end|>",
|
| 255 |
+
"<|mimo_video_start|>",
|
| 256 |
+
"<|mimo_video_end|>"
|
| 257 |
+
],
|
| 258 |
+
"bos_token": null,
|
| 259 |
+
"clean_up_tokenization_spaces": false,
|
| 260 |
+
"eos_token": "<|im_end|>",
|
| 261 |
+
"errors": "replace",
|
| 262 |
+
"model_max_length": 131072,
|
| 263 |
+
"pad_token": "<|endoftext|>",
|
| 264 |
+
"split_special_tokens": false,
|
| 265 |
+
"tokenizer_class": "Qwen2Tokenizer",
|
| 266 |
+
"unk_token": null
|
| 267 |
+
}
|
config.json
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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+
"attention_dropout": 0.0,
|
| 11 |
+
"attention_projection_layout": "fused_qkv",
|
| 12 |
+
"attention_value_scale": 0.707,
|
| 13 |
+
"add_full_attention_sink_bias": false,
|
| 14 |
+
"add_swa_attention_sink_bias": true,
|
| 15 |
+
"audio_config": {
|
| 16 |
+
"add_post_norm": true,
|
| 17 |
+
"audio_channels": 20,
|
| 18 |
+
"audio_segment_size": 6000,
|
| 19 |
+
"group_size": 4,
|
| 20 |
+
"input_full_attention": true,
|
| 21 |
+
"input_local_attn_heads": 16,
|
| 22 |
+
"input_local_dim": 1024,
|
| 23 |
+
"input_local_head_dim": 64,
|
| 24 |
+
"input_local_hidden_dropout": 0.0,
|
| 25 |
+
"input_local_intermediate_size": 4096,
|
| 26 |
+
"input_local_layers": 6,
|
| 27 |
+
"out_hidden_size": 4096,
|
| 28 |
+
"partial_rotary_factor": 1.0,
|
| 29 |
+
"projection_layers": 2,
|
| 30 |
+
"rope_theta": 640000,
|
| 31 |
+
"speech_vocab_size": "1280",
|
| 32 |
+
"speech_zeroemb_idx": "1024",
|
| 33 |
+
"tokenizer_version": "v2"
|
| 34 |
+
},
|
| 35 |
+
"dtype": "bfloat16",
|
| 36 |
+
"eos_token_id": 151645,
|
| 37 |
+
"head_dim": 192,
|
| 38 |
+
"hidden_act": "silu",
|
| 39 |
+
"hidden_size": 4096,
|
| 40 |
+
"hybrid_block_size": null,
|
| 41 |
+
"hybrid_layer_pattern": [
|
| 42 |
+
0,
|
| 43 |
+
1,
|
| 44 |
+
1,
|
| 45 |
+
1,
|
| 46 |
+
1,
|
| 47 |
+
0,
|
| 48 |
+
1,
|
| 49 |
+
1,
|
| 50 |
+
1,
|
| 51 |
+
1,
|
| 52 |
+
1,
|
| 53 |
+
0,
|
| 54 |
+
1,
|
| 55 |
+
1,
|
| 56 |
+
1,
|
| 57 |
+
1,
|
| 58 |
+
1,
|
| 59 |
+
0,
|
| 60 |
+
1,
|
| 61 |
+
1,
|
| 62 |
+
1,
|
| 63 |
+
1,
|
| 64 |
+
1,
|
| 65 |
+
0,
|
| 66 |
+
1,
|
| 67 |
+
1,
|
| 68 |
+
1,
|
| 69 |
+
1,
|
| 70 |
+
1,
|
| 71 |
+
0,
|
| 72 |
+
1,
|
| 73 |
+
1,
|
| 74 |
+
1,
|
| 75 |
+
1,
|
| 76 |
+
1,
|
| 77 |
+
0,
|
| 78 |
+
1,
|
| 79 |
+
1,
|
| 80 |
+
1,
|
| 81 |
+
1,
|
| 82 |
+
1,
|
| 83 |
+
0,
|
| 84 |
+
1,
|
| 85 |
+
1,
|
| 86 |
+
1,
|
| 87 |
+
1,
|
| 88 |
+
1,
|
| 89 |
+
0
|
| 90 |
+
],
|
| 91 |
+
"image_token_id": 151655,
|
| 92 |
+
"initializer_range": 0.02,
|
| 93 |
+
"intermediate_size": 16384,
|
| 94 |
+
"layernorm_epsilon": 1e-05,
|
| 95 |
+
"max_position_embeddings": 1048576,
|
| 96 |
+
"model_type": "mimo_v2",
|
| 97 |
+
"moe_intermediate_size": 2048,
|
| 98 |
+
"moe_layer_freq": [
|
| 99 |
+
0,
|
| 100 |
+
1,
|
| 101 |
+
1,
|
| 102 |
+
1,
|
| 103 |
+
1,
|
| 104 |
+
1,
|
| 105 |
+
1,
|
| 106 |
+
1,
|
| 107 |
+
1,
|
| 108 |
+
1,
|
| 109 |
+
1,
|
| 110 |
+
1,
|
| 111 |
+
1,
|
| 112 |
+
1,
|
| 113 |
+
1,
|
| 114 |
+
1,
|
| 115 |
+
1,
|
| 116 |
+
1,
|
| 117 |
+
1,
|
| 118 |
+
1,
|
| 119 |
+
1,
|
| 120 |
+
1,
|
| 121 |
+
1,
|
| 122 |
+
1,
|
| 123 |
+
1,
|
| 124 |
+
1,
|
| 125 |
+
1,
|
| 126 |
+
1,
|
| 127 |
+
1,
|
| 128 |
+
1,
|
| 129 |
+
1,
|
| 130 |
+
1,
|
| 131 |
+
1,
|
| 132 |
+
1,
|
| 133 |
+
1,
|
| 134 |
+
1,
|
| 135 |
+
1,
|
| 136 |
+
1,
|
| 137 |
+
1,
|
| 138 |
+
1,
|
| 139 |
+
1,
|
| 140 |
+
1,
|
| 141 |
+
1,
|
| 142 |
+
1,
|
| 143 |
+
1,
|
| 144 |
+
1,
|
| 145 |
+
1,
|
| 146 |
+
1
|
| 147 |
+
],
|
| 148 |
+
"n_group": 1,
|
| 149 |
+
"n_routed_experts": 256,
|
| 150 |
+
"n_shared_experts": null,
|
| 151 |
+
"norm_topk_prob": true,
|
| 152 |
+
"num_attention_heads": 64,
|
| 153 |
+
"num_experts_per_tok": 8,
|
| 154 |
+
"num_hidden_layers": 48,
|
| 155 |
+
"num_key_value_heads": 4,
|
| 156 |
+
"pad_token_id": 151643,
|
| 157 |
+
"partial_rotary_factor": 0.334,
|
| 158 |
+
"processor_config": {
|
| 159 |
+
"audio_avg_pooler": 2,
|
| 160 |
+
"audio_channels": 20,
|
| 161 |
+
"audio_end_token_id": 151674,
|
| 162 |
+
"audio_fmax": null,
|
| 163 |
+
"audio_fmin": 0,
|
| 164 |
+
"audio_group_size": 4,
|
| 165 |
+
"audio_hop_length": 240,
|
| 166 |
+
"audio_input_id_per_second": 25.0,
|
| 167 |
+
"audio_kernel_size": 3,
|
| 168 |
+
"audio_n_mels": 128,
|
| 169 |
+
"audio_nfft": 960,
|
| 170 |
+
"audio_sampling_rate": 24000,
|
| 171 |
+
"audio_segment_size": 6000,
|
| 172 |
+
"audio_start_token_id": 151673,
|
| 173 |
+
"audio_stride_size": 2,
|
| 174 |
+
"audio_token_id": 151669,
|
| 175 |
+
"audio_window_size": 960,
|
| 176 |
+
"audio_zeroemb_idx": [
|
| 177 |
+
1024,
|
| 178 |
+
1024,
|
| 179 |
+
1024,
|
| 180 |
+
1024,
|
| 181 |
+
1024,
|
| 182 |
+
1024,
|
| 183 |
+
1024,
|
| 184 |
+
1024,
|
| 185 |
+
1024,
|
| 186 |
+
1024,
|
| 187 |
+
1024,
|
| 188 |
+
1024,
|
| 189 |
+
1024,
|
| 190 |
+
1024,
|
| 191 |
+
1024,
|
| 192 |
+
1024,
|
| 193 |
+
1024,
|
| 194 |
+
1024,
|
| 195 |
+
1024,
|
| 196 |
+
1024
|
| 197 |
+
],
|
| 198 |
+
"fps": 1.0,
|
| 199 |
+
"image_max_pixels": 8388608,
|
| 200 |
+
"image_min_pixels": 8192,
|
| 201 |
+
"image_token_id": 151655,
|
| 202 |
+
"max_frames": 3600,
|
| 203 |
+
"merge_size": 2,
|
| 204 |
+
"min_frames": null,
|
| 205 |
+
"num_frames": null,
|
| 206 |
+
"pad_token_id": 151643,
|
| 207 |
+
"patch_size": 16,
|
| 208 |
+
"rope_type": "rope",
|
| 209 |
+
"temporal_compression_ratio": 1,
|
| 210 |
+
"temporal_patch_size": 2,
|
| 211 |
+
"use_per_grid_t_timestamps": false,
|
| 212 |
+
"use_video_timestamps": true,
|
| 213 |
+
"video_audio_interleave_length": 0.0,
|
| 214 |
+
"video_end_token_id": 151671,
|
| 215 |
+
"video_max_pixels": 8388608,
|
| 216 |
+
"video_min_pixels": 8192,
|
| 217 |
+
"video_process_num_threads": 16,
|
| 218 |
+
"video_start_token_id": 151670,
|
| 219 |
+
"video_token_id": 151656,
|
| 220 |
+
"video_tokens_per_second": 2,
|
| 221 |
+
"video_total_max_pixels": 268435456,
|
| 222 |
+
"vision_end_token_id": 151653,
|
| 223 |
+
"vision_start_token_id": 151652
|
| 224 |
+
},
|
| 225 |
+
"quantization_config": {
|
| 226 |
+
"activation_scheme": "dynamic",
|
| 227 |
+
"fmt": "e4m3",
|
| 228 |
+
"ignored_layers": [
|
| 229 |
+
"model.layers.0.self_attn.o_proj",
|
| 230 |
+
"model.layers.1.self_attn.o_proj",
|
| 231 |
+
"model.layers.2.self_attn.o_proj",
|
| 232 |
+
"model.layers.3.self_attn.o_proj",
|
| 233 |
+
"model.layers.4.self_attn.o_proj",
|
| 234 |
+
"model.layers.5.self_attn.o_proj",
|
| 235 |
+
"model.layers.6.self_attn.o_proj",
|
| 236 |
+
"model.layers.7.self_attn.o_proj",
|
| 237 |
+
"model.layers.8.self_attn.o_proj",
|
| 238 |
+
"model.layers.9.self_attn.o_proj",
|
| 239 |
+
"model.layers.10.self_attn.o_proj",
|
| 240 |
+
"model.layers.11.self_attn.o_proj",
|
| 241 |
+
"model.layers.12.self_attn.o_proj",
|
| 242 |
+
"model.layers.13.self_attn.o_proj",
|
| 243 |
+
"model.layers.14.self_attn.o_proj",
|
| 244 |
+
"model.layers.15.self_attn.o_proj",
|
| 245 |
+
"model.layers.16.self_attn.o_proj",
|
| 246 |
+
"model.layers.17.self_attn.o_proj",
|
| 247 |
+
"model.layers.18.self_attn.o_proj",
|
| 248 |
+
"model.layers.19.self_attn.o_proj",
|
| 249 |
+
"model.layers.20.self_attn.o_proj",
|
| 250 |
+
"model.layers.21.self_attn.o_proj",
|
| 251 |
+
"model.layers.22.self_attn.o_proj",
|
| 252 |
+
"model.layers.23.self_attn.o_proj",
|
| 253 |
+
"model.layers.24.self_attn.o_proj",
|
| 254 |
+
"model.layers.25.self_attn.o_proj",
|
| 255 |
+
"model.layers.26.self_attn.o_proj",
|
| 256 |
+
"model.layers.27.self_attn.o_proj",
|
| 257 |
+
"model.layers.28.self_attn.o_proj",
|
| 258 |
+
"model.layers.29.self_attn.o_proj",
|
| 259 |
+
"model.layers.30.self_attn.o_proj",
|
| 260 |
+
"model.layers.31.self_attn.o_proj",
|
| 261 |
+
"model.layers.32.self_attn.o_proj",
|
| 262 |
+
"model.layers.33.self_attn.o_proj",
|
| 263 |
+
"model.layers.34.self_attn.o_proj",
|
| 264 |
+
"model.layers.35.self_attn.o_proj",
|
| 265 |
+
"model.layers.36.self_attn.o_proj",
|
| 266 |
+
"model.layers.37.self_attn.o_proj",
|
| 267 |
+
"model.layers.38.self_attn.o_proj",
|
| 268 |
+
"model.layers.39.self_attn.o_proj",
|
| 269 |
+
"model.layers.40.self_attn.o_proj",
|
| 270 |
+
"model.layers.41.self_attn.o_proj",
|
| 271 |
+
"model.layers.42.self_attn.o_proj",
|
| 272 |
+
"model.layers.43.self_attn.o_proj",
|
| 273 |
+
"model.layers.44.self_attn.o_proj",
|
| 274 |
+
"model.layers.45.self_attn.o_proj",
|
| 275 |
+
"model.layers.46.self_attn.o_proj",
|
| 276 |
+
"model.layers.47.self_attn.o_proj",
|
| 277 |
+
"model.decoder.self_attn.o_proj"
|
| 278 |
+
],
|
| 279 |
+
"quant_method": "fp8",
|
| 280 |
+
"store_dtype": "fp8",
|
| 281 |
+
"weight_block_size": [
|
| 282 |
+
128,
|
| 283 |
+
128
|
| 284 |
+
]
|
| 285 |
+
},
|
| 286 |
+
"rope_scaling": {
|
| 287 |
+
"type": "default",
|
| 288 |
+
"rope_type": "default"
|
| 289 |
+
},
|
| 290 |
+
"rope_theta": 10000000,
|
| 291 |
+
"routed_scaling_factor": null,
|
| 292 |
+
"scoring_func": "sigmoid",
|
| 293 |
+
"sliding_window": 128,
|
| 294 |
+
"sliding_window_size": 128,
|
| 295 |
+
"swa_head_dim": 192,
|
| 296 |
+
"swa_num_attention_heads": 64,
|
| 297 |
+
"swa_num_key_value_heads": 8,
|
| 298 |
+
"swa_rope_theta": 10000,
|
| 299 |
+
"swa_v_head_dim": 128,
|
| 300 |
+
"tie_word_embeddings": false,
|
| 301 |
+
"topk_group": 1,
|
| 302 |
+
"topk_method": "noaux_tc",
|
| 303 |
+
"torch_dtype": "bfloat16",
|
| 304 |
+
"transformers_version": "4.40.1",
|
| 305 |
+
"use_cache": true,
|
| 306 |
+
"v_head_dim": 128,
|
| 307 |
+
"video_token_id": 151656,
|
| 308 |
+
"vision_config": {
|
| 309 |
+
"depth": 28,
|
| 310 |
+
"fullatt_block_indexes": [
|
| 311 |
+
0,
|
| 312 |
+
9,
|
| 313 |
+
18,
|
| 314 |
+
27
|
| 315 |
+
],
|
| 316 |
+
"hidden_act": "silu",
|
| 317 |
+
"hidden_size": 1280,
|
| 318 |
+
"in_chans": 3,
|
| 319 |
+
"intermediate_size": 4608,
|
| 320 |
+
"num_heads": 32,
|
| 321 |
+
"num_key_value_heads": 8,
|
| 322 |
+
"num_query_groups": 4,
|
| 323 |
+
"out_hidden_size": 4096,
|
| 324 |
+
"patch_merger_conv": false,
|
| 325 |
+
"patch_merger_linear": false,
|
| 326 |
+
"patch_size": 16,
|
| 327 |
+
"spatial_merge_size": 2,
|
| 328 |
+
"spatial_patch_size": 16,
|
| 329 |
+
"temporal_patch_size": 2,
|
| 330 |
+
"tokens_per_second": 2,
|
| 331 |
+
"use_sink": true,
|
| 332 |
+
"visual_token_window_size": 64,
|
| 333 |
+
"vit_window_attn_types": [
|
| 334 |
+
-1,
|
| 335 |
+
0,
|
| 336 |
+
0,
|
| 337 |
+
0,
|
| 338 |
+
0,
|
| 339 |
+
1,
|
| 340 |
+
1,
|
| 341 |
+
1,
|
| 342 |
+
1,
|
| 343 |
+
-1,
|
| 344 |
+
0,
|
| 345 |
+
0,
|
| 346 |
+
0,
|
| 347 |
+
0,
|
| 348 |
+
1,
|
| 349 |
+
1,
|
| 350 |
+
1,
|
| 351 |
+
1,
|
| 352 |
+
-1,
|
| 353 |
+
0,
|
| 354 |
+
0,
|
| 355 |
+
0,
|
| 356 |
+
0,
|
| 357 |
+
1,
|
| 358 |
+
1,
|
| 359 |
+
1,
|
| 360 |
+
1,
|
| 361 |
+
-1
|
| 362 |
+
],
|
| 363 |
+
"window_size": 128
|
| 364 |
+
},
|
| 365 |
+
"vision_end_token_id": 151653,
|
| 366 |
+
"vision_model_type": "mimovl",
|
| 367 |
+
"vision_start_token_id": 151652,
|
| 368 |
+
"vocab_size": 152576
|
| 369 |
+
}
|
configuration_mimo_v2.py
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
#
|
| 3 |
+
# Copyright 2026 Xiaomi Corporation.
|
| 4 |
+
# Copyright 2026 The HuggingFace Inc. team.
|
| 5 |
+
#
|
| 6 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
+
# you may not use this file except in compliance with the License.
|
| 8 |
+
# You may obtain a copy of the License at
|
| 9 |
+
#
|
| 10 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
#
|
| 12 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
# See the License for the specific language governing permissions and
|
| 16 |
+
# limitations under the License.
|
| 17 |
+
|
| 18 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 19 |
+
from transformers.modeling_rope_utils import rope_config_validation
|
| 20 |
+
from transformers.utils import logging
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
logger = logging.get_logger(__name__)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
_MIMOV2_ATTENTION_PROJECTION_LAYOUTS = {"split", "fused_qkv"}
|
| 27 |
+
|
| 28 |
+
_MIMOV2_SPLIT_TP_PLAN = {
|
| 29 |
+
"layers.*.self_attn.q_proj": "colwise",
|
| 30 |
+
"layers.*.self_attn.k_proj": "colwise",
|
| 31 |
+
"layers.*.self_attn.v_proj": "colwise",
|
| 32 |
+
"layers.*.self_attn.o_proj": "rowwise",
|
| 33 |
+
"layers.*.mlp.gate_proj": "colwise",
|
| 34 |
+
"layers.*.mlp.up_proj": "colwise",
|
| 35 |
+
"layers.*.mlp.down_proj": "rowwise",
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
_MIMOV2_FUSED_QKV_TP_PLAN = {
|
| 39 |
+
"layers.*.self_attn.qkv_proj": "colwise",
|
| 40 |
+
"layers.*.self_attn.o_proj": "rowwise",
|
| 41 |
+
"layers.*.mlp.gate_proj": "colwise",
|
| 42 |
+
"layers.*.mlp.up_proj": "colwise",
|
| 43 |
+
"layers.*.mlp.down_proj": "rowwise",
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
_MIMOV2_PP_PLAN = {
|
| 47 |
+
"embed_tokens": (["input_ids"], ["inputs_embeds"]),
|
| 48 |
+
"layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
|
| 49 |
+
"norm": (["hidden_states"], ["hidden_states"]),
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class MiMoV2Config(PretrainedConfig):
|
| 54 |
+
|
| 55 |
+
model_type = "mimo_v2"
|
| 56 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 57 |
+
|
| 58 |
+
base_model_tp_plan = _MIMOV2_SPLIT_TP_PLAN
|
| 59 |
+
base_model_pp_plan = _MIMOV2_PP_PLAN
|
| 60 |
+
|
| 61 |
+
attribute_map = {
|
| 62 |
+
"num_local_experts": "n_routed_experts",
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
def __init__(
|
| 66 |
+
self,
|
| 67 |
+
vocab_size=151936,
|
| 68 |
+
hidden_size=4096,
|
| 69 |
+
intermediate_size=22016,
|
| 70 |
+
num_hidden_layers=32,
|
| 71 |
+
num_attention_heads=32,
|
| 72 |
+
num_key_value_heads=32,
|
| 73 |
+
hidden_act="silu",
|
| 74 |
+
max_position_embeddings=32768,
|
| 75 |
+
initializer_range=0.02,
|
| 76 |
+
layernorm_epsilon=1e-6,
|
| 77 |
+
use_cache=True,
|
| 78 |
+
tie_word_embeddings=False,
|
| 79 |
+
rope_theta=10000.0,
|
| 80 |
+
rope_scaling=None,
|
| 81 |
+
attention_dropout=0.0,
|
| 82 |
+
attention_bias=False,
|
| 83 |
+
attention_value_scale=None,
|
| 84 |
+
head_dim=None,
|
| 85 |
+
v_head_dim=None,
|
| 86 |
+
swa_num_attention_heads=None,
|
| 87 |
+
swa_num_key_value_heads=None,
|
| 88 |
+
swa_head_dim=None,
|
| 89 |
+
swa_v_head_dim=None,
|
| 90 |
+
swa_rope_theta=None,
|
| 91 |
+
sliding_window=None,
|
| 92 |
+
sliding_window_size=None,
|
| 93 |
+
add_full_attention_sink_bias=False,
|
| 94 |
+
add_swa_attention_sink_bias=False,
|
| 95 |
+
hybrid_block_size=None,
|
| 96 |
+
hybrid_layer_pattern=None,
|
| 97 |
+
partial_rotary_factor=1.0,
|
| 98 |
+
n_routed_experts=None,
|
| 99 |
+
moe_intermediate_size=None,
|
| 100 |
+
num_experts_per_tok=None,
|
| 101 |
+
routed_scaling_factor=None,
|
| 102 |
+
scoring_func="sigmoid",
|
| 103 |
+
topk_method="noaux_tc",
|
| 104 |
+
n_group=None,
|
| 105 |
+
topk_group=None,
|
| 106 |
+
norm_topk_prob=True,
|
| 107 |
+
moe_layer_freq=None,
|
| 108 |
+
attention_projection_layout=None,
|
| 109 |
+
**kwargs,
|
| 110 |
+
):
|
| 111 |
+
rope_parameters = kwargs.pop("rope_parameters", None)
|
| 112 |
+
if rope_scaling is None and rope_parameters is not None:
|
| 113 |
+
rope_scaling = rope_parameters
|
| 114 |
+
|
| 115 |
+
# NOTE: DO NOT auto-fill attention_projection_layout to "split" when unset.
|
| 116 |
+
# sglang's server_args (MIMO_V2_MODEL_ARCHS branch) rejects any
|
| 117 |
+
# non-"fused_qkv" value that's explicitly present on the config; leaving
|
| 118 |
+
# the attribute absent triggers the None early-return path.
|
| 119 |
+
if attention_projection_layout is not None and attention_projection_layout not in _MIMOV2_ATTENTION_PROJECTION_LAYOUTS:
|
| 120 |
+
raise ValueError(f"Unsupported MiMoV2 attention projection layout: {attention_projection_layout}")
|
| 121 |
+
|
| 122 |
+
if attention_projection_layout is not None:
|
| 123 |
+
self.attention_projection_layout = attention_projection_layout
|
| 124 |
+
self.base_model_tp_plan = (
|
| 125 |
+
_MIMOV2_FUSED_QKV_TP_PLAN.copy()
|
| 126 |
+
if attention_projection_layout == "fused_qkv"
|
| 127 |
+
else _MIMOV2_SPLIT_TP_PLAN.copy()
|
| 128 |
+
)
|
| 129 |
+
self.base_model_pp_plan = _MIMOV2_PP_PLAN.copy()
|
| 130 |
+
|
| 131 |
+
self.vocab_size = vocab_size
|
| 132 |
+
self.max_position_embeddings = max_position_embeddings
|
| 133 |
+
self.hidden_size = hidden_size
|
| 134 |
+
self.intermediate_size = intermediate_size
|
| 135 |
+
self.num_hidden_layers = num_hidden_layers
|
| 136 |
+
self.num_attention_heads = num_attention_heads
|
| 137 |
+
|
| 138 |
+
if num_key_value_heads is None:
|
| 139 |
+
num_key_value_heads = num_attention_heads
|
| 140 |
+
if num_attention_heads % num_key_value_heads != 0:
|
| 141 |
+
raise ValueError("num_attention_heads must be divisible by num_key_value_heads")
|
| 142 |
+
|
| 143 |
+
self.num_key_value_heads = num_key_value_heads
|
| 144 |
+
self.hidden_act = hidden_act
|
| 145 |
+
self.initializer_range = initializer_range
|
| 146 |
+
self.layernorm_epsilon = layernorm_epsilon
|
| 147 |
+
self.use_cache = use_cache
|
| 148 |
+
self.rope_theta = rope_theta
|
| 149 |
+
self.rope_scaling = rope_scaling
|
| 150 |
+
self.attention_dropout = attention_dropout
|
| 151 |
+
self.attention_bias = attention_bias
|
| 152 |
+
self.attention_value_scale = attention_value_scale
|
| 153 |
+
|
| 154 |
+
self.head_dim = head_dim if head_dim is not None else hidden_size // num_attention_heads
|
| 155 |
+
self.v_head_dim = v_head_dim if v_head_dim is not None else self.head_dim
|
| 156 |
+
self.swa_num_attention_heads = (
|
| 157 |
+
swa_num_attention_heads if swa_num_attention_heads is not None else num_attention_heads
|
| 158 |
+
)
|
| 159 |
+
self.swa_num_key_value_heads = (
|
| 160 |
+
swa_num_key_value_heads if swa_num_key_value_heads is not None else num_key_value_heads
|
| 161 |
+
)
|
| 162 |
+
if self.swa_num_attention_heads % self.swa_num_key_value_heads != 0:
|
| 163 |
+
raise ValueError("swa_num_attention_heads must be divisible by swa_num_key_value_heads")
|
| 164 |
+
self.swa_head_dim = swa_head_dim if swa_head_dim is not None else self.head_dim
|
| 165 |
+
self.swa_v_head_dim = swa_v_head_dim if swa_v_head_dim is not None else self.swa_head_dim
|
| 166 |
+
self.swa_rope_theta = swa_rope_theta if swa_rope_theta is not None else rope_theta
|
| 167 |
+
|
| 168 |
+
if sliding_window is None:
|
| 169 |
+
sliding_window = sliding_window_size
|
| 170 |
+
self.sliding_window = sliding_window
|
| 171 |
+
self.sliding_window_size = sliding_window_size if sliding_window_size is not None else sliding_window
|
| 172 |
+
self.add_full_attention_sink_bias = add_full_attention_sink_bias
|
| 173 |
+
self.add_swa_attention_sink_bias = add_swa_attention_sink_bias
|
| 174 |
+
|
| 175 |
+
if hybrid_block_size is not None and hybrid_layer_pattern is None:
|
| 176 |
+
hybrid_layer_pattern = [0 if ((i + 1) % hybrid_block_size == 0) else 1 for i in range(num_hidden_layers)]
|
| 177 |
+
elif hybrid_layer_pattern is None:
|
| 178 |
+
hybrid_layer_pattern = [0] * num_hidden_layers
|
| 179 |
+
if len(hybrid_layer_pattern) != num_hidden_layers:
|
| 180 |
+
raise ValueError("hybrid_layer_pattern length must match num_hidden_layers")
|
| 181 |
+
self.hybrid_block_size = hybrid_block_size
|
| 182 |
+
self.hybrid_layer_pattern = hybrid_layer_pattern
|
| 183 |
+
|
| 184 |
+
self.partial_rotary_factor = partial_rotary_factor
|
| 185 |
+
|
| 186 |
+
self.n_routed_experts = n_routed_experts
|
| 187 |
+
self.moe_intermediate_size = moe_intermediate_size if moe_intermediate_size is not None else intermediate_size
|
| 188 |
+
self.num_experts_per_tok = num_experts_per_tok
|
| 189 |
+
self.routed_scaling_factor = routed_scaling_factor
|
| 190 |
+
self.scoring_func = scoring_func
|
| 191 |
+
self.topk_method = topk_method
|
| 192 |
+
self.n_group = n_group
|
| 193 |
+
self.topk_group = topk_group
|
| 194 |
+
self.norm_topk_prob = norm_topk_prob
|
| 195 |
+
if isinstance(moe_layer_freq, int):
|
| 196 |
+
moe_layer_freq = [moe_layer_freq > 0 and i % moe_layer_freq == 0 for i in range(num_hidden_layers)]
|
| 197 |
+
elif moe_layer_freq is None:
|
| 198 |
+
moe_layer_freq = [False] * num_hidden_layers
|
| 199 |
+
if len(moe_layer_freq) != num_hidden_layers:
|
| 200 |
+
raise ValueError("moe_layer_freq length must match num_hidden_layers")
|
| 201 |
+
self.moe_layer_freq = moe_layer_freq
|
| 202 |
+
|
| 203 |
+
if self.rope_scaling is not None and "type" in self.rope_scaling:
|
| 204 |
+
self.rope_scaling["rope_type"] = self.rope_scaling["type"]
|
| 205 |
+
rope_config_validation(self)
|
| 206 |
+
|
| 207 |
+
super().__init__(
|
| 208 |
+
tie_word_embeddings=tie_word_embeddings,
|
| 209 |
+
**kwargs,
|
| 210 |
+
)
|
| 211 |
+
|
| 212 |
+
__all__ = ["MiMoV2Config"]
|
dflash/config.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"DFlashDraftModel"
|
| 4 |
+
],
|
| 5 |
+
"model_type": "qwen3",
|
| 6 |
+
"auto_map": {
|
| 7 |
+
"AutoModel": "dflash.DFlashDraftModel"
|
| 8 |
+
},
|
| 9 |
+
"hidden_size": 4096,
|
| 10 |
+
"intermediate_size": 16384,
|
| 11 |
+
"num_hidden_layers": 5,
|
| 12 |
+
"num_attention_heads": 64,
|
| 13 |
+
"num_key_value_heads": 8,
|
| 14 |
+
"head_dim": 128,
|
| 15 |
+
"v_head_dim": 128,
|
| 16 |
+
"partial_rotary_factor": 0.5,
|
| 17 |
+
"block_size": 8,
|
| 18 |
+
"dflash_config": {
|
| 19 |
+
"target_layer_ids": [
|
| 20 |
+
0,
|
| 21 |
+
11,
|
| 22 |
+
23,
|
| 23 |
+
35,
|
| 24 |
+
47
|
| 25 |
+
],
|
| 26 |
+
"mask_token_id": 151675,
|
| 27 |
+
"num_anchors": 4096,
|
| 28 |
+
"block_size": 8,
|
| 29 |
+
"loss_decay_gamma": 7.0,
|
| 30 |
+
"use_swa": true,
|
| 31 |
+
"swa_window_size": 1024,
|
| 32 |
+
"backbone_rotary_base": 5000000,
|
| 33 |
+
"attention_value_scale": 0.612,
|
| 34 |
+
"attention_sink_bias": true
|
| 35 |
+
},
|
| 36 |
+
"num_target_layers": 48,
|
| 37 |
+
"vocab_size": 152576,
|
| 38 |
+
"max_position_embeddings": 262144,
|
| 39 |
+
"rope_theta": 10000,
|
| 40 |
+
"sliding_window": 1024,
|
| 41 |
+
"rms_norm_eps": 1e-06,
|
| 42 |
+
"torch_dtype": "bfloat16",
|
| 43 |
+
"hidden_act": "silu",
|
| 44 |
+
"attention_bias": false,
|
| 45 |
+
"attention_dropout": 0.0,
|
| 46 |
+
"tie_word_embeddings": false,
|
| 47 |
+
"use_cache": true
|
| 48 |
+
}
|
dflash/dflash.py
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Callable, Optional
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
from torch import nn
|
| 5 |
+
from transformers import DynamicCache
|
| 6 |
+
from transformers.cache_utils import Cache
|
| 7 |
+
from transformers.modeling_outputs import CausalLMOutputWithPast
|
| 8 |
+
from transformers.models.qwen3.modeling_qwen3 import (
|
| 9 |
+
ALL_ATTENTION_FUNCTIONS,
|
| 10 |
+
FlashAttentionKwargs,
|
| 11 |
+
GradientCheckpointingLayer,
|
| 12 |
+
Qwen3Config,
|
| 13 |
+
Qwen3MLP,
|
| 14 |
+
Qwen3PreTrainedModel,
|
| 15 |
+
Qwen3RMSNorm,
|
| 16 |
+
Qwen3RotaryEmbedding,
|
| 17 |
+
eager_attention_forward,
|
| 18 |
+
rotate_half,
|
| 19 |
+
)
|
| 20 |
+
from typing_extensions import Tuple, Unpack
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def sample(logits: torch.Tensor, temperature: float = 0.0) -> torch.Tensor:
|
| 24 |
+
if temperature < 1e-5:
|
| 25 |
+
return torch.argmax(logits, dim=-1)
|
| 26 |
+
bsz, seq_len, vocab_size = logits.shape
|
| 27 |
+
logits = logits.view(-1, vocab_size)
|
| 28 |
+
logits = logits / temperature
|
| 29 |
+
probs = torch.softmax(logits, dim=-1)
|
| 30 |
+
return torch.multinomial(probs, num_samples=1).view(bsz, seq_len)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
|
| 34 |
+
cos = cos.unsqueeze(unsqueeze_dim)
|
| 35 |
+
sin = sin.unsqueeze(unsqueeze_dim)
|
| 36 |
+
q_len = q.size(-2)
|
| 37 |
+
q_embed = (q * cos[..., -q_len:, :]) + (rotate_half(q) * sin[..., -q_len:, :])
|
| 38 |
+
k_embed = (k * cos) + (rotate_half(k) * sin)
|
| 39 |
+
return q_embed, k_embed
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class Qwen3DFlashAttention(nn.Module):
|
| 43 |
+
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
| 44 |
+
|
| 45 |
+
def __init__(self, config: Qwen3Config, layer_idx: int):
|
| 46 |
+
super().__init__()
|
| 47 |
+
self.config = config
|
| 48 |
+
self.layer_idx = layer_idx
|
| 49 |
+
self.head_dim = getattr(
|
| 50 |
+
config, "head_dim", config.hidden_size // config.num_attention_heads
|
| 51 |
+
)
|
| 52 |
+
self.num_key_value_groups = (
|
| 53 |
+
config.num_attention_heads // config.num_key_value_heads
|
| 54 |
+
)
|
| 55 |
+
self.scaling = self.head_dim**-0.5
|
| 56 |
+
self.attention_dropout = config.attention_dropout
|
| 57 |
+
self.is_causal = False
|
| 58 |
+
self.q_proj = nn.Linear(
|
| 59 |
+
config.hidden_size,
|
| 60 |
+
config.num_attention_heads * self.head_dim,
|
| 61 |
+
bias=config.attention_bias,
|
| 62 |
+
)
|
| 63 |
+
self.k_proj = nn.Linear(
|
| 64 |
+
config.hidden_size,
|
| 65 |
+
config.num_key_value_heads * self.head_dim,
|
| 66 |
+
bias=config.attention_bias,
|
| 67 |
+
)
|
| 68 |
+
self.v_proj = nn.Linear(
|
| 69 |
+
config.hidden_size,
|
| 70 |
+
config.num_key_value_heads * self.head_dim,
|
| 71 |
+
bias=config.attention_bias,
|
| 72 |
+
)
|
| 73 |
+
self.o_proj = nn.Linear(
|
| 74 |
+
config.num_attention_heads * self.head_dim,
|
| 75 |
+
config.hidden_size,
|
| 76 |
+
bias=config.attention_bias,
|
| 77 |
+
)
|
| 78 |
+
self.q_norm = Qwen3RMSNorm(self.head_dim, eps=config.rms_norm_eps)
|
| 79 |
+
self.k_norm = Qwen3RMSNorm(self.head_dim, eps=config.rms_norm_eps)
|
| 80 |
+
self.sliding_window = (
|
| 81 |
+
config.sliding_window
|
| 82 |
+
if config.layer_types[layer_idx] == "sliding_attention"
|
| 83 |
+
else None
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
def forward(
|
| 87 |
+
self,
|
| 88 |
+
hidden_states: torch.Tensor,
|
| 89 |
+
target_hidden: torch.Tensor,
|
| 90 |
+
position_embeddings: tuple[torch.Tensor, torch.Tensor],
|
| 91 |
+
attention_mask: Optional[torch.Tensor],
|
| 92 |
+
past_key_values: Optional[Cache] = None,
|
| 93 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 94 |
+
**kwargs: Unpack[FlashAttentionKwargs],
|
| 95 |
+
) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
|
| 96 |
+
bsz, q_len = hidden_states.shape[:-1]
|
| 97 |
+
ctx_len = target_hidden.shape[1]
|
| 98 |
+
q = self.q_proj(hidden_states)
|
| 99 |
+
q = q.view(bsz, q_len, -1, self.head_dim)
|
| 100 |
+
q = self.q_norm(q).transpose(1, 2)
|
| 101 |
+
k_ctx = self.k_proj(target_hidden)
|
| 102 |
+
k_noise = self.k_proj(hidden_states)
|
| 103 |
+
v_ctx = self.v_proj(target_hidden)
|
| 104 |
+
v_noise = self.v_proj(hidden_states)
|
| 105 |
+
k = torch.cat([k_ctx, k_noise], dim=1).view(
|
| 106 |
+
bsz, ctx_len + q_len, -1, self.head_dim
|
| 107 |
+
)
|
| 108 |
+
v = torch.cat([v_ctx, v_noise], dim=1).view(
|
| 109 |
+
bsz, ctx_len + q_len, -1, self.head_dim
|
| 110 |
+
)
|
| 111 |
+
k = self.k_norm(k).transpose(1, 2)
|
| 112 |
+
v = v.transpose(1, 2)
|
| 113 |
+
cos, sin = position_embeddings
|
| 114 |
+
q, k = apply_rotary_pos_emb(q, k, cos, sin)
|
| 115 |
+
if past_key_values is not None:
|
| 116 |
+
cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
|
| 117 |
+
k, v = past_key_values.update(k, v, self.layer_idx, cache_kwargs)
|
| 118 |
+
attn_fn: Callable = eager_attention_forward
|
| 119 |
+
if self.config._attn_implementation != "eager":
|
| 120 |
+
attn_fn = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation]
|
| 121 |
+
attn_output, attn_weights = attn_fn(
|
| 122 |
+
self,
|
| 123 |
+
q,
|
| 124 |
+
k,
|
| 125 |
+
v,
|
| 126 |
+
attention_mask,
|
| 127 |
+
dropout=0.0 if not self.training else self.attention_dropout,
|
| 128 |
+
scaling=self.scaling,
|
| 129 |
+
sliding_window=self.sliding_window,
|
| 130 |
+
**kwargs,
|
| 131 |
+
)
|
| 132 |
+
attn_output = attn_output.reshape(bsz, q_len, -1)
|
| 133 |
+
attn_output = self.o_proj(attn_output)
|
| 134 |
+
return attn_output, attn_weights
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
class Qwen3DFlashDecoderLayer(GradientCheckpointingLayer):
|
| 138 |
+
def __init__(self, config: Qwen3Config, layer_idx: int):
|
| 139 |
+
super().__init__()
|
| 140 |
+
self.hidden_size = config.hidden_size
|
| 141 |
+
self.self_attn = Qwen3DFlashAttention(config=config, layer_idx=layer_idx)
|
| 142 |
+
self.mlp = Qwen3MLP(config)
|
| 143 |
+
self.input_layernorm = Qwen3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 144 |
+
self.post_attention_layernorm = Qwen3RMSNorm(
|
| 145 |
+
config.hidden_size, eps=config.rms_norm_eps
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
def forward(
|
| 149 |
+
self,
|
| 150 |
+
target_hidden: Optional[torch.Tensor] = None,
|
| 151 |
+
hidden_states: Optional[torch.Tensor] = None,
|
| 152 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 153 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 154 |
+
past_key_value: Optional[Cache] = None,
|
| 155 |
+
output_attentions: Optional[bool] = False,
|
| 156 |
+
use_cache: Optional[bool] = False,
|
| 157 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 158 |
+
position_embeddings: Optional[
|
| 159 |
+
Tuple[torch.Tensor, torch.Tensor]
|
| 160 |
+
] = None, # necessary, but kept here for BC
|
| 161 |
+
**kwargs: Unpack[FlashAttentionKwargs],
|
| 162 |
+
) -> Tuple[
|
| 163 |
+
torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]
|
| 164 |
+
]:
|
| 165 |
+
residual = hidden_states
|
| 166 |
+
hidden_states = self.input_layernorm(hidden_states)
|
| 167 |
+
hidden_states = self.self_attn(
|
| 168 |
+
hidden_states=hidden_states,
|
| 169 |
+
target_hidden=target_hidden,
|
| 170 |
+
attention_mask=attention_mask,
|
| 171 |
+
position_ids=position_ids,
|
| 172 |
+
past_key_values=past_key_value,
|
| 173 |
+
output_attentions=output_attentions,
|
| 174 |
+
use_cache=use_cache,
|
| 175 |
+
cache_position=cache_position,
|
| 176 |
+
position_embeddings=position_embeddings,
|
| 177 |
+
**kwargs,
|
| 178 |
+
)[0]
|
| 179 |
+
hidden_states = residual + hidden_states
|
| 180 |
+
residual = hidden_states
|
| 181 |
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
| 182 |
+
hidden_states = self.mlp(hidden_states)
|
| 183 |
+
hidden_states = residual + hidden_states
|
| 184 |
+
return hidden_states
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def build_target_layer_ids(num_target_layers: int, num_draft_layers: int):
|
| 188 |
+
if num_draft_layers == 1:
|
| 189 |
+
return [(num_target_layers // 2)]
|
| 190 |
+
start = 1
|
| 191 |
+
end = num_target_layers - 3
|
| 192 |
+
span = end - start
|
| 193 |
+
target_layer_ids = [
|
| 194 |
+
int(round(start + (i * span) / (num_draft_layers - 1)))
|
| 195 |
+
for i in range(num_draft_layers)
|
| 196 |
+
]
|
| 197 |
+
return target_layer_ids
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def extract_context_feature(
|
| 201 |
+
hidden_states: list[torch.Tensor],
|
| 202 |
+
layer_ids: Optional[list[int]],
|
| 203 |
+
) -> torch.Tensor:
|
| 204 |
+
offset = 1
|
| 205 |
+
selected_states = []
|
| 206 |
+
for layer_id in layer_ids:
|
| 207 |
+
selected_states.append(hidden_states[layer_id + offset])
|
| 208 |
+
target_hidden = torch.cat(selected_states, dim=-1)
|
| 209 |
+
return target_hidden
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
class DFlashDraftModel(Qwen3PreTrainedModel):
|
| 213 |
+
config_class = Qwen3Config
|
| 214 |
+
_no_split_modules = ["Qwen3DFlashDecoderLayer"]
|
| 215 |
+
|
| 216 |
+
def __init__(self, config) -> None:
|
| 217 |
+
super().__init__(config)
|
| 218 |
+
self.config = config
|
| 219 |
+
self.layers = nn.ModuleList(
|
| 220 |
+
[
|
| 221 |
+
Qwen3DFlashDecoderLayer(config, layer_idx)
|
| 222 |
+
for layer_idx in range(config.num_hidden_layers)
|
| 223 |
+
]
|
| 224 |
+
)
|
| 225 |
+
dflash_config = getattr(config, "dflash_config", {}) or {}
|
| 226 |
+
self.target_layer_ids = dflash_config.get(
|
| 227 |
+
"target_layer_ids",
|
| 228 |
+
build_target_layer_ids(config.num_target_layers, config.num_hidden_layers),
|
| 229 |
+
)
|
| 230 |
+
self.norm = Qwen3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 231 |
+
self.rotary_emb = Qwen3RotaryEmbedding(config)
|
| 232 |
+
self.fc = nn.Linear(
|
| 233 |
+
len(self.target_layer_ids) * config.hidden_size,
|
| 234 |
+
config.hidden_size,
|
| 235 |
+
bias=False,
|
| 236 |
+
)
|
| 237 |
+
self.hidden_norm = Qwen3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 238 |
+
self.block_size = config.block_size
|
| 239 |
+
self.mask_token_id = dflash_config.get("mask_token_id", None)
|
| 240 |
+
self.post_init()
|
| 241 |
+
|
| 242 |
+
def forward(
|
| 243 |
+
self,
|
| 244 |
+
position_ids: torch.LongTensor,
|
| 245 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 246 |
+
noise_embedding: Optional[torch.Tensor] = None,
|
| 247 |
+
target_hidden: Optional[torch.Tensor] = None,
|
| 248 |
+
past_key_values: Optional[Cache] = None,
|
| 249 |
+
use_cache: bool = False,
|
| 250 |
+
**kwargs,
|
| 251 |
+
) -> CausalLMOutputWithPast:
|
| 252 |
+
hidden_states = noise_embedding
|
| 253 |
+
target_hidden = self.hidden_norm(self.fc(target_hidden))
|
| 254 |
+
position_embeddings = self.rotary_emb(hidden_states, position_ids)
|
| 255 |
+
for layer in self.layers:
|
| 256 |
+
hidden_states = layer(
|
| 257 |
+
hidden_states=hidden_states,
|
| 258 |
+
target_hidden=target_hidden,
|
| 259 |
+
attention_mask=attention_mask,
|
| 260 |
+
position_ids=position_ids,
|
| 261 |
+
past_key_value=past_key_values,
|
| 262 |
+
use_cache=use_cache,
|
| 263 |
+
position_embeddings=position_embeddings,
|
| 264 |
+
**kwargs,
|
| 265 |
+
)
|
| 266 |
+
return self.norm(hidden_states)
|
| 267 |
+
|
| 268 |
+
@torch.inference_mode()
|
| 269 |
+
def spec_generate(
|
| 270 |
+
self,
|
| 271 |
+
target: nn.Module,
|
| 272 |
+
input_ids: torch.LongTensor,
|
| 273 |
+
max_new_tokens: int,
|
| 274 |
+
stop_token_ids: list[int],
|
| 275 |
+
temperature: float,
|
| 276 |
+
):
|
| 277 |
+
self.eval()
|
| 278 |
+
num_input_tokens = input_ids.shape[1]
|
| 279 |
+
max_length = num_input_tokens + max_new_tokens
|
| 280 |
+
|
| 281 |
+
block_size = self.block_size
|
| 282 |
+
output_ids = torch.full(
|
| 283 |
+
(1, max_length + block_size),
|
| 284 |
+
self.mask_token_id,
|
| 285 |
+
dtype=torch.long,
|
| 286 |
+
device=target.device,
|
| 287 |
+
)
|
| 288 |
+
position_ids = torch.arange(
|
| 289 |
+
output_ids.shape[1], device=target.device
|
| 290 |
+
).unsqueeze(0)
|
| 291 |
+
|
| 292 |
+
past_key_values_target = DynamicCache()
|
| 293 |
+
past_key_values_draft = DynamicCache()
|
| 294 |
+
|
| 295 |
+
# Prefill stage
|
| 296 |
+
output = target(
|
| 297 |
+
input_ids,
|
| 298 |
+
position_ids=position_ids[:, :num_input_tokens],
|
| 299 |
+
past_key_values=past_key_values_target,
|
| 300 |
+
use_cache=True,
|
| 301 |
+
logits_to_keep=1,
|
| 302 |
+
output_hidden_states=True,
|
| 303 |
+
)
|
| 304 |
+
|
| 305 |
+
output_ids[:, :num_input_tokens] = input_ids
|
| 306 |
+
output_ids[:, num_input_tokens : num_input_tokens + 1] = sample(
|
| 307 |
+
output.logits, temperature
|
| 308 |
+
)
|
| 309 |
+
target_hidden = extract_context_feature(
|
| 310 |
+
output.hidden_states, self.target_layer_ids
|
| 311 |
+
)
|
| 312 |
+
|
| 313 |
+
# Decode stage
|
| 314 |
+
acceptance_lengths = []
|
| 315 |
+
start = input_ids.shape[1]
|
| 316 |
+
while start < max_length:
|
| 317 |
+
block_output_ids = output_ids[:, start : start + block_size].clone()
|
| 318 |
+
block_position_ids = position_ids[:, start : start + block_size]
|
| 319 |
+
noise_embedding = target.model.embed_tokens(block_output_ids)
|
| 320 |
+
draft_logits = target.lm_head(
|
| 321 |
+
self(
|
| 322 |
+
target_hidden=target_hidden,
|
| 323 |
+
noise_embedding=noise_embedding,
|
| 324 |
+
position_ids=position_ids[
|
| 325 |
+
:, past_key_values_draft.get_seq_length() : start + block_size
|
| 326 |
+
],
|
| 327 |
+
past_key_values=past_key_values_draft,
|
| 328 |
+
use_cache=True,
|
| 329 |
+
is_causal=False,
|
| 330 |
+
)[:, -block_size + 1 :, :]
|
| 331 |
+
)
|
| 332 |
+
past_key_values_draft.crop(start)
|
| 333 |
+
block_output_ids[:, 1:] = sample(draft_logits)
|
| 334 |
+
|
| 335 |
+
output = target(
|
| 336 |
+
block_output_ids,
|
| 337 |
+
position_ids=block_position_ids,
|
| 338 |
+
past_key_values=past_key_values_target,
|
| 339 |
+
use_cache=True,
|
| 340 |
+
output_hidden_states=True,
|
| 341 |
+
)
|
| 342 |
+
|
| 343 |
+
posterior = sample(output.logits, temperature)
|
| 344 |
+
acceptance_length = (
|
| 345 |
+
(block_output_ids[:, 1:] == posterior[:, :-1])
|
| 346 |
+
.cumprod(dim=1)
|
| 347 |
+
.sum(dim=1)[0]
|
| 348 |
+
.item()
|
| 349 |
+
)
|
| 350 |
+
output_ids[:, start : start + acceptance_length + 1] = block_output_ids[
|
| 351 |
+
:, : acceptance_length + 1
|
| 352 |
+
]
|
| 353 |
+
output_ids[:, start + acceptance_length + 1] = posterior[
|
| 354 |
+
:, acceptance_length
|
| 355 |
+
]
|
| 356 |
+
start += acceptance_length + 1
|
| 357 |
+
past_key_values_target.crop(start)
|
| 358 |
+
target_hidden = extract_context_feature(
|
| 359 |
+
output.hidden_states, self.target_layer_ids
|
| 360 |
+
)[:, : acceptance_length + 1, :]
|
| 361 |
+
acceptance_lengths.append(acceptance_length + 1)
|
| 362 |
+
if stop_token_ids is not None and any(
|
| 363 |
+
stop_token_id in output_ids[:, num_input_tokens:]
|
| 364 |
+
for stop_token_id in stop_token_ids
|
| 365 |
+
):
|
| 366 |
+
break
|
| 367 |
+
output_ids = output_ids[:, :max_length]
|
| 368 |
+
output_ids = output_ids[:, output_ids[0] != self.mask_token_id]
|
| 369 |
+
if stop_token_ids is not None:
|
| 370 |
+
stop_token_ids = torch.tensor(stop_token_ids, device=output_ids.device)
|
| 371 |
+
stop_token_indices = torch.isin(
|
| 372 |
+
output_ids[0][num_input_tokens:], stop_token_ids
|
| 373 |
+
).nonzero(as_tuple=True)[0]
|
| 374 |
+
if stop_token_indices.numel() > 0:
|
| 375 |
+
output_ids = output_ids[
|
| 376 |
+
:, : num_input_tokens + stop_token_indices[0] + 1
|
| 377 |
+
]
|
| 378 |
+
|
| 379 |
+
return output_ids
|
dflash/done_mtp
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
1
|
dflash/mask_embedding.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a982aea3bb45e78bbe59bd3d624cfbc3f1261958e0f466e64f14b9e22377b724
|
| 3 |
+
size 9882
|
dflash/model.safetensors.index.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"metadata": {
|
| 3 |
+
"total_size": 2936114304
|
| 4 |
+
},
|
| 5 |
+
"weight_map": {
|
| 6 |
+
"fc.weight": "dflash_draft_model.safetensors",
|
| 7 |
+
"hidden_norm.weight": "dflash_draft_model.safetensors",
|
| 8 |
+
"norm.weight": "dflash_draft_model.safetensors",
|
| 9 |
+
"layers.0.input_layernorm.weight": "dflash_draft_model.safetensors",
|
| 10 |
+
"layers.0.post_attention_layernorm.weight": "dflash_draft_model.safetensors",
|
| 11 |
+
"layers.0.self_attn.q_proj.weight": "dflash_draft_model.safetensors",
|
| 12 |
+
"layers.0.self_attn.k_proj.weight": "dflash_draft_model.safetensors",
|
| 13 |
+
"layers.0.self_attn.v_proj.weight": "dflash_draft_model.safetensors",
|
| 14 |
+
"layers.0.self_attn.o_proj.weight": "dflash_draft_model.safetensors",
|
| 15 |
+
"layers.0.self_attn.q_norm.weight": "dflash_draft_model.safetensors",
|
| 16 |
+
"layers.0.self_attn.k_norm.weight": "dflash_draft_model.safetensors",
|
| 17 |
+
"layers.0.self_attn.attention_sink_bias": "dflash_draft_model.safetensors",
|
| 18 |
+
"layers.0.mlp.gate_proj.weight": "dflash_draft_model.safetensors",
|
| 19 |
+
"layers.0.mlp.up_proj.weight": "dflash_draft_model.safetensors",
|
| 20 |
+
"layers.0.mlp.down_proj.weight": "dflash_draft_model.safetensors",
|
| 21 |
+
"layers.1.input_layernorm.weight": "dflash_draft_model.safetensors",
|
| 22 |
+
"layers.1.post_attention_layernorm.weight": "dflash_draft_model.safetensors",
|
| 23 |
+
"layers.1.self_attn.q_proj.weight": "dflash_draft_model.safetensors",
|
| 24 |
+
"layers.1.self_attn.k_proj.weight": "dflash_draft_model.safetensors",
|
| 25 |
+
"layers.1.self_attn.v_proj.weight": "dflash_draft_model.safetensors",
|
| 26 |
+
"layers.1.self_attn.o_proj.weight": "dflash_draft_model.safetensors",
|
| 27 |
+
"layers.1.self_attn.q_norm.weight": "dflash_draft_model.safetensors",
|
| 28 |
+
"layers.1.self_attn.k_norm.weight": "dflash_draft_model.safetensors",
|
| 29 |
+
"layers.1.self_attn.attention_sink_bias": "dflash_draft_model.safetensors",
|
| 30 |
+
"layers.1.mlp.gate_proj.weight": "dflash_draft_model.safetensors",
|
| 31 |
+
"layers.1.mlp.up_proj.weight": "dflash_draft_model.safetensors",
|
| 32 |
+
"layers.1.mlp.down_proj.weight": "dflash_draft_model.safetensors",
|
| 33 |
+
"layers.2.input_layernorm.weight": "dflash_draft_model.safetensors",
|
| 34 |
+
"layers.2.post_attention_layernorm.weight": "dflash_draft_model.safetensors",
|
| 35 |
+
"layers.2.self_attn.q_proj.weight": "dflash_draft_model.safetensors",
|
| 36 |
+
"layers.2.self_attn.k_proj.weight": "dflash_draft_model.safetensors",
|
| 37 |
+
"layers.2.self_attn.v_proj.weight": "dflash_draft_model.safetensors",
|
| 38 |
+
"layers.2.self_attn.o_proj.weight": "dflash_draft_model.safetensors",
|
| 39 |
+
"layers.2.self_attn.q_norm.weight": "dflash_draft_model.safetensors",
|
| 40 |
+
"layers.2.self_attn.k_norm.weight": "dflash_draft_model.safetensors",
|
| 41 |
+
"layers.2.self_attn.attention_sink_bias": "dflash_draft_model.safetensors",
|
| 42 |
+
"layers.2.mlp.gate_proj.weight": "dflash_draft_model.safetensors",
|
| 43 |
+
"layers.2.mlp.up_proj.weight": "dflash_draft_model.safetensors",
|
| 44 |
+
"layers.2.mlp.down_proj.weight": "dflash_draft_model.safetensors",
|
| 45 |
+
"layers.3.input_layernorm.weight": "dflash_draft_model.safetensors",
|
| 46 |
+
"layers.3.post_attention_layernorm.weight": "dflash_draft_model.safetensors",
|
| 47 |
+
"layers.3.self_attn.q_proj.weight": "dflash_draft_model.safetensors",
|
| 48 |
+
"layers.3.self_attn.k_proj.weight": "dflash_draft_model.safetensors",
|
| 49 |
+
"layers.3.self_attn.v_proj.weight": "dflash_draft_model.safetensors",
|
| 50 |
+
"layers.3.self_attn.o_proj.weight": "dflash_draft_model.safetensors",
|
| 51 |
+
"layers.3.self_attn.q_norm.weight": "dflash_draft_model.safetensors",
|
| 52 |
+
"layers.3.self_attn.k_norm.weight": "dflash_draft_model.safetensors",
|
| 53 |
+
"layers.3.self_attn.attention_sink_bias": "dflash_draft_model.safetensors",
|
| 54 |
+
"layers.3.mlp.gate_proj.weight": "dflash_draft_model.safetensors",
|
| 55 |
+
"layers.3.mlp.up_proj.weight": "dflash_draft_model.safetensors",
|
| 56 |
+
"layers.3.mlp.down_proj.weight": "dflash_draft_model.safetensors",
|
| 57 |
+
"layers.4.input_layernorm.weight": "dflash_draft_model.safetensors",
|
| 58 |
+
"layers.4.post_attention_layernorm.weight": "dflash_draft_model.safetensors",
|
| 59 |
+
"layers.4.self_attn.q_proj.weight": "dflash_draft_model.safetensors",
|
| 60 |
+
"layers.4.self_attn.k_proj.weight": "dflash_draft_model.safetensors",
|
| 61 |
+
"layers.4.self_attn.v_proj.weight": "dflash_draft_model.safetensors",
|
| 62 |
+
"layers.4.self_attn.o_proj.weight": "dflash_draft_model.safetensors",
|
| 63 |
+
"layers.4.self_attn.q_norm.weight": "dflash_draft_model.safetensors",
|
| 64 |
+
"layers.4.self_attn.k_norm.weight": "dflash_draft_model.safetensors",
|
| 65 |
+
"layers.4.self_attn.attention_sink_bias": "dflash_draft_model.safetensors",
|
| 66 |
+
"layers.4.mlp.gate_proj.weight": "dflash_draft_model.safetensors",
|
| 67 |
+
"layers.4.mlp.up_proj.weight": "dflash_draft_model.safetensors",
|
| 68 |
+
"layers.4.mlp.down_proj.weight": "dflash_draft_model.safetensors"
|
| 69 |
+
}
|
| 70 |
+
}
|
generation_config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token_id": 151643,
|
| 3 |
+
"do_sample": false,
|
| 4 |
+
"eos_token_id": [151643, 151645, 151672],
|
| 5 |
+
"temperature": 1.0,
|
| 6 |
+
"top_p": 0.95,
|
| 7 |
+
"max_new_tokens": 2048,
|
| 8 |
+
"transformers_version": "4.37.0"
|
| 9 |
+
}
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model.safetensors.index.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
preprocessor_config.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"min_pixels": 3136,
|
| 3 |
+
"max_pixels": 12845056,
|
| 4 |
+
"patch_size": 16,
|
| 5 |
+
"temporal_patch_size": 2,
|
| 6 |
+
"merge_size": 2,
|
| 7 |
+
"image_mean": [
|
| 8 |
+
0.48145466,
|
| 9 |
+
0.4578275,
|
| 10 |
+
0.40821073
|
| 11 |
+
],
|
| 12 |
+
"image_std": [
|
| 13 |
+
0.26862954,
|
| 14 |
+
0.26130258,
|
| 15 |
+
0.27577711
|
| 16 |
+
],
|
| 17 |
+
"image_processor_type": "Qwen2VLImageProcessor",
|
| 18 |
+
"processor_class": "Qwen2_5_VLProcessor"
|
| 19 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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token": false,
|
| 3 |
+
"add_prefix_space": false,
|
| 4 |
+
"added_tokens_decoder": {
|
| 5 |
+
"151643": {
|
| 6 |
+
"content": "<|endoftext|>",
|
| 7 |
+
"lstrip": false,
|
| 8 |
+
"normalized": false,
|
| 9 |
+
"rstrip": false,
|
| 10 |
+
"single_word": false,
|
| 11 |
+
"special": true
|
| 12 |
+
},
|
| 13 |
+
"151644": {
|
| 14 |
+
"content": "<|im_start|>",
|
| 15 |
+
"lstrip": false,
|
| 16 |
+
"normalized": false,
|
| 17 |
+
"rstrip": false,
|
| 18 |
+
"single_word": false,
|
| 19 |
+
"special": true
|
| 20 |
+
},
|
| 21 |
+
"151645": {
|
| 22 |
+
"content": "<|im_end|>",
|
| 23 |
+
"lstrip": false,
|
| 24 |
+
"normalized": false,
|
| 25 |
+
"rstrip": false,
|
| 26 |
+
"single_word": false,
|
| 27 |
+
"special": true
|
| 28 |
+
},
|
| 29 |
+
"151646": {
|
| 30 |
+
"content": "<|object_ref_start|>",
|
| 31 |
+
"lstrip": false,
|
| 32 |
+
"normalized": false,
|
| 33 |
+
"rstrip": false,
|
| 34 |
+
"single_word": false,
|
| 35 |
+
"special": true
|
| 36 |
+
},
|
| 37 |
+
"151647": {
|
| 38 |
+
"content": "<|object_ref_end|>",
|
| 39 |
+
"lstrip": false,
|
| 40 |
+
"normalized": false,
|
| 41 |
+
"rstrip": false,
|
| 42 |
+
"single_word": false,
|
| 43 |
+
"special": true
|
| 44 |
+
},
|
| 45 |
+
"151648": {
|
| 46 |
+
"content": "<|box_start|>",
|
| 47 |
+
"lstrip": false,
|
| 48 |
+
"normalized": false,
|
| 49 |
+
"rstrip": false,
|
| 50 |
+
"single_word": false,
|
| 51 |
+
"special": true
|
| 52 |
+
},
|
| 53 |
+
"151649": {
|
| 54 |
+
"content": "<|box_end|>",
|
| 55 |
+
"lstrip": false,
|
| 56 |
+
"normalized": false,
|
| 57 |
+
"rstrip": false,
|
| 58 |
+
"single_word": false,
|
| 59 |
+
"special": true
|
| 60 |
+
},
|
| 61 |
+
"151650": {
|
| 62 |
+
"content": "<|quad_start|>",
|
| 63 |
+
"lstrip": false,
|
| 64 |
+
"normalized": false,
|
| 65 |
+
"rstrip": false,
|
| 66 |
+
"single_word": false,
|
| 67 |
+
"special": true
|
| 68 |
+
},
|
| 69 |
+
"151651": {
|
| 70 |
+
"content": "<|quad_end|>",
|
| 71 |
+
"lstrip": false,
|
| 72 |
+
"normalized": false,
|
| 73 |
+
"rstrip": false,
|
| 74 |
+
"single_word": false,
|
| 75 |
+
"special": true
|
| 76 |
+
},
|
| 77 |
+
"151652": {
|
| 78 |
+
"content": "<|vision_start|>",
|
| 79 |
+
"lstrip": false,
|
| 80 |
+
"normalized": false,
|
| 81 |
+
"rstrip": false,
|
| 82 |
+
"single_word": false,
|
| 83 |
+
"special": true
|
| 84 |
+
},
|
| 85 |
+
"151653": {
|
| 86 |
+
"content": "<|vision_end|>",
|
| 87 |
+
"lstrip": false,
|
| 88 |
+
"normalized": false,
|
| 89 |
+
"rstrip": false,
|
| 90 |
+
"single_word": false,
|
| 91 |
+
"special": true
|
| 92 |
+
},
|
| 93 |
+
"151654": {
|
| 94 |
+
"content": "<|vision_pad|>",
|
| 95 |
+
"lstrip": false,
|
| 96 |
+
"normalized": false,
|
| 97 |
+
"rstrip": false,
|
| 98 |
+
"single_word": false,
|
| 99 |
+
"special": true
|
| 100 |
+
},
|
| 101 |
+
"151655": {
|
| 102 |
+
"content": "<|image_pad|>",
|
| 103 |
+
"lstrip": false,
|
| 104 |
+
"normalized": false,
|
| 105 |
+
"rstrip": false,
|
| 106 |
+
"single_word": false,
|
| 107 |
+
"special": true
|
| 108 |
+
},
|
| 109 |
+
"151656": {
|
| 110 |
+
"content": "<|video_pad|>",
|
| 111 |
+
"lstrip": false,
|
| 112 |
+
"normalized": false,
|
| 113 |
+
"rstrip": false,
|
| 114 |
+
"single_word": false,
|
| 115 |
+
"special": true
|
| 116 |
+
},
|
| 117 |
+
"151657": {
|
| 118 |
+
"content": "<tool_call>",
|
| 119 |
+
"lstrip": false,
|
| 120 |
+
"normalized": false,
|
| 121 |
+
"rstrip": false,
|
| 122 |
+
"single_word": false,
|
| 123 |
+
"special": false
|
| 124 |
+
},
|
| 125 |
+
"151658": {
|
| 126 |
+
"content": "</tool_call>",
|
| 127 |
+
"lstrip": false,
|
| 128 |
+
"normalized": false,
|
| 129 |
+
"rstrip": false,
|
| 130 |
+
"single_word": false,
|
| 131 |
+
"special": false
|
| 132 |
+
},
|
| 133 |
+
"151659": {
|
| 134 |
+
"content": "<|fim_prefix|>",
|
| 135 |
+
"lstrip": false,
|
| 136 |
+
"normalized": false,
|
| 137 |
+
"rstrip": false,
|
| 138 |
+
"single_word": false,
|
| 139 |
+
"special": false
|
| 140 |
+
},
|
| 141 |
+
"151660": {
|
| 142 |
+
"content": "<|fim_middle|>",
|
| 143 |
+
"lstrip": false,
|
| 144 |
+
"normalized": false,
|
| 145 |
+
"rstrip": false,
|
| 146 |
+
"single_word": false,
|
| 147 |
+
"special": false
|
| 148 |
+
},
|
| 149 |
+
"151661": {
|
| 150 |
+
"content": "<|fim_suffix|>",
|
| 151 |
+
"lstrip": false,
|
| 152 |
+
"normalized": false,
|
| 153 |
+
"rstrip": false,
|
| 154 |
+
"single_word": false,
|
| 155 |
+
"special": false
|
| 156 |
+
},
|
| 157 |
+
"151662": {
|
| 158 |
+
"content": "<|fim_pad|>",
|
| 159 |
+
"lstrip": false,
|
| 160 |
+
"normalized": false,
|
| 161 |
+
"rstrip": false,
|
| 162 |
+
"single_word": false,
|
| 163 |
+
"special": false
|
| 164 |
+
},
|
| 165 |
+
"151663": {
|
| 166 |
+
"content": "<|repo_name|>",
|
| 167 |
+
"lstrip": false,
|
| 168 |
+
"normalized": false,
|
| 169 |
+
"rstrip": false,
|
| 170 |
+
"single_word": false,
|
| 171 |
+
"special": false
|
| 172 |
+
},
|
| 173 |
+
"151664": {
|
| 174 |
+
"content": "<|file_sep|>",
|
| 175 |
+
"lstrip": false,
|
| 176 |
+
"normalized": false,
|
| 177 |
+
"rstrip": false,
|
| 178 |
+
"single_word": false,
|
| 179 |
+
"special": false
|
| 180 |
+
},
|
| 181 |
+
"151665": {
|
| 182 |
+
"content": "<tool_response>",
|
| 183 |
+
"lstrip": false,
|
| 184 |
+
"normalized": false,
|
| 185 |
+
"rstrip": false,
|
| 186 |
+
"single_word": false,
|
| 187 |
+
"special": false
|
| 188 |
+
},
|
| 189 |
+
"151666": {
|
| 190 |
+
"content": "</tool_response>",
|
| 191 |
+
"lstrip": false,
|
| 192 |
+
"normalized": false,
|
| 193 |
+
"rstrip": false,
|
| 194 |
+
"single_word": false,
|
| 195 |
+
"special": false
|
| 196 |
+
},
|
| 197 |
+
"151667": {
|
| 198 |
+
"content": "<think>",
|
| 199 |
+
"lstrip": false,
|
| 200 |
+
"normalized": false,
|
| 201 |
+
"rstrip": false,
|
| 202 |
+
"single_word": false,
|
| 203 |
+
"special": false
|
| 204 |
+
},
|
| 205 |
+
"151668": {
|
| 206 |
+
"content": "</think>",
|
| 207 |
+
"lstrip": false,
|
| 208 |
+
"normalized": false,
|
| 209 |
+
"rstrip": false,
|
| 210 |
+
"single_word": false,
|
| 211 |
+
"special": false
|
| 212 |
+
},
|
| 213 |
+
"151669": {
|
| 214 |
+
"content": "<|audio_pad|>",
|
| 215 |
+
"lstrip": false,
|
| 216 |
+
"normalized": false,
|
| 217 |
+
"rstrip": false,
|
| 218 |
+
"single_word": false,
|
| 219 |
+
"special": true
|
| 220 |
+
},
|
| 221 |
+
"151670": {
|
| 222 |
+
"content": "<|mimo_video_start|>",
|
| 223 |
+
"lstrip": false,
|
| 224 |
+
"normalized": false,
|
| 225 |
+
"rstrip": false,
|
| 226 |
+
"single_word": false,
|
| 227 |
+
"special": true
|
| 228 |
+
},
|
| 229 |
+
"151671": {
|
| 230 |
+
"content": "<|mimo_video_end|>",
|
| 231 |
+
"lstrip": false,
|
| 232 |
+
"normalized": false,
|
| 233 |
+
"rstrip": false,
|
| 234 |
+
"single_word": false,
|
| 235 |
+
"special": true
|
| 236 |
+
},
|
| 237 |
+
"151672": {
|
| 238 |
+
"content": "<|mimo_audio_eod|>",
|
| 239 |
+
"lstrip": false,
|
| 240 |
+
"normalized": false,
|
| 241 |
+
"rstrip": false,
|
| 242 |
+
"single_word": false,
|
| 243 |
+
"special": true
|
| 244 |
+
},
|
| 245 |
+
"151673": {
|
| 246 |
+
"content": "<|mimo_audio_start|>",
|
| 247 |
+
"lstrip": false,
|
| 248 |
+
"normalized": false,
|
| 249 |
+
"rstrip": false,
|
| 250 |
+
"single_word": false,
|
| 251 |
+
"special": true
|
| 252 |
+
},
|
| 253 |
+
"151674": {
|
| 254 |
+
"content": "<|mimo_audio_end|>",
|
| 255 |
+
"lstrip": false,
|
| 256 |
+
"normalized": false,
|
| 257 |
+
"rstrip": false,
|
| 258 |
+
"single_word": false,
|
| 259 |
+
"special": true
|
| 260 |
+
}
|
| 261 |
+
},
|
| 262 |
+
"additional_special_tokens": [
|
| 263 |
+
"<|im_start|>",
|
| 264 |
+
"<|im_end|>",
|
| 265 |
+
"<|object_ref_start|>",
|
| 266 |
+
"<|object_ref_end|>",
|
| 267 |
+
"<|box_start|>",
|
| 268 |
+
"<|box_end|>",
|
| 269 |
+
"<|quad_start|>",
|
| 270 |
+
"<|quad_end|>",
|
| 271 |
+
"<|vision_start|>",
|
| 272 |
+
"<|vision_end|>",
|
| 273 |
+
"<|vision_pad|>",
|
| 274 |
+
"<|image_pad|>",
|
| 275 |
+
"<|video_pad|>",
|
| 276 |
+
"<|audio_pad|>",
|
| 277 |
+
"<|mimo_video_start|>",
|
| 278 |
+
"<|mimo_video_end|>",
|
| 279 |
+
"<|mimo_audio_eod|>",
|
| 280 |
+
"<|mimo_audio_start|>",
|
| 281 |
+
"<|mimo_audio_end|>"
|
| 282 |
+
],
|
| 283 |
+
"bos_token": null,
|
| 284 |
+
"chat_template": "{%- if not add_generation_prompt is defined -%}\n {%- set add_generation_prompt = false -%}\n{%- endif -%}\n{%- if not enable_thinking is defined -%}\n {%- set enable_thinking = true -%}\n{%- endif -%}\n{%- if not keep_all_reasoning is defined -%}\n {%- set keep_all_reasoning = true -%}\n{%- endif -%}\n{%- macro render_extra_keys(json_dict, handled_keys) -%}\n {%- if json_dict is mapping %}\n {%- for json_key in json_dict if json_key not in handled_keys %}\n {%- if json_dict[json_key] is mapping or (json_dict[json_key] is sequence and json_dict[json_key] is not string) %}\n {{- '\\n<' ~ json_key ~ '>' ~ (json_dict[json_key] | tojson | safe) ~ '</' ~ json_key ~ '>' }}\n {%- else %}\n {{-'\\n<' ~ json_key ~ '>' ~ (json_dict[json_key] | string) ~ '</' ~ json_key ~ '>' }}\n {%- endif %}\n {%- endfor %}\n {%- endif %}\n{%- endmacro -%}\n{%- macro render_content(message_content) -%}\n {%- if message_content is string -%}\n {{- message_content -}}\n {%- else -%}\n {%- for content in message_content -%}\n {%- if content['type'] == 'image' or 'image' in content or 'image_url' in content -%}\n {{- '<|vision_start|><|image_pad|><|vision_end|>' -}}\n {%- elif content['type'] == 'audio' or 'audio' in content or 'audio_url' in content -%}\n {{- '<|mimo_audio_start|><|audio_pad|><|mimo_audio_end|>' -}}\n {%- elif content['type'] == 'video' or 'video' in content or 'video_url' in content -%}\n {{- '<|vision_start|><|video_pad|><|vision_end|>' -}}\n {%- elif 'text' in content -%}\n {{- content['text'] -}}\n {%- endif -%}\n {%- endfor -%}\n {%- endif -%}\n{%- endmacro -%}\n{%- if messages[0][\"role\"] == \"system\" %}\n {%- set system_message = messages[0][\"content\"] %}\n {%- set loop_messages = messages[1:] %}\n{%- else %}\n {%- set loop_messages = messages %}\n{%- endif %}\n{%- set ns = namespace(last_user_index=-1) %}\n{%- for m in loop_messages %}\n {%- if m.role == 'user' %}\n {%- set ns.last_user_index = loop.index0 -%}\n {%- endif %}\n{%- endfor %}\n{%- if not tools is defined %}\n {%- set tools = [] %}\n{%- endif %}\n{%- if system_message is defined %}\n {{- \"<|im_start|>system\\n\" + render_content(system_message) }}\n{%- else %}\n {{- \"<|im_start|>system\\nYou are MiMo, a helpful AI assistant engineered by Xiaomi.\" }}\n{%- endif %}\n{%- if tools is iterable and tools | length > 0 %}\n {{- \"\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou have access to the following functions:\\n\\n\" }}\n {{- \"<tools>\" }}\n {%- for tool in tools %}\n {%- if tool.function is defined %}\n {%- set tool = tool.function %}\n {%- endif %}\n {{- \"\\n<function>\\n<name>\" ~ tool.name ~ \"</name>\" }}\n {%- if tool.description is defined %}\n {{- '\\n<description>' ~ (tool.description | trim) ~ '</description>' }}\n {%- endif %}\n {{- '\\n<parameters>' }}\n {%- if tool.parameters is defined and tool.parameters is mapping and tool.parameters.properties is defined and tool.parameters.properties is mapping %}\n {%- for param_name, param_fields in tool.parameters.properties|items %}\n {{- '\\n<parameter>' }}\n {{- '\\n<name>' ~ param_name ~ '</name>' }}\n {%- if param_fields.type is defined %}\n {{- '\\n<type>' ~ (param_fields.type | string) ~ '</type>' }}\n {%- endif %}\n {%- if param_fields.description is defined %}\n {{- '\\n<description>' ~ (param_fields.description | trim) ~ '</description>' }}\n {%- endif %}\n {%- set handled_keys = ['name', 'type', 'description'] %}\n {{- render_extra_keys(param_fields, handled_keys) }}\n {{- '\\n</parameter>' }}\n {%- endfor %}\n {%- endif %}\n {%- set handled_keys = ['type', 'properties'] %}\n {{- render_extra_keys(tool.parameters, handled_keys) }}\n {{- '\\n</parameters>' }}\n {%- set handled_keys = ['type', 'name', 'description', 'parameters'] %}\n {{- render_extra_keys(tool, handled_keys) }}\n {{- '\\n</function>' }}\n {%- endfor %}\n {{- \"\\n</tools>\" }}\n {{- '\\n\\nFor each function call, output the function name and arguments in the following format:\\n<tool_call>\\n<function=example_function_name>\\n<parameter=example_parameter_1>value_1</parameter>\\n<parameter=example_parameter_2>This is the value for the second parameter\\nthat can span\\nmultiple lines</parameter>\\n</function>\\n</tool_call>\\n\\n<IMPORTANT>\\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\\n- DO NOT use function calls inside <think></think> tags.\\n- The value enclosed between parameter tags is preserved exactly as-is, including newlines and spaces.\\n</IMPORTANT>' }}\n{%- endif %}\n{{- '<|im_end|>' }}\n{%- for message in loop_messages %}\n {%- if message.content is string %}\n {%- set content = message.content %}\n {%- else %}\n {%- set content = render_content(message.content) %}\n {%- endif %}\n {%- if message.role == \"assistant\" %}\n {%- if message.reasoning_content is string %}\n {%- set reasoning_content = message.reasoning_content %}\n {%- else %}\n {%- set reasoning_content = '' %}\n {%- if '</think>' in content %}\n {%- set reasoning_content = content.split('</think>')[0].split('<think>')[-1] %}\n {%- set content = content.split('</think>')[-1] %}\n {%- endif %}\n {%- endif %}\n {%- if (keep_all_reasoning or loop.index0 > ns.last_user_index) and reasoning_content -%}\n {{- '<|im_start|>' + message.role + '\\n<think>' + reasoning_content + '</think>' + content }}\n {%- else %}\n {{- '<|im_start|>' + message.role + '\\n<think></think>' + content }}\n {%- endif %}\n {%- if message.tool_calls is defined and message.tool_calls is iterable and message.tool_calls | length > 0 %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '<tool_call>\\n<function=' + tool_call.name + '>\\n' }}\n {%- if tool_call.arguments is defined %}\n {%- for args_name, args_value in tool_call.arguments|items %}\n {{- '<parameter=' + args_name + '>' }}\n {%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}\n {{- args_value }}\n {{- '</parameter>\\n' }}\n {%- endfor %}\n {%- endif %}\n {{- '</function>\\n</tool_call>' }}\n {%- endfor %}\n {%- endif %}\n {{- '<|im_end|>' }}\n {%- elif message.role == \"user\" %}\n {{- '<|im_start|>' + message.role + '\\n' + render_content(message.content) + '<|im_end|>' }}\n {%- elif message.role == \"system\" %}\n {{- '<|im_start|>' + message.role + '\\n' + render_content(message.content) + '<|im_end|>' }}\n {%- elif message.role == \"tool\" %}\n {%- if loop.previtem and loop.previtem.role != \"tool\" %}\n {{- '<|im_start|>tool\\n' }}\n {%- endif %}\n {{- '<tool_response>\\n' }}\n {{- render_content(message.content) }}\n {{- '\\n</tool_response>\\n' }}\n {%- if not loop.last and loop.nextitem.role != \"tool\" %}\n {{- '<|im_end|>' }}\n {%- elif loop.last %}\n {{- '<|im_end|>' }}\n {%- endif %}\n {%- else %}\n {{- '<|im_start|>' + message.role + '\\n' + render_content(message.content) + '<|im_end|>' }}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n {%- if not enable_thinking -%}\n {{- '<think></think>' -}}\n {%- else -%}\n {{- '' -}}\n {%- endif -%}\n{%- endif %}\n",
|
| 285 |
+
"clean_up_tokenization_spaces": false,
|
| 286 |
+
"eos_token": "<|im_end|>",
|
| 287 |
+
"errors": "replace",
|
| 288 |
+
"model_max_length": 131072,
|
| 289 |
+
"pad_token": "<|endoftext|>",
|
| 290 |
+
"split_special_tokens": false,
|
| 291 |
+
"tokenizer_class": "Qwen2Tokenizer",
|
| 292 |
+
"unk_token": null
|
| 293 |
+
}
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|