Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- README.md +85 -0
- added_tokens.json +32 -0
- chat_template.jinja +170 -0
- config.json +108 -0
- fp8_meta.json +12 -0
- generation_config.json +6 -0
- merges.txt +0 -0
- model.safetensors +3 -0
- quantize_fp8.py +294 -0
- quantize_fp8_stream.py +121 -0
- special_tokens_map.json +31 -0
- tokenizer.json +3 -0
- tokenizer_config.json +271 -0
- vocab.json +0 -0
.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,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- zh
|
| 5 |
+
- en
|
| 6 |
+
- yue
|
| 7 |
+
pipeline_tag: automatic-speech-recognition
|
| 8 |
+
tags:
|
| 9 |
+
- safetensors
|
| 10 |
+
- fp8
|
| 11 |
+
- quantization
|
| 12 |
+
- speech-recognition
|
| 13 |
+
base_model: XiaomiMiMo/MiMo-V2.5-ASR
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# MiMo-V2.5-ASR — FP8 (e4m3fn)
|
| 17 |
+
|
| 18 |
+
FP8-quantized build of [XiaomiMiMo/MiMo-V2.5-ASR](https://huggingface.co/XiaomiMiMo/MiMo-V2.5-ASR),
|
| 19 |
+
the Xiaomi MiMo end-to-end ASR model with native Mandarin/English code-switching,
|
| 20 |
+
Chinese dialects, song lyrics, noisy/multi-speaker robustness, and native punctuation.
|
| 21 |
+
|
| 22 |
+
## What this is
|
| 23 |
+
|
| 24 |
+
- **Weights:** `float8_e4m3fn`, per-output-channel absmax scaling (one fp32 scale per row), baked at save time.
|
| 25 |
+
- **Activations:** dynamic per-tensor fp8 quantization each forward pass.
|
| 26 |
+
- **Matmul:** `torch._scaled_mm` (FP8 tensor cores on Ada / Hopper / Blackwell).
|
| 27 |
+
- **Skipped (kept bf16):** embeddings, RMSNorm/LayerNorm, biases. 417 Linear layers converted.
|
| 28 |
+
- The audio encoder/tokenizer ([MiMo-Audio-Tokenizer](https://huggingface.co/XiaomiMiMo/MiMo-Audio-Tokenizer)) is **not** quantized; download it separately for inference.
|
| 29 |
+
|
| 30 |
+
This roughly halves the LLM weight footprint (~32 GB bf16 → ~16-17 GB on disk).
|
| 31 |
+
|
| 32 |
+
## Important: this is NOT a drop-in `from_pretrained` checkpoint
|
| 33 |
+
|
| 34 |
+
`model.safetensors` stores custom `FP8Linear` buffers (`*.weight_fp8`, `*.weight_scale`),
|
| 35 |
+
not standard HF Linear weights. It must be loaded through the matching `FP8Linear`
|
| 36 |
+
modules. Use the loader below.
|
| 37 |
+
|
| 38 |
+
## Usage
|
| 39 |
+
|
| 40 |
+
```bash
|
| 41 |
+
git clone https://github.com/XiaomiMiMo/MiMo-V2.5-ASR.git
|
| 42 |
+
cd MiMo-V2.5-ASR
|
| 43 |
+
pip install -r requirements.txt
|
| 44 |
+
pip install flash-attn==2.7.4.post1 # required by the audio tokenizer
|
| 45 |
+
hf download XiaomiMiMo/MiMo-Audio-Tokenizer --local-dir ./models/MiMo-Audio-Tokenizer
|
| 46 |
+
hf download Infatoshi/MiMo-V2.5-ASR-FP8 --local-dir ./MiMo-V2.5-ASR-FP8
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
Then load with the `FP8Linear` loader (`quantize_fp8.py`, included here as `quantize_fp8.py`):
|
| 50 |
+
|
| 51 |
+
```python
|
| 52 |
+
from quantize_fp8 import load_fp8_model
|
| 53 |
+
mimo = load_fp8_model(
|
| 54 |
+
fp8_dir="./MiMo-V2.5-ASR-FP8",
|
| 55 |
+
tokenizer_path="./models/MiMo-Audio-Tokenizer",
|
| 56 |
+
repo_root=".", # the cloned MiMo-V2.5-ASR repo
|
| 57 |
+
)
|
| 58 |
+
print(mimo.asr_sft("audio.wav", audio_tag="<english>"))
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
## Quantization fidelity
|
| 62 |
+
|
| 63 |
+
Per-output-channel absmax dequant error vs the original fp32 weights, sampled across
|
| 64 |
+
depth (layers 0/17/35), all attn+mlp projections, lm_head, and the audio local transformer:
|
| 65 |
+
|
| 66 |
+
- relative Frobenius error: **~0.026, uniform** across every sampled layer (max 0.027 on lm_head)
|
| 67 |
+
- no corrupted or outlier layers
|
| 68 |
+
|
| 69 |
+
This is the expected magnitude for fp8 e4m3 with per-channel scaling (3 mantissa bits).
|
| 70 |
+
|
| 71 |
+
## Requirements
|
| 72 |
+
|
| 73 |
+
- CUDA GPU with FP8 tensor cores (Ada / Hopper / Blackwell), CUDA >= 12.0
|
| 74 |
+
- torch >= 2.6, safetensors
|
| 75 |
+
- **Blackwell (sm_120, e.g. RTX PRO 6000 / RTX 50xx):** use a torch build with CUDA 12.8+
|
| 76 |
+
(torch >= 2.7, `cu128`). torch 2.6 `cu124` ships no sm_120 kernels and will fail with
|
| 77 |
+
"no kernel image is available for execution on the device".
|
| 78 |
+
|
| 79 |
+
## Notes / caveats
|
| 80 |
+
|
| 81 |
+
- FP8 e4m3fn weight-only-style quantization is lossy; expect small WER deltas vs bf16.
|
| 82 |
+
- Per-tensor dynamic activation scaling is simple and fast but less accurate than
|
| 83 |
+
per-token scaling on activations with large outliers.
|
| 84 |
+
|
| 85 |
+
Derivative of an MIT-licensed model; original credit to the Xiaomi MiMo team.
|
added_tokens.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"</tool_call>": 151658,
|
| 3 |
+
"<tool_call>": 151657,
|
| 4 |
+
"<|Human|>": 151668,
|
| 5 |
+
"<|SpeechLM|>": 151669,
|
| 6 |
+
"<|box_end|>": 151649,
|
| 7 |
+
"<|box_start|>": 151648,
|
| 8 |
+
"<|empty|>": 151667,
|
| 9 |
+
"<|endoftext|>": 151643,
|
| 10 |
+
"<|eosp|>": 151666,
|
| 11 |
+
"<|eostm|>": 151671,
|
| 12 |
+
"<|eot|>": 151672,
|
| 13 |
+
"<|file_sep|>": 151664,
|
| 14 |
+
"<|fim_middle|>": 151660,
|
| 15 |
+
"<|fim_pad|>": 151662,
|
| 16 |
+
"<|fim_prefix|>": 151659,
|
| 17 |
+
"<|fim_suffix|>": 151661,
|
| 18 |
+
"<|im_end|>": 151645,
|
| 19 |
+
"<|im_start|>": 151644,
|
| 20 |
+
"<|image_pad|>": 151655,
|
| 21 |
+
"<|object_ref_end|>": 151647,
|
| 22 |
+
"<|object_ref_start|>": 151646,
|
| 23 |
+
"<|quad_end|>": 151651,
|
| 24 |
+
"<|quad_start|>": 151650,
|
| 25 |
+
"<|repo_name|>": 151663,
|
| 26 |
+
"<|sosp|>": 151665,
|
| 27 |
+
"<|sostm|>": 151670,
|
| 28 |
+
"<|video_pad|>": 151656,
|
| 29 |
+
"<|vision_end|>": 151653,
|
| 30 |
+
"<|vision_pad|>": 151654,
|
| 31 |
+
"<|vision_start|>": 151652
|
| 32 |
+
}
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- if not add_generation_prompt is defined -%}
|
| 2 |
+
{%- set add_generation_prompt = false -%}
|
| 3 |
+
{%- endif -%}
|
| 4 |
+
{%- if not enable_thinking is defined -%}
|
| 5 |
+
{%- set enable_thinking = false -%}
|
| 6 |
+
{%- endif -%}
|
| 7 |
+
{%- if not keep_all_reasoning is defined -%}
|
| 8 |
+
{%- set keep_all_reasoning = false -%}
|
| 9 |
+
{%- endif -%}
|
| 10 |
+
{%- macro render_extra_keys(json_dict, handled_keys) -%}
|
| 11 |
+
{%- if json_dict is mapping %}
|
| 12 |
+
{%- for json_key in json_dict if json_key not in handled_keys %}
|
| 13 |
+
{%- if json_dict[json_key] is mapping or (json_dict[json_key] is sequence and json_dict[json_key] is not string) %}
|
| 14 |
+
{{- '\n<' ~ json_key ~ '>' ~ (json_dict[json_key] | tojson | safe) ~ '</' ~ json_key ~ '>' }}
|
| 15 |
+
{%- else %}
|
| 16 |
+
{{-'\n<' ~ json_key ~ '>' ~ (json_dict[json_key] | string) ~ '</' ~ json_key ~ '>' }}
|
| 17 |
+
{%- endif %}
|
| 18 |
+
{%- endfor %}
|
| 19 |
+
{%- endif %}
|
| 20 |
+
{%- endmacro -%}
|
| 21 |
+
{%- macro render_content(message_content) -%}
|
| 22 |
+
{%- if message_content is string -%}
|
| 23 |
+
{{- message_content -}}
|
| 24 |
+
{%- else -%}
|
| 25 |
+
{%- for content in message_content -%}
|
| 26 |
+
{%- if content['type'] == 'image' or 'image' in content or 'image_url' in content -%}
|
| 27 |
+
{{- '<|vision_start|><|image_pad|><|vision_end|>' -}}
|
| 28 |
+
{%- elif content['type'] == 'audio' or 'audio' in content or 'audio_url' in content -%}
|
| 29 |
+
{{- '<|sosp|><|empty|><|eosp|>' -}}
|
| 30 |
+
{%- elif content['type'] == 'video' or 'video' in content or 'video_url' in content -%}
|
| 31 |
+
{{- '<|vision_start|><|video_pad|><|vision_end|>' -}}
|
| 32 |
+
{%- elif 'text' in content -%}
|
| 33 |
+
{{- content['text'] -}}
|
| 34 |
+
{%- endif -%}
|
| 35 |
+
{%- endfor -%}
|
| 36 |
+
{%- endif -%}
|
| 37 |
+
{%- endmacro -%}
|
| 38 |
+
{%- if messages[0]["role"] == "system" %}
|
| 39 |
+
{%- set system_message = messages[0]["content"] %}
|
| 40 |
+
{%- set loop_messages = messages[1:] %}
|
| 41 |
+
{%- else %}
|
| 42 |
+
{%- set loop_messages = messages %}
|
| 43 |
+
{%- endif %}
|
| 44 |
+
{%- set ns = namespace(last_user_index=-1, assistant_is_last=false) %}
|
| 45 |
+
{%- for m in loop_messages %}
|
| 46 |
+
{%- if m.role == 'user' %}
|
| 47 |
+
{%- set ns.last_user_index = loop.index0 -%}
|
| 48 |
+
{%- endif %}
|
| 49 |
+
{%- endfor %}
|
| 50 |
+
{%- if not tools is defined %}
|
| 51 |
+
{%- set tools = [] %}
|
| 52 |
+
{%- endif %}
|
| 53 |
+
{%- set has_system = false %}
|
| 54 |
+
{%- if system_message is defined %}
|
| 55 |
+
{{- "<|im_start|>system\n" + system_message }}
|
| 56 |
+
{%- set has_system = true %}
|
| 57 |
+
{%- endif %}
|
| 58 |
+
{%- if tools is iterable and tools | length > 0 %}
|
| 59 |
+
{%- if not has_system %}
|
| 60 |
+
{{- "<|im_start|>system\n" }}
|
| 61 |
+
{%- set has_system = true %}
|
| 62 |
+
{%- endif %}
|
| 63 |
+
{{- "\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" }}
|
| 64 |
+
{{- "<tools>" }}
|
| 65 |
+
{%- for tool in tools %}
|
| 66 |
+
{%- if tool.function is defined %}
|
| 67 |
+
{%- set tool = tool.function %}
|
| 68 |
+
{%- endif %}
|
| 69 |
+
{{- "\n<function>\n<name>" ~ tool.name ~ "</name>" }}
|
| 70 |
+
{%- if tool.description is defined %}
|
| 71 |
+
{{- '\n<description>' ~ (tool.description | trim) ~ '</description>' }}
|
| 72 |
+
{%- endif %}
|
| 73 |
+
{{- '\n<parameters>' }}
|
| 74 |
+
{%- if tool.parameters is defined and tool.parameters is mapping and tool.parameters.properties is defined and tool.parameters.properties is mapping %}
|
| 75 |
+
{%- for param_name, param_fields in tool.parameters.properties|items %}
|
| 76 |
+
{{- '\n<parameter>' }}
|
| 77 |
+
{{- '\n<name>' ~ param_name ~ '</name>' }}
|
| 78 |
+
{%- if param_fields.type is defined %}
|
| 79 |
+
{{- '\n<type>' ~ (param_fields.type | string) ~ '</type>' }}
|
| 80 |
+
{%- endif %}
|
| 81 |
+
{%- if param_fields.description is defined %}
|
| 82 |
+
{{- '\n<description>' ~ (param_fields.description | trim) ~ '</description>' }}
|
| 83 |
+
{%- endif %}
|
| 84 |
+
{%- set handled_keys = ['name', 'type', 'description'] %}
|
| 85 |
+
{{- render_extra_keys(param_fields, handled_keys) }}
|
| 86 |
+
{{- '\n</parameter>' }}
|
| 87 |
+
{%- endfor %}
|
| 88 |
+
{%- endif %}
|
| 89 |
+
{%- set handled_keys = ['type', 'properties'] %}
|
| 90 |
+
{{- render_extra_keys(tool.parameters, handled_keys) }}
|
| 91 |
+
{{- '\n</parameters>' }}
|
| 92 |
+
{%- set handled_keys = ['type', 'name', 'description', 'parameters'] %}
|
| 93 |
+
{{- render_extra_keys(tool, handled_keys) }}
|
| 94 |
+
{{- '\n</function>' }}
|
| 95 |
+
{%- endfor %}
|
| 96 |
+
{{- "\n</tools>" }}
|
| 97 |
+
{{- '\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>' }}
|
| 98 |
+
{%- endif %}
|
| 99 |
+
{%- if has_system %}
|
| 100 |
+
{{- '<|im_end|>\n' }}
|
| 101 |
+
{%- endif %}
|
| 102 |
+
{%- for message in loop_messages %}
|
| 103 |
+
{%- if message.content is string %}
|
| 104 |
+
{%- set content = message.content %}
|
| 105 |
+
{%- else %}
|
| 106 |
+
{%- set content = render_content(message.content) %}
|
| 107 |
+
{%- endif %}
|
| 108 |
+
{%- if message.role == "assistant" %}
|
| 109 |
+
{%- if message.reasoning_content is string %}
|
| 110 |
+
{%- set reasoning_content = message.reasoning_content %}
|
| 111 |
+
{%- else %}
|
| 112 |
+
{%- set reasoning_content = '' %}
|
| 113 |
+
{%- if '</think>' in content %}
|
| 114 |
+
{%- set reasoning_content = content.split('</think>')[0].split('<think>')[-1] %}
|
| 115 |
+
{%- set content = content.split('</think>')[-1] %}
|
| 116 |
+
{%- endif %}
|
| 117 |
+
{%- endif %}
|
| 118 |
+
{%- if (keep_all_reasoning or loop.index0 > ns.last_user_index) and reasoning_content -%}
|
| 119 |
+
{{- '<|im_start|>' + message.role + '\n<think>' + reasoning_content + '</think>' + content }}
|
| 120 |
+
{%- else %}
|
| 121 |
+
{{- '<|im_start|>' + message.role + '\n<think></think>' + content }}
|
| 122 |
+
{%- endif %}
|
| 123 |
+
{%- if message.tool_calls is defined and message.tool_calls is iterable and message.tool_calls | length > 0 %}
|
| 124 |
+
{%- for tool_call in message.tool_calls %}
|
| 125 |
+
{%- if tool_call.function is defined %}
|
| 126 |
+
{%- set tool_call = tool_call.function %}
|
| 127 |
+
{%- endif %}
|
| 128 |
+
{{- '<tool_call>\n<function=' + tool_call.name + '>\n' }}
|
| 129 |
+
{%- if tool_call.arguments is defined %}
|
| 130 |
+
{%- for args_name, args_value in tool_call.arguments|items %}
|
| 131 |
+
{{- '<parameter=' + args_name + '>' }}
|
| 132 |
+
{%- 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 %}
|
| 133 |
+
{{- args_value }}
|
| 134 |
+
{{- '</parameter>\n' }}
|
| 135 |
+
{%- endfor %}
|
| 136 |
+
{%- endif %}
|
| 137 |
+
{{- '</function>\n</tool_call>' }}
|
| 138 |
+
{%- endfor %}
|
| 139 |
+
{%- endif %}
|
| 140 |
+
{%- if loop.last %}
|
| 141 |
+
{%- set ns.assistant_is_last = true %}
|
| 142 |
+
{%- else %}
|
| 143 |
+
{{- '<|im_end|>\n' }}
|
| 144 |
+
{%- endif %}
|
| 145 |
+
{%- elif message.role == "user" %}
|
| 146 |
+
{{- '<|im_start|>' + message.role + '\n' + render_content(message.content) + '<|im_end|>\n' }}
|
| 147 |
+
{%- elif message.role == "system" %}
|
| 148 |
+
{{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>\n' }}
|
| 149 |
+
{%- elif message.role == "tool" %}
|
| 150 |
+
{%- if loop.previtem and loop.previtem.role != "tool" %}
|
| 151 |
+
{{- '<|im_start|>tool\n' }}
|
| 152 |
+
{%- endif %}
|
| 153 |
+
{{- '<tool_response>\n' }}
|
| 154 |
+
{{- render_content(message.content) }}
|
| 155 |
+
{{- '\n</tool_response>\n' }}
|
| 156 |
+
{%- if not loop.last and loop.nextitem.role != "tool" %}
|
| 157 |
+
{{- '<|im_end|>\n' }}
|
| 158 |
+
{%- elif loop.last %}
|
| 159 |
+
{{- '<|im_end|>\n' }}
|
| 160 |
+
{%- endif %}
|
| 161 |
+
{%- else %}
|
| 162 |
+
{{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>\n' }}
|
| 163 |
+
{%- endif %}
|
| 164 |
+
{%- endfor %}
|
| 165 |
+
{%- if add_generation_prompt and not ns.assistant_is_last %}
|
| 166 |
+
{{- '<|im_start|>assistant\n' }}
|
| 167 |
+
{%- if not enable_thinking -%}
|
| 168 |
+
{{- '<think>\n\n</think>\n' -}}
|
| 169 |
+
{%- endif -%}
|
| 170 |
+
{%- endif %}
|
config.json
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_input_local_transformer": true,
|
| 3 |
+
"add_speech_sosp_eosp": false,
|
| 4 |
+
"architectures": [
|
| 5 |
+
"MiMoV2ASRForCausalLM"
|
| 6 |
+
],
|
| 7 |
+
"attention_bias": true,
|
| 8 |
+
"attention_dropout": 0.0,
|
| 9 |
+
"audio_channels": 8,
|
| 10 |
+
"delay_pattern": "0-1-2-3-4-5-6-7",
|
| 11 |
+
"dtype": "bfloat16",
|
| 12 |
+
"empty_loss_weight": 0.01,
|
| 13 |
+
"group_size": 4,
|
| 14 |
+
"head_dim": 128,
|
| 15 |
+
"hidden_act": "silu",
|
| 16 |
+
"hidden_size": 4096,
|
| 17 |
+
"initializer_range": 0.02,
|
| 18 |
+
"input_full_attention": true,
|
| 19 |
+
"input_local_dim": 1024,
|
| 20 |
+
"input_local_layers": 6,
|
| 21 |
+
"intermediate_size": 11008,
|
| 22 |
+
"layer_types": [
|
| 23 |
+
"full_attention",
|
| 24 |
+
"full_attention",
|
| 25 |
+
"full_attention",
|
| 26 |
+
"full_attention",
|
| 27 |
+
"full_attention",
|
| 28 |
+
"full_attention",
|
| 29 |
+
"full_attention",
|
| 30 |
+
"full_attention",
|
| 31 |
+
"full_attention",
|
| 32 |
+
"full_attention",
|
| 33 |
+
"full_attention",
|
| 34 |
+
"full_attention",
|
| 35 |
+
"full_attention",
|
| 36 |
+
"full_attention",
|
| 37 |
+
"full_attention",
|
| 38 |
+
"full_attention",
|
| 39 |
+
"full_attention",
|
| 40 |
+
"full_attention",
|
| 41 |
+
"full_attention",
|
| 42 |
+
"full_attention",
|
| 43 |
+
"full_attention",
|
| 44 |
+
"full_attention",
|
| 45 |
+
"full_attention",
|
| 46 |
+
"full_attention",
|
| 47 |
+
"full_attention",
|
| 48 |
+
"full_attention",
|
| 49 |
+
"full_attention",
|
| 50 |
+
"full_attention",
|
| 51 |
+
"full_attention",
|
| 52 |
+
"full_attention",
|
| 53 |
+
"full_attention",
|
| 54 |
+
"full_attention",
|
| 55 |
+
"full_attention",
|
| 56 |
+
"full_attention",
|
| 57 |
+
"full_attention",
|
| 58 |
+
"full_attention"
|
| 59 |
+
],
|
| 60 |
+
"local_attn_dropout": 0.1,
|
| 61 |
+
"local_attn_heads": 64,
|
| 62 |
+
"local_dim": 1024,
|
| 63 |
+
"local_ffn_dim": 4096,
|
| 64 |
+
"local_hidden_dropout": 0.1,
|
| 65 |
+
"local_layers": 16,
|
| 66 |
+
"local_rotary_base": 640000,
|
| 67 |
+
"max_position_embeddings": 8192,
|
| 68 |
+
"max_window_layers": 28,
|
| 69 |
+
"mlp_layers": 1,
|
| 70 |
+
"model_type": "qwen2",
|
| 71 |
+
"n_rvq": 20,
|
| 72 |
+
"no_speech_loss": false,
|
| 73 |
+
"no_text_loss": false,
|
| 74 |
+
"num_attention_heads": 32,
|
| 75 |
+
"num_hidden_layers": 36,
|
| 76 |
+
"num_key_value_heads": 8,
|
| 77 |
+
"rms_norm_eps": 1e-06,
|
| 78 |
+
"rope_scaling": null,
|
| 79 |
+
"rope_theta": 640000,
|
| 80 |
+
"sliding_window": null,
|
| 81 |
+
"speech_vocab_size": "1025-1025-129-129-129-129-129-129",
|
| 82 |
+
"speech_zeroemb_idx": "1024-1024-128-128-128-128-128-128",
|
| 83 |
+
"tie_word_embeddings": false,
|
| 84 |
+
"transformers_version": "4.57.1",
|
| 85 |
+
"use_cache": true,
|
| 86 |
+
"use_sliding_window": false,
|
| 87 |
+
"vocab_size": 151680,
|
| 88 |
+
"audio_config": {
|
| 89 |
+
"tokenizer_version": "v1",
|
| 90 |
+
"speech_vocab_size": "1025-1025-129-129-129-129-129-129",
|
| 91 |
+
"speech_zeroemb_idx": "1024-1024-128-128-128-128-128-128",
|
| 92 |
+
"group_size": 4,
|
| 93 |
+
"audio_channels": 8,
|
| 94 |
+
"input_local_layers": 6,
|
| 95 |
+
"input_local_dim": 1024,
|
| 96 |
+
"input_full_attention": true,
|
| 97 |
+
"input_local_attn_heads": 64,
|
| 98 |
+
"input_local_head_dim": 16,
|
| 99 |
+
"input_local_intermediate_size": 4096,
|
| 100 |
+
"input_local_hidden_dropout": 0.1,
|
| 101 |
+
"out_hidden_size": 4096,
|
| 102 |
+
"rope_theta": 640000,
|
| 103 |
+
"partial_rotary_factor": 1.0,
|
| 104 |
+
"projection_layers": 1,
|
| 105 |
+
"add_post_norm": true,
|
| 106 |
+
"audio_segment_size": 6000
|
| 107 |
+
}
|
| 108 |
+
}
|
fp8_meta.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"dtype": "float8_e4m3fn",
|
| 3 |
+
"weight_scaling": "per_channel_absmax",
|
| 4 |
+
"activation_scaling": "dynamic_per_tensor",
|
| 5 |
+
"matmul_op": "torch._scaled_mm",
|
| 6 |
+
"output_dtype": "bfloat16",
|
| 7 |
+
"converted_layers": 417,
|
| 8 |
+
"weight_gb_before": 32.074,
|
| 9 |
+
"weight_gb_after": 8.65,
|
| 10 |
+
"compression_ratio": 3.708,
|
| 11 |
+
"quantizer": "streaming_cpu"
|
| 12 |
+
}
|
generation_config.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"do_sample": true,
|
| 3 |
+
"temperature": 0.6,
|
| 4 |
+
"top_k": -1,
|
| 5 |
+
"top_p": 0.95
|
| 6 |
+
}
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7502bf5d0971b5673f1f33479a2c51769bce3e1f4b268cebf49776ea28a7a0b5
|
| 3 |
+
size 8650576304
|
quantize_fp8.py
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
MiMo-V2.5-ASR -> FP8 e4m3fn (per-channel weight quant, dynamic activation quant)
|
| 3 |
+
|
| 4 |
+
Quantize entrypoint loads MiMoAudioForCausalLM directly (no audio tokenizer / no
|
| 5 |
+
flash-attn needed -- the LLM is pure Qwen2). Verify/load paths still go through the
|
| 6 |
+
full MimoAudio stack and DO require flash-attn + the audio tokenizer.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import os
|
| 10 |
+
import sys
|
| 11 |
+
import json
|
| 12 |
+
import shutil
|
| 13 |
+
import argparse
|
| 14 |
+
from pathlib import Path
|
| 15 |
+
|
| 16 |
+
import torch
|
| 17 |
+
import torch.nn as nn
|
| 18 |
+
from safetensors.torch import save_file, safe_open
|
| 19 |
+
|
| 20 |
+
REPO_ROOT = Path(__file__).resolve().parent
|
| 21 |
+
if str(REPO_ROOT) not in sys.path:
|
| 22 |
+
sys.path.insert(0, str(REPO_ROOT))
|
| 23 |
+
|
| 24 |
+
# ----- constants -----
|
| 25 |
+
FP8_DTYPE = torch.float8_e4m3fn
|
| 26 |
+
FP8_MAX = torch.finfo(FP8_DTYPE).max # 448.0
|
| 27 |
+
SCALE_DTYPE = torch.float32
|
| 28 |
+
SKIP_TYPES = (nn.Embedding, nn.LayerNorm, nn.GroupNorm,
|
| 29 |
+
nn.BatchNorm1d, nn.BatchNorm2d, nn.RMSNorm)
|
| 30 |
+
|
| 31 |
+
CONFIG_FILES = [
|
| 32 |
+
"config.json", "tokenizer_config.json", "tokenizer.json",
|
| 33 |
+
"special_tokens_map.json", "generation_config.json",
|
| 34 |
+
"added_tokens.json", "merges.txt", "vocab.json", "chat_template.jinja",
|
| 35 |
+
]
|
| 36 |
+
|
| 37 |
+
SPECIAL_TOKENS = ["<|sosp|>", "<|eosp|>", "<|empty|>", "<|Human|>",
|
| 38 |
+
"<|SpeechLM|>", "<|sostm|>", "<|eostm|>", "<|eot|>"]
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
# ----- weight quantization -----
|
| 42 |
+
def quantize_weight_per_channel(weight: torch.Tensor):
|
| 43 |
+
"""Per output-channel absmax scaling. weight: [out, in]"""
|
| 44 |
+
w = weight.float()
|
| 45 |
+
amax = w.abs().amax(dim=1, keepdim=True).clamp(min=1e-12)
|
| 46 |
+
scale = (amax / FP8_MAX).to(SCALE_DTYPE)
|
| 47 |
+
w_fp8 = (w / scale).clamp(-FP8_MAX, FP8_MAX).to(FP8_DTYPE)
|
| 48 |
+
return w_fp8, scale
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class FP8Linear(nn.Module):
|
| 52 |
+
"""FP8 e4m3fn weights + per-channel scales; dynamic per-tensor activation quant."""
|
| 53 |
+
|
| 54 |
+
def __init__(self, linear: nn.Linear):
|
| 55 |
+
super().__init__()
|
| 56 |
+
with torch.no_grad():
|
| 57 |
+
w_fp8, w_scale = quantize_weight_per_channel(linear.weight)
|
| 58 |
+
self.register_buffer("weight_fp8", w_fp8.contiguous()) # [out, in]
|
| 59 |
+
self.register_buffer("weight_scale", w_scale.squeeze(1)) # [out]
|
| 60 |
+
if linear.bias is not None:
|
| 61 |
+
self.register_buffer("bias", linear.bias.detach().clone())
|
| 62 |
+
else:
|
| 63 |
+
self.bias = None
|
| 64 |
+
self.in_features = linear.in_features
|
| 65 |
+
self.out_features = linear.out_features
|
| 66 |
+
|
| 67 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 68 |
+
leading = x.shape[:-1]
|
| 69 |
+
x2d = x.reshape(-1, self.in_features)
|
| 70 |
+
x_scale = (x2d.float().abs().max().clamp(min=1e-12) / FP8_MAX).to(SCALE_DTYPE)
|
| 71 |
+
x_fp8 = (x2d.float() / x_scale).clamp(-FP8_MAX, FP8_MAX).to(FP8_DTYPE)
|
| 72 |
+
w_scale_scalar = self.weight_scale.max().to(SCALE_DTYPE)
|
| 73 |
+
out = torch._scaled_mm(
|
| 74 |
+
x_fp8, self.weight_fp8.t(),
|
| 75 |
+
scale_a=x_scale, scale_b=w_scale_scalar,
|
| 76 |
+
out_dtype=torch.bfloat16, use_fast_accum=True,
|
| 77 |
+
)
|
| 78 |
+
correction = (self.weight_scale / w_scale_scalar).to(torch.bfloat16)
|
| 79 |
+
out = out * correction.unsqueeze(0)
|
| 80 |
+
if self.bias is not None:
|
| 81 |
+
out = out + self.bias.to(out.dtype)
|
| 82 |
+
return out.reshape(*leading, self.out_features)
|
| 83 |
+
|
| 84 |
+
def extra_repr(self):
|
| 85 |
+
return f"in={self.in_features}, out={self.out_features}, fp8=e4m3fn"
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
# ----- model walk -----
|
| 89 |
+
def quantize_model(model: nn.Module, verbose: bool = True):
|
| 90 |
+
stats = {"converted": 0, "skipped": 0, "bytes_before": 0, "bytes_after": 0}
|
| 91 |
+
|
| 92 |
+
def _walk(parent, prefix=""):
|
| 93 |
+
for name, module in list(parent.named_children()):
|
| 94 |
+
full = f"{prefix}.{name}" if prefix else name
|
| 95 |
+
if isinstance(module, nn.Linear) and not isinstance(module, SKIP_TYPES):
|
| 96 |
+
b_before = module.weight.numel() * module.weight.element_size()
|
| 97 |
+
if module.bias is not None:
|
| 98 |
+
b_before += module.bias.numel() * module.bias.element_size()
|
| 99 |
+
fp8mod = FP8Linear(module)
|
| 100 |
+
b_after = fp8mod.weight_fp8.numel() + fp8mod.weight_scale.numel() * 4
|
| 101 |
+
if fp8mod.bias is not None:
|
| 102 |
+
b_after += fp8mod.bias.numel() * fp8mod.bias.element_size()
|
| 103 |
+
setattr(parent, name, fp8mod)
|
| 104 |
+
stats["converted"] += 1
|
| 105 |
+
stats["bytes_before"] += b_before
|
| 106 |
+
stats["bytes_after"] += b_after
|
| 107 |
+
if verbose:
|
| 108 |
+
print(f" [FP8] {full:<70} {b_before/max(b_after,1):.1f}x")
|
| 109 |
+
elif isinstance(module, SKIP_TYPES):
|
| 110 |
+
stats["skipped"] += 1
|
| 111 |
+
else:
|
| 112 |
+
_walk(module, full)
|
| 113 |
+
|
| 114 |
+
_walk(model)
|
| 115 |
+
return model, stats
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
# ----- save -----
|
| 119 |
+
def save_fp8(model, out_dir: Path, stats: dict, model_path: Path):
|
| 120 |
+
out_dir.mkdir(parents=True, exist_ok=True)
|
| 121 |
+
state = {k: v.contiguous().cpu() for k, v in model.state_dict().items()}
|
| 122 |
+
st_path = out_dir / "model.safetensors"
|
| 123 |
+
save_file(state, str(st_path), metadata={"format": "pt"})
|
| 124 |
+
|
| 125 |
+
copied = []
|
| 126 |
+
for cfg in CONFIG_FILES:
|
| 127 |
+
src = model_path / cfg
|
| 128 |
+
if src.exists():
|
| 129 |
+
shutil.copy2(src, out_dir / cfg)
|
| 130 |
+
copied.append(cfg)
|
| 131 |
+
if copied:
|
| 132 |
+
print(f" Copied config: {', '.join(copied)}")
|
| 133 |
+
|
| 134 |
+
gb_before = stats["bytes_before"] / 1e9
|
| 135 |
+
gb_after = stats["bytes_after"] / 1e9
|
| 136 |
+
ratio = round(stats["bytes_before"] / max(stats["bytes_after"], 1), 3)
|
| 137 |
+
meta = {
|
| 138 |
+
"dtype": "float8_e4m3fn", "weight_scaling": "per_channel_absmax",
|
| 139 |
+
"activation_scaling": "dynamic_per_tensor", "matmul_op": "torch._scaled_mm",
|
| 140 |
+
"output_dtype": "bfloat16", "converted_layers": stats["converted"],
|
| 141 |
+
"skipped_layers": stats["skipped"], "weight_gb_before": round(gb_before, 3),
|
| 142 |
+
"weight_gb_after": round(gb_after, 3), "compression_ratio": ratio,
|
| 143 |
+
}
|
| 144 |
+
with open(out_dir / "fp8_meta.json", "w") as f:
|
| 145 |
+
json.dump(meta, f, indent=2)
|
| 146 |
+
|
| 147 |
+
actual_gb = st_path.stat().st_size / 1e9
|
| 148 |
+
print(f"\nOK {st_path} ({actual_gb:.2f} GB on disk)")
|
| 149 |
+
print(f" weight bytes: {gb_before:.2f} GB -> {gb_after:.2f} GB ({ratio}x)")
|
| 150 |
+
print(f" {stats['converted']} layers converted, {stats['skipped']} skipped")
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def _build_args_and_tokenizer(model_path: str):
|
| 154 |
+
from transformers import AutoTokenizer
|
| 155 |
+
from src.mimo_audio.modeling_mimo_audio import MiMoAudioArguments
|
| 156 |
+
tok = AutoTokenizer.from_pretrained(model_path)
|
| 157 |
+
for t in SPECIAL_TOKENS:
|
| 158 |
+
if t not in tok.get_vocab():
|
| 159 |
+
tok.add_tokens([t], special_tokens=True)
|
| 160 |
+
gid = lambda t: tok.convert_tokens_to_ids(t)
|
| 161 |
+
args = MiMoAudioArguments(
|
| 162 |
+
model_name_or_path=model_path,
|
| 163 |
+
sosp_idx=gid("<|sosp|>"), eosp_idx=gid("<|eosp|>"),
|
| 164 |
+
empty_idx=gid("<|empty|>"), sostm_idx=gid("<|sostm|>"),
|
| 165 |
+
eostm_idx=gid("<|eostm|>"), eot_idx=gid("<|eot|>"),
|
| 166 |
+
)
|
| 167 |
+
return args, tok
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
# ----- quantize entrypoint (direct LLM load, no audio tokenizer / flash-attn) -----
|
| 171 |
+
def run_quantize(args):
|
| 172 |
+
from src.mimo_audio.modeling_mimo_audio import MiMoAudioForCausalLM
|
| 173 |
+
|
| 174 |
+
print(f"Loading MiMoAudioForCausalLM from {args.model_path} on {args.device} ...")
|
| 175 |
+
model_args, _ = _build_args_and_tokenizer(args.model_path)
|
| 176 |
+
model = MiMoAudioForCausalLM.from_pretrained(
|
| 177 |
+
args.model_path,
|
| 178 |
+
args=model_args,
|
| 179 |
+
torch_dtype=torch.bfloat16,
|
| 180 |
+
device_map={"": args.device},
|
| 181 |
+
attn_implementation="sdpa",
|
| 182 |
+
)
|
| 183 |
+
model.eval()
|
| 184 |
+
print("OK loaded\n")
|
| 185 |
+
|
| 186 |
+
print("Quantizing to FP8 e4m3fn ...")
|
| 187 |
+
with torch.no_grad():
|
| 188 |
+
model, stats = quantize_model(model, verbose=not args.quiet)
|
| 189 |
+
save_fp8(model, Path(args.out_dir), stats, Path(args.model_path))
|
| 190 |
+
print("\nDone.")
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
# ----- load FP8 model (for inference / verify) -----
|
| 194 |
+
def load_fp8_model(fp8_dir: str, tokenizer_path: str, repo_root: str, device: str = "cuda"):
|
| 195 |
+
"""
|
| 196 |
+
Load the FP8 checkpoint for inference, returning a MimoAudio wrapper exposing .asr_sft().
|
| 197 |
+
|
| 198 |
+
Strategy: instantiate the real architecture via from_pretrained on the ORIGINAL repo
|
| 199 |
+
weights is NOT required -- instead we build the bf16 architecture from config (correct
|
| 200 |
+
rotary init), replace Linears with FP8Linear shells, then load the FP8 state dict.
|
| 201 |
+
|
| 202 |
+
repo_root must be the cloned MiMo-V2.5-ASR repo (contains src/).
|
| 203 |
+
fp8_dir must contain model.safetensors + config/tokenizer files.
|
| 204 |
+
"""
|
| 205 |
+
rr = Path(repo_root).resolve()
|
| 206 |
+
if str(rr) not in sys.path:
|
| 207 |
+
sys.path.insert(0, str(rr))
|
| 208 |
+
|
| 209 |
+
from src.mimo_audio.mimo_audio import MimoAudio
|
| 210 |
+
from src.mimo_audio.modeling_mimo_audio import MiMoAudioForCausalLM
|
| 211 |
+
from src.mimo_audio_tokenizer import MiMoAudioTokenizer
|
| 212 |
+
from transformers import AutoTokenizer, AutoConfig, GenerationConfig
|
| 213 |
+
|
| 214 |
+
fp8_dir = Path(fp8_dir)
|
| 215 |
+
model_args, tokenizer = _build_args_and_tokenizer(str(fp8_dir))
|
| 216 |
+
|
| 217 |
+
# Build architecture with real init (correct rotary inv_freq), no pretrained shards.
|
| 218 |
+
print("Building architecture (config init) ...")
|
| 219 |
+
cfg = AutoConfig.from_pretrained(str(fp8_dir))
|
| 220 |
+
model = MiMoAudioForCausalLM(cfg, model_args).to(torch.bfloat16)
|
| 221 |
+
|
| 222 |
+
print("Installing FP8 modules ...")
|
| 223 |
+
with torch.no_grad():
|
| 224 |
+
quantize_model(model, verbose=False)
|
| 225 |
+
model = model.to(device)
|
| 226 |
+
|
| 227 |
+
print("Loading FP8 weights ...")
|
| 228 |
+
state = {}
|
| 229 |
+
with safe_open(str(fp8_dir / "model.safetensors"), framework="pt", device=device) as f:
|
| 230 |
+
for key in f.keys():
|
| 231 |
+
state[key] = f.get_tensor(key)
|
| 232 |
+
model.load_state_dict(state, strict=True)
|
| 233 |
+
model.eval()
|
| 234 |
+
|
| 235 |
+
# Wrap in MimoAudio without re-running its __init__ (which would reload weights).
|
| 236 |
+
mimo = object.__new__(MimoAudio)
|
| 237 |
+
mimo.device = device
|
| 238 |
+
mimo.path = str(fp8_dir)
|
| 239 |
+
mimo.mimo_audio_tokenizer_path = tokenizer_path
|
| 240 |
+
mimo.tokenizer = tokenizer
|
| 241 |
+
mimo.padding_idx = int(tokenizer.pad_token_id)
|
| 242 |
+
mimo.sosp_idx = model_args.sosp_idx
|
| 243 |
+
mimo.eosp_idx = model_args.eosp_idx
|
| 244 |
+
mimo.empty_token = model_args.empty_idx
|
| 245 |
+
mimo.sostm_idx = model_args.sostm_idx
|
| 246 |
+
mimo.eostm_idx = model_args.eostm_idx
|
| 247 |
+
mimo.eot_idx = model_args.eot_idx
|
| 248 |
+
mimo.im_start_idx = tokenizer.convert_tokens_to_ids("<|im_start|>")
|
| 249 |
+
mimo.im_end_idx = tokenizer.convert_tokens_to_ids("<|im_end|>")
|
| 250 |
+
mimo.model = model
|
| 251 |
+
mimo.group_size = model.config.group_size
|
| 252 |
+
mimo.audio_channels = model.config.audio_channels
|
| 253 |
+
mimo.delay_pattern = model.config.delay_pattern
|
| 254 |
+
mimo.vocab_size = model.config.vocab_size
|
| 255 |
+
mimo.speech_zeroemb_idx = model.speech_empty_ids
|
| 256 |
+
|
| 257 |
+
from src.mimo_audio.modeling_mimo_audio import MiMoSampler
|
| 258 |
+
mimo.default_global_sampler = MiMoSampler(do_sample=True, temperature=0.6, top_k=50, top_p=0.95)
|
| 259 |
+
mimo.default_local_sampler = MiMoSampler(do_sample=True, temperature=0.9, top_k=50, top_p=0.95)
|
| 260 |
+
mimo.task_sampler_configs = {
|
| 261 |
+
"asr": {"global": MiMoSampler(do_sample=False, temperature=1.0, top_p=1.0),
|
| 262 |
+
"local": MiMoSampler(do_sample=True, temperature=0.9, top_p=0.95)},
|
| 263 |
+
}
|
| 264 |
+
mimo.generate_kwargs = {
|
| 265 |
+
"max_length": 8192,
|
| 266 |
+
"eos_token_id": tokenizer.eos_token_id,
|
| 267 |
+
"pad_token_id": tokenizer.pad_token_id,
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
mimo.mimo_audio_tokenizer = MiMoAudioTokenizer.from_pretrained(tokenizer_path)
|
| 271 |
+
mimo.mimo_audio_tokenizer.eval().bfloat16().to(device)
|
| 272 |
+
from torchaudio.transforms import MelSpectrogram
|
| 273 |
+
tcfg = mimo.mimo_audio_tokenizer.config
|
| 274 |
+
mimo.mel_transform = MelSpectrogram(
|
| 275 |
+
sample_rate=tcfg.sampling_rate, n_fft=tcfg.nfft, hop_length=tcfg.hop_length,
|
| 276 |
+
win_length=tcfg.window_size, f_min=tcfg.fmin, f_max=tcfg.fmax,
|
| 277 |
+
n_mels=tcfg.n_mels, power=1.0, center=True,
|
| 278 |
+
).to(device)
|
| 279 |
+
print("FP8 model ready\n")
|
| 280 |
+
return mimo
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
def main():
|
| 284 |
+
ap = argparse.ArgumentParser()
|
| 285 |
+
ap.add_argument("--model-path", required=True)
|
| 286 |
+
ap.add_argument("--out-dir", default="./MiMo-V2.5-ASR-FP8")
|
| 287 |
+
ap.add_argument("--device", default="cuda")
|
| 288 |
+
ap.add_argument("--quiet", action="store_true")
|
| 289 |
+
args = ap.parse_args()
|
| 290 |
+
run_quantize(args)
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
if __name__ == "__main__":
|
| 294 |
+
main()
|
quantize_fp8_stream.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Streaming CPU FP8 quantizer for MiMo-V2.5-ASR.
|
| 3 |
+
|
| 4 |
+
Avoids loading the full model into RAM and never uses CUDA (works around the lack of
|
| 5 |
+
sm_120 / Blackwell kernels in torch 2.6+cu124). Reads the original safetensors shards,
|
| 6 |
+
quantizes every nn.Linear weight to float8_e4m3fn (per-out-channel absmax), leaves
|
| 7 |
+
embeddings / norms / biases in bf16, and writes a single model.safetensors whose keys
|
| 8 |
+
match the FP8Linear loader (`*.weight_fp8`, `*.weight_scale`).
|
| 9 |
+
"""
|
| 10 |
+
import sys, json, shutil, argparse
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
import torch
|
| 13 |
+
import torch.nn as nn
|
| 14 |
+
from safetensors.torch import save_file, safe_open
|
| 15 |
+
|
| 16 |
+
REPO = Path(__file__).resolve().parent
|
| 17 |
+
sys.path.insert(0, str(REPO))
|
| 18 |
+
from quantize_fp8 import (
|
| 19 |
+
quantize_weight_per_channel, CONFIG_FILES, _build_args_and_tokenizer, FP8_DTYPE,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def linear_weight_names(model_path: str) -> set:
|
| 24 |
+
"""Build the model on meta and collect '<path>.weight' for every nn.Linear."""
|
| 25 |
+
from src.mimo_audio.modeling_mimo_audio import MiMoAudioForCausalLM
|
| 26 |
+
from transformers import AutoConfig
|
| 27 |
+
args, _ = _build_args_and_tokenizer(model_path)
|
| 28 |
+
cfg = AutoConfig.from_pretrained(model_path)
|
| 29 |
+
with torch.device("meta"):
|
| 30 |
+
model = MiMoAudioForCausalLM(cfg, args)
|
| 31 |
+
names = set()
|
| 32 |
+
for name, mod in model.named_modules():
|
| 33 |
+
if isinstance(mod, nn.Linear):
|
| 34 |
+
names.add(name + ".weight")
|
| 35 |
+
return names
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def main():
|
| 39 |
+
ap = argparse.ArgumentParser()
|
| 40 |
+
ap.add_argument("--model-path", required=True)
|
| 41 |
+
ap.add_argument("--out-dir", required=True)
|
| 42 |
+
ap.add_argument("--dry-run", action="store_true")
|
| 43 |
+
a = ap.parse_args()
|
| 44 |
+
mp = Path(a.model_path)
|
| 45 |
+
out = Path(a.out_dir)
|
| 46 |
+
|
| 47 |
+
lin = linear_weight_names(str(mp))
|
| 48 |
+
print(f"quantizable Linear weights: {len(lin)}")
|
| 49 |
+
|
| 50 |
+
idx = json.loads((mp / "model.safetensors.index.json").read_text())
|
| 51 |
+
weight_map = idx["weight_map"]
|
| 52 |
+
shards = {}
|
| 53 |
+
for k, sh in weight_map.items():
|
| 54 |
+
shards.setdefault(sh, []).append(k)
|
| 55 |
+
all_keys = set(weight_map)
|
| 56 |
+
matched = lin & all_keys
|
| 57 |
+
missing = lin - all_keys
|
| 58 |
+
print(f"checkpoint keys: {len(all_keys)} | linear matched: {len(matched)} | linear missing in ckpt: {len(missing)}")
|
| 59 |
+
if missing:
|
| 60 |
+
print(" MISSING (first 10):", sorted(missing)[:10])
|
| 61 |
+
|
| 62 |
+
if a.dry_run:
|
| 63 |
+
# show a few non-linear keys for sanity
|
| 64 |
+
nonlin = sorted(all_keys - lin)
|
| 65 |
+
print("sample NON-linear keys kept as-is:", nonlin[:8])
|
| 66 |
+
print("total params:", len(all_keys), "-> fp8:", len(matched), "kept:", len(all_keys) - len(matched))
|
| 67 |
+
return
|
| 68 |
+
|
| 69 |
+
out.mkdir(parents=True, exist_ok=True)
|
| 70 |
+
new_state = {}
|
| 71 |
+
bytes_before = bytes_after = 0
|
| 72 |
+
conv = 0
|
| 73 |
+
for shard in sorted(shards):
|
| 74 |
+
with safe_open(str(mp / shard), framework="pt", device="cpu") as f:
|
| 75 |
+
for k in shards[shard]:
|
| 76 |
+
t = f.get_tensor(k)
|
| 77 |
+
if k in lin:
|
| 78 |
+
w_fp8, scale = quantize_weight_per_channel(t) # scale [out,1]
|
| 79 |
+
base = k[:-len(".weight")]
|
| 80 |
+
new_state[base + ".weight_fp8"] = w_fp8.contiguous()
|
| 81 |
+
new_state[base + ".weight_scale"] = scale.squeeze(1).contiguous()
|
| 82 |
+
bytes_before += t.numel() * t.element_size()
|
| 83 |
+
bytes_after += w_fp8.numel() + scale.numel() * 4
|
| 84 |
+
conv += 1
|
| 85 |
+
else:
|
| 86 |
+
bytes_before += t.numel() * t.element_size()
|
| 87 |
+
# kept tensors (embeddings/norms/biases): store bf16 to match the
|
| 88 |
+
# bf16 model the FP8Linear loader builds, and to shrink the file.
|
| 89 |
+
if t.is_floating_point():
|
| 90 |
+
t = t.to(torch.bfloat16)
|
| 91 |
+
new_state[k] = t.contiguous()
|
| 92 |
+
bytes_after += t.numel() * t.element_size()
|
| 93 |
+
print(f" done {shard} (running fp8 layers: {conv})")
|
| 94 |
+
|
| 95 |
+
st = out / "model.safetensors"
|
| 96 |
+
save_file(new_state, str(st), metadata={"format": "pt"})
|
| 97 |
+
|
| 98 |
+
copied = []
|
| 99 |
+
for cfg in CONFIG_FILES:
|
| 100 |
+
src = mp / cfg
|
| 101 |
+
if src.exists():
|
| 102 |
+
shutil.copy2(src, out / cfg); copied.append(cfg)
|
| 103 |
+
|
| 104 |
+
ratio = round(bytes_before / max(bytes_after, 1), 3)
|
| 105 |
+
meta = {
|
| 106 |
+
"dtype": "float8_e4m3fn", "weight_scaling": "per_channel_absmax",
|
| 107 |
+
"activation_scaling": "dynamic_per_tensor", "matmul_op": "torch._scaled_mm",
|
| 108 |
+
"output_dtype": "bfloat16", "converted_layers": conv,
|
| 109 |
+
"weight_gb_before": round(bytes_before / 1e9, 3),
|
| 110 |
+
"weight_gb_after": round(bytes_after / 1e9, 3), "compression_ratio": ratio,
|
| 111 |
+
"quantizer": "streaming_cpu",
|
| 112 |
+
}
|
| 113 |
+
(out / "fp8_meta.json").write_text(json.dumps(meta, indent=2))
|
| 114 |
+
gb = st.stat().st_size / 1e9
|
| 115 |
+
print(f"\nOK {st} ({gb:.2f} GB on disk)")
|
| 116 |
+
print(f" {conv} layers -> fp8 | {round(bytes_before/1e9,2)}GB -> {round(bytes_after/1e9,2)}GB ({ratio}x)")
|
| 117 |
+
print(f" copied config: {', '.join(copied)}")
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
if __name__ == "__main__":
|
| 121 |
+
main()
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"additional_special_tokens": [
|
| 3 |
+
"<|im_start|>",
|
| 4 |
+
"<|im_end|>",
|
| 5 |
+
"<|object_ref_start|>",
|
| 6 |
+
"<|object_ref_end|>",
|
| 7 |
+
"<|box_start|>",
|
| 8 |
+
"<|box_end|>",
|
| 9 |
+
"<|quad_start|>",
|
| 10 |
+
"<|quad_end|>",
|
| 11 |
+
"<|vision_start|>",
|
| 12 |
+
"<|vision_end|>",
|
| 13 |
+
"<|vision_pad|>",
|
| 14 |
+
"<|image_pad|>",
|
| 15 |
+
"<|video_pad|>"
|
| 16 |
+
],
|
| 17 |
+
"eos_token": {
|
| 18 |
+
"content": "<|endoftext|>",
|
| 19 |
+
"lstrip": false,
|
| 20 |
+
"normalized": false,
|
| 21 |
+
"rstrip": false,
|
| 22 |
+
"single_word": false
|
| 23 |
+
},
|
| 24 |
+
"pad_token": {
|
| 25 |
+
"content": "<|endoftext|>",
|
| 26 |
+
"lstrip": false,
|
| 27 |
+
"normalized": false,
|
| 28 |
+
"rstrip": false,
|
| 29 |
+
"single_word": false
|
| 30 |
+
}
|
| 31 |
+
}
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d91a78cce6441fd6855038f6764fc5f811ae949d9b89f43ac326cddfe91c66db
|
| 3 |
+
size 11423383
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_bos_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": "<|sosp|>",
|
| 183 |
+
"lstrip": false,
|
| 184 |
+
"normalized": false,
|
| 185 |
+
"rstrip": false,
|
| 186 |
+
"single_word": false,
|
| 187 |
+
"special": true
|
| 188 |
+
},
|
| 189 |
+
"151666": {
|
| 190 |
+
"content": "<|eosp|>",
|
| 191 |
+
"lstrip": false,
|
| 192 |
+
"normalized": false,
|
| 193 |
+
"rstrip": false,
|
| 194 |
+
"single_word": false,
|
| 195 |
+
"special": true
|
| 196 |
+
},
|
| 197 |
+
"151667": {
|
| 198 |
+
"content": "<|empty|>",
|
| 199 |
+
"lstrip": false,
|
| 200 |
+
"normalized": false,
|
| 201 |
+
"rstrip": false,
|
| 202 |
+
"single_word": false,
|
| 203 |
+
"special": true
|
| 204 |
+
},
|
| 205 |
+
"151668": {
|
| 206 |
+
"content": "<|Human|>",
|
| 207 |
+
"lstrip": false,
|
| 208 |
+
"normalized": false,
|
| 209 |
+
"rstrip": false,
|
| 210 |
+
"single_word": false,
|
| 211 |
+
"special": true
|
| 212 |
+
},
|
| 213 |
+
"151669": {
|
| 214 |
+
"content": "<|SpeechLM|>",
|
| 215 |
+
"lstrip": false,
|
| 216 |
+
"normalized": false,
|
| 217 |
+
"rstrip": false,
|
| 218 |
+
"single_word": false,
|
| 219 |
+
"special": true
|
| 220 |
+
},
|
| 221 |
+
"151670": {
|
| 222 |
+
"content": "<|sostm|>",
|
| 223 |
+
"lstrip": false,
|
| 224 |
+
"normalized": false,
|
| 225 |
+
"rstrip": false,
|
| 226 |
+
"single_word": false,
|
| 227 |
+
"special": true
|
| 228 |
+
},
|
| 229 |
+
"151671": {
|
| 230 |
+
"content": "<|eostm|>",
|
| 231 |
+
"lstrip": false,
|
| 232 |
+
"normalized": false,
|
| 233 |
+
"rstrip": false,
|
| 234 |
+
"single_word": false,
|
| 235 |
+
"special": true
|
| 236 |
+
},
|
| 237 |
+
"151672": {
|
| 238 |
+
"content": "<|eot|>",
|
| 239 |
+
"lstrip": false,
|
| 240 |
+
"normalized": false,
|
| 241 |
+
"rstrip": false,
|
| 242 |
+
"single_word": false,
|
| 243 |
+
"special": true
|
| 244 |
+
}
|
| 245 |
+
},
|
| 246 |
+
"additional_special_tokens": [
|
| 247 |
+
"<|im_start|>",
|
| 248 |
+
"<|im_end|>",
|
| 249 |
+
"<|object_ref_start|>",
|
| 250 |
+
"<|object_ref_end|>",
|
| 251 |
+
"<|box_start|>",
|
| 252 |
+
"<|box_end|>",
|
| 253 |
+
"<|quad_start|>",
|
| 254 |
+
"<|quad_end|>",
|
| 255 |
+
"<|vision_start|>",
|
| 256 |
+
"<|vision_end|>",
|
| 257 |
+
"<|vision_pad|>",
|
| 258 |
+
"<|image_pad|>",
|
| 259 |
+
"<|video_pad|>"
|
| 260 |
+
],
|
| 261 |
+
"bos_token": null,
|
| 262 |
+
"clean_up_tokenization_spaces": false,
|
| 263 |
+
"eos_token": "<|im_end|>",
|
| 264 |
+
"errors": "replace",
|
| 265 |
+
"extra_special_tokens": {},
|
| 266 |
+
"model_max_length": 131072,
|
| 267 |
+
"pad_token": "<|endoftext|>",
|
| 268 |
+
"split_special_tokens": false,
|
| 269 |
+
"tokenizer_class": "Qwen2Tokenizer",
|
| 270 |
+
"unk_token": null
|
| 271 |
+
}
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|