Text Generation
Transformers
Safetensors
English
Chinese
mimo_v2
multimodal
vision-language
audio
agent
video-understanding
long-context
conversational
custom_code
fp8
Instructions to use gghfexp/mimo-v2.6-flash-rl with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use gghfexp/mimo-v2.6-flash-rl with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="gghfexp/mimo-v2.6-flash-rl", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("gghfexp/mimo-v2.6-flash-rl", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use gghfexp/mimo-v2.6-flash-rl with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "gghfexp/mimo-v2.6-flash-rl" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gghfexp/mimo-v2.6-flash-rl", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/gghfexp/mimo-v2.6-flash-rl
- SGLang
How to use gghfexp/mimo-v2.6-flash-rl with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "gghfexp/mimo-v2.6-flash-rl" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gghfexp/mimo-v2.6-flash-rl", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "gghfexp/mimo-v2.6-flash-rl" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gghfexp/mimo-v2.6-flash-rl", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use gghfexp/mimo-v2.6-flash-rl with Docker Model Runner:
docker model run hf.co/gghfexp/mimo-v2.6-flash-rl
Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +3 -0
- MiMo_V2_6_technical_report.pdf +3 -0
- README.md +229 -0
- chat_template.jinja +96 -0
- config.json +376 -0
- configuration_mimo_v2.py +247 -0
- generation_config.json +9 -0
- merges.txt +0 -0
- meta.json +1 -0
- model.safetensors.index.json +0 -0
- modeling_mimo_v2.py +1878 -0
- moe_L01.safetensors +3 -0
- moe_L02.safetensors +3 -0
- moe_L03.safetensors +3 -0
- moe_L04.safetensors +3 -0
- moe_L05.safetensors +3 -0
- moe_L06.safetensors +3 -0
- moe_L07.safetensors +3 -0
- moe_L08.safetensors +3 -0
- moe_L09.safetensors +3 -0
- moe_L10.safetensors +3 -0
- moe_L11.safetensors +3 -0
- moe_L12.safetensors +3 -0
- moe_L13.safetensors +3 -0
- moe_L14.safetensors +3 -0
- moe_L15.safetensors +3 -0
- moe_L16.safetensors +3 -0
- moe_L17.safetensors +3 -0
- moe_L18.safetensors +3 -0
- moe_L19.safetensors +3 -0
- moe_L20.safetensors +3 -0
- moe_L21.safetensors +3 -0
- moe_L22.safetensors +3 -0
- moe_L23.safetensors +3 -0
- moe_L24.safetensors +3 -0
- moe_L25.safetensors +3 -0
- moe_L26.safetensors +3 -0
- moe_L27.safetensors +3 -0
- moe_L28.safetensors +3 -0
- moe_L29.safetensors +3 -0
- moe_L30.safetensors +3 -0
- moe_L31.safetensors +3 -0
- moe_L32.safetensors +3 -0
- moe_L33.safetensors +3 -0
- moe_L34.safetensors +3 -0
- moe_L35.safetensors +3 -0
- moe_L36.safetensors +3 -0
- moe_L37.safetensors +3 -0
- moe_L38.safetensors +3 -0
- moe_L39.safetensors +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,6 @@ 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 |
+
MiMo_V2_6_technical_report.pdf filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
assets/architecture.png filter=lfs diff=lfs merge=lfs -text
|
MiMo_V2_6_technical_report.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fb81e6e083801b3358f084ed6be953dc23b0d2e434690f4541d5eae03e01e7af
|
| 3 |
+
size 3046687
|
README.md
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
- zh
|
| 6 |
+
tags:
|
| 7 |
+
- text-generation
|
| 8 |
+
- multimodal
|
| 9 |
+
- vision-language
|
| 10 |
+
- audio
|
| 11 |
+
- agent
|
| 12 |
+
- video-understanding
|
| 13 |
+
- long-context
|
| 14 |
+
- mimo_v2
|
| 15 |
+
- transformers
|
| 16 |
+
library_name: transformers
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
<br/><br/>
|
| 20 |
+
|
| 21 |
+
<div align="center">
|
| 22 |
+
<picture>
|
| 23 |
+
<source srcset="https://github.com/XiaomiMiMo/MiMo/raw/main/figures/Xiaomi_MiMo_darkmode.png?raw=true" media="(prefers-color-scheme: dark)">
|
| 24 |
+
<img src="https://github.com/XiaomiMiMo/MiMo/raw/main/figures/Xiaomi_MiMo.png?raw=true" width="60%" alt="Xiaomi-MiMo" />
|
| 25 |
+
</picture>
|
| 26 |
+
</div>
|
| 27 |
+
|
| 28 |
+
<br/>
|
| 29 |
+
|
| 30 |
+
<div align="center" style="line-height: 1;">
|
| 31 |
+
|
|
| 32 |
+
<a href="https://huggingface.co/XiaomiMiMo/MiMo-V2.6-Flash-RL" target="_blank">🤗 HuggingFace</a>
|
| 33 |
+
|
|
| 34 |
+
<a href="https://mimo.xiaomi.com/mimo-v2-6" target="_blank">📰 Blog </a>
|
| 35 |
+
|
|
| 36 |
+
<a href="https://platform.xiaomimimo.com" target="_blank">🎨 Xiaomi MiMo API Platform </a>
|
| 37 |
+
|
|
| 38 |
+
<a href="https://aistudio.xiaomimimo.com" target="_blank">🗨️ Xiaomi MiMo Studio </a>
|
| 39 |
+
|
|
| 40 |
+
<a href="https://mimo.xiaomimimo.com/desktop/" target="_blank">💻 Xiaomi MiMo Desktop </a>
|
| 41 |
+
|
|
| 42 |
+
</div>
|
| 43 |
+
|
| 44 |
+
<br/>
|
| 45 |
+
|
| 46 |
+
<div align="center" style="line-height: 1.2;">
|
| 47 |
+
<strong>Community</strong><br/>
|
| 48 |
+
<a href="https://huggingface.co/XiaomiMiMo/MiMo-V2.5-Pro/blob/main/assets/wechat.jpg" target="_blank">WeChat Group</a>
|
| 49 |
+
|
|
| 50 |
+
<a href="https://discord.gg/kKC2kNnQEX" target="_blank">Discord</a>
|
| 51 |
+
|
|
| 52 |
+
<a href="https://t.me/+3T-I0pekOVIyNDBl" target="_blank">Telegram</a>
|
| 53 |
+
|
|
| 54 |
+
<a href="https://www.reddit.com/r/XiaomiMiMo_Official/" target="_blank">Reddit</a>
|
| 55 |
+
</div>
|
| 56 |
+
|
| 57 |
+
<br/>
|
| 58 |
+
|
| 59 |
+
# MiMo-V2.6-Flash-RL
|
| 60 |
+
|
| 61 |
+
**Scaling Reinforcement Learning Toward Self-Improvement**
|
| 62 |
+
|
| 63 |
+
<p align="center">
|
| 64 |
+
<a href="https://huggingface.co/XiaomiMiMo/MiMo-V2.6-Flash-RL/blob/main/MiMo_V2_6_technical_report.pdf"><b>Technical Report</b></a>
|
| 65 |
+
</p>
|
| 66 |
+
|
| 67 |
+
## 1. Introduction
|
| 68 |
+
|
| 69 |
+
MiMo-V2.6-Flash-RL is the efficiency-balanced checkpoint of the MiMo-V2.6 series. The series is built to **scale reinforcement learning toward self-improvement** — scaling RL compute, environment diversity, and grader compute together, so the model keeps expanding its capability frontier through exploration and feedback. Key features include:
|
| 70 |
+
|
| 71 |
+
- **Native Omnimodal + Long Horizon**: Text, image, video, and audio in one model; 1M tokens for long repositories, tool traces, and multi-session agent runs.
|
| 72 |
+
- **You Only RL Once**: One mixed RL run across coding, general agents, visual, and cybersecurity — not separate per-domain runs. Tasks and multiple harnesses are mixed in the same batch so capabilities reinforce each other and strategies transfer to harnesses never seen in training.
|
| 73 |
+
- **Scaling RL Compute**: Fully asynchronous Group Relative Policy Optimization (GRPO) on very large batches — 1,568 prompts × 16 rollouts per step, billions of tokens per update.
|
| 74 |
+
- **Groupwise Agentic Grading (Self-Improvement Loop)**: Binary pass/fail cannot rank passing solutions, so the reward signal itself is scaled. An agentic grader compares rollouts *within each group*: **Groupwise Reward Synthesis (GRS)** builds task-specific rubrics offline from contrasting rollouts and fuses rubric quality with test outcomes; **Groupwise Advantage Redistribution (GAR)** ranks passing trajectories online and moves advantage toward higher-quality solutions. Judged against the policy’s own samples, this closes a self-improvement loop and steers toward shorter paths and fewer tokens per task.
|
| 75 |
+
- **Aligned RL**: Cold start from self-correction — the model reflects on and rewrites its own misaligned turns into grounded next steps. Throughout RL, environment hardening, adversarial screening, and verifier cross-checks keep the loop honest against reward hacking.
|
| 76 |
+
- **Multi-Prefix Multi-Teacher On-Policy Distillation (MOPD2)**: After mixed RL, MOPD2 combines autonomous student rollouts with prefix-conditioned single-turn rollouts (Teacher-Prefix and SFT-Prefix), reusing histories from teacher trajectories and SFT demonstrations so decision points train without regenerating preceding turns — extending capabilities to hard-to-verify tasks.
|
| 77 |
+
|
| 78 |
+
## Model Summary
|
| 79 |
+
|
| 80 |
+
- **Architecture**: Sparse MoE (Mixture of Experts), 309B total / 15B activated parameters
|
| 81 |
+
- **Context Length**: 1M tokens
|
| 82 |
+
- **Modalities**: Text, Image, Video, Audio
|
| 83 |
+
- **Vision Encoder**: 681M-param MiMo ViT (28 layers: 24 SWA + 4 Full)
|
| 84 |
+
- **Audio Encoder**: 308M AudioTokenizer + 127M audio patch encoder
|
| 85 |
+
- **Multi-Token Prediction (MTP)**: 5-layer speculative decoder
|
| 86 |
+
|
| 87 |
+

|
| 88 |
+
|
| 89 |
+
*Figure 1. MiMo-V2.6 architecture.*
|
| 90 |
+
|
| 91 |
+
## 2. Downloads
|
| 92 |
+
|
| 93 |
+
| Model | Download |
|
| 94 |
+
| --- | --- |
|
| 95 |
+
| **MiMo-V2.6-Pro-RL** | [🤗 HuggingFace](https://huggingface.co/XiaomiMiMo/MiMo-V2.6-Pro-RL) · [🤖 ModelScope](https://www.modelscope.cn/models/XiaomiMiMo/MiMo-V2.6-Pro-RL) |
|
| 96 |
+
| **MiMo-V2.6-Flash-RL** | [🤗 HuggingFace](https://huggingface.co/XiaomiMiMo/MiMo-V2.6-Flash-RL) · [🤖 ModelScope](https://www.modelscope.cn/models/XiaomiMiMo/MiMo-V2.6-Flash-RL) |
|
| 97 |
+
|
| 98 |
+
## 3. Evaluation Results
|
| 99 |
+
|
| 100 |
+
| Benchmark | MiMo-V2.6 Pro | MiMo-V2.6 Flash | MiMo-V2.5 Pro | Claude Opus 5 | GPT-5.6 Sol | Claude Fable 5 |
|
| 101 |
+
| --- | --- | --- | --- | --- | --- | --- |
|
| 102 |
+
| **Code Agent** | | | | | | |
|
| 103 |
+
| DeepSWE v1.1 | 71.9 | 67.9 | 19.0 | 74.0 | 73.0 | 70.0 |
|
| 104 |
+
| ProgramBench | 26.5 | 26.0 | 12.5 | 37.0 | 25.0 | 33.0 |
|
| 105 |
+
| MiMo Code Bench | 63.2 | 61.2 | 40.4 | 68.6 | 59.3 | - |
|
| 106 |
+
| **General Agent** | | | | | | |
|
| 107 |
+
| AutomationBench v1.0.6 | 53.1 | 52.3 | 16.0 | 50.3 | 45.8 | 46.2 |
|
| 108 |
+
| Toolathlon-Verified | 76.9 | 73.6 | 49.1 | 80.6 | 74.9 | 77.9 |
|
| 109 |
+
| GDPval-AA 2.1 | 1673 | - | 1107 | 1708 | 1588 | 1595 |
|
| 110 |
+
| Agents’ Last Exam | 31.6 | 27.6 | 13.2 | 31.6 | 30.8 | 25.7 |
|
| 111 |
+
| Terminal Bench 4.0 | 34.9 | 28.8 | 1.5 | 49.0 | 39.9 | 42.4 |
|
| 112 |
+
| Terminal Bench 2.1 | 89.9 | 87.6 | 65.2 | 89.1 | 88.8 | 84.3 |
|
| 113 |
+
| OSWorld-Verified | 82.0 | 80.8 | - | 83.4 | 83.0 | 86.0 |
|
| 114 |
+
| JobBench | 62.0 | 61.2 | 25.0 | 65.7 | 45.4 | 57.4 |
|
| 115 |
+
| **Cybersecurity** | | | | | | |
|
| 116 |
+
| CyberGym | 94.0 | 95.1 | 40.0 | - | - | - |
|
| 117 |
+
| MiMo Cyber Bench | 80.2 | 77.2 | 0.0 | - | - | - |
|
| 118 |
+
| ExploitGym | 17.8 | 6.0 | 0.2 | 22.1 | 30.3 | 28.4 |
|
| 119 |
+
| ExploitBench | 47.9 | 25.3 | 16.6 | 70.0 | 78.5 | 78.0 |
|
| 120 |
+
| SEC Bench Pro | 66.3 | 47.5 | 17.7 | - | 79.1 | - |
|
| 121 |
+
| **Visual Agent** | | | | | | |
|
| 122 |
+
| MiMo VisualCoding | 72.3 | 71.5 | - | 70.0 | 73.4 | 69.1 |
|
| 123 |
+
|
| 124 |
+
## 4. Model Architecture
|
| 125 |
+
|
| 126 |
+
### LLM Backbone
|
| 127 |
+
|
| 128 |
+
| Component | MiMo-V2.6-Flash-RL |
|
| 129 |
+
| --- | --- |
|
| 130 |
+
| Layers (Total / SWA / GA) | 48 / 39 / 9 |
|
| 131 |
+
| Hidden Size | 4096 |
|
| 132 |
+
| SWA Heads (Q/KV) | 64 / 8 |
|
| 133 |
+
| GA Heads (Q/KV) | 64 / 4 |
|
| 134 |
+
| Head Dimensions (QK / V) | 192 / 128 |
|
| 135 |
+
| Sliding Window Size | 128 |
|
| 136 |
+
| Routed Experts (Total / Activated) | 256 / 8 |
|
| 137 |
+
| Max Context Length | 1M |
|
| 138 |
+
| MTP / Speculative Decoder | 5 SWA layers, window 1024 |
|
| 139 |
+
|
| 140 |
+
The first Transformer block uses global attention with a dense FFN. Remaining blocks interleave local SWA and GA; both use sparse MoE FFNs without shared experts.
|
| 141 |
+
|
| 142 |
+
### Vision Encoder (MiMo ViT)
|
| 143 |
+
|
| 144 |
+
| Configuration | Value |
|
| 145 |
+
| --- | --- |
|
| 146 |
+
| Layers (Total / SWA / GA) | 28 / 24 / 4 |
|
| 147 |
+
| Hidden Size | 1280 |
|
| 148 |
+
| Attention Heads (Q / KV) | 32 / 8 |
|
| 149 |
+
| Head Dimension | 64 |
|
| 150 |
+
| Patch Size (T × H × W) | 2 × 16 × 16 |
|
| 151 |
+
| Sliding Window (Left / Right) | 64 / 64 |
|
| 152 |
+
| Spatial Merge Size | 2 × 2 |
|
| 153 |
+
| Parameters | 681M |
|
| 154 |
+
|
| 155 |
+
### Audio Encoders
|
| 156 |
+
|
| 157 |
+
AudioTokenizer encoder: 24 layers (12 SWA / 12 GA), hidden 1024, 20 RVQ codebooks, 308M parameters. Audio patch encoder: 6 layers, 127M parameters; four frames per patch (25 Hz → 6.25 Hz).
|
| 158 |
+
|
| 159 |
+
### Speculative Decoder
|
| 160 |
+
|
| 161 |
+
5-layer SWA MTP drafter (DFlash-style). Predicts 7 subsequent tokens per forward pass for parallel verification.
|
| 162 |
+
|
| 163 |
+
## 5. Deployment
|
| 164 |
+
|
| 165 |
+
For best performance, follow the [SGLang MiMo cookbook](https://docs.sglang.io/cookbook/autoregressive/Xiaomi/MiMo-V2.5). Docker image: `lmsysorg/sglang:latest`.
|
| 166 |
+
|
| 167 |
+
### SGLang
|
| 168 |
+
|
| 169 |
+
```bash
|
| 170 |
+
sglang serve \
|
| 171 |
+
--trust-remote-code \
|
| 172 |
+
--model-path XiaomiMiMo/MiMo-V2.6-Flash-RL \
|
| 173 |
+
--tp 8 \
|
| 174 |
+
--dp 2 \
|
| 175 |
+
--enable-dp-attention \
|
| 176 |
+
--enable-dp-lm-head \
|
| 177 |
+
--mm-enable-dp-encoder \
|
| 178 |
+
--mem-fraction-static 0.65 \
|
| 179 |
+
--chunked-prefill-size 16384 \
|
| 180 |
+
--speculative-algorithm EAGLE \
|
| 181 |
+
--speculative-num-steps 3 \
|
| 182 |
+
--speculative-eagle-topk 1 \
|
| 183 |
+
--speculative-num-draft-tokens 4 \
|
| 184 |
+
--enable-multi-layer-eagle \
|
| 185 |
+
--reasoning-parser mimo \
|
| 186 |
+
--tool-call-parser mimo \
|
| 187 |
+
--host 0.0.0.0 \
|
| 188 |
+
--port 30000
|
| 189 |
+
```
|
| 190 |
+
|
| 191 |
+
### vLLM
|
| 192 |
+
|
| 193 |
+
Follow the [vLLM MiMo-V2.5 recipe](https://recipes.vllm.ai/XiaomiMiMo/MiMo-V2.5). Stable vLLM may lag; pre-built image: `docker pull vllm/vllm-openai:mimov25-cu129`.
|
| 194 |
+
|
| 195 |
+
```bash
|
| 196 |
+
vllm serve XiaomiMiMo/MiMo-V2.6-Flash-RL \
|
| 197 |
+
--tensor-parallel-size 4 \
|
| 198 |
+
--trust-remote-code \
|
| 199 |
+
--gpu-memory-utilization 0.95 \
|
| 200 |
+
--max-model-len auto \
|
| 201 |
+
--reasoning-parser mimo \
|
| 202 |
+
--tool-call-parser mimo \
|
| 203 |
+
--enable-auto-tool-choice \
|
| 204 |
+
--generation-config vllm
|
| 205 |
+
```
|
| 206 |
+
|
| 207 |
+
Recommended sampling: `temperature=1.0`, `top_p=0.95`.
|
| 208 |
+
|
| 209 |
+
Also available in AI Studio, MiMo Code, Xiaomi MiMo Desktop, Xiaomi MiMo Open Platform API, and OpenRouter.
|
| 210 |
+
|
| 211 |
+
## Citation
|
| 212 |
+
|
| 213 |
+
```bibtex
|
| 214 |
+
@misc{mimo2026v26flash,
|
| 215 |
+
title={MiMo-V2.6-Flash-RL},
|
| 216 |
+
author={{Xiaomi MiMo Team}},
|
| 217 |
+
year={2026},
|
| 218 |
+
howpublished={\url{https://huggingface.co/XiaomiMiMo/MiMo-V2.6-Flash-RL}},
|
| 219 |
+
}
|
| 220 |
+
```
|
| 221 |
+
|
| 222 |
+
## Contact
|
| 223 |
+
|
| 224 |
+
For questions or feedback, reach us at [mimo@xiaomi.com](mailto:mimo@xiaomi.com) or join our community:
|
| 225 |
+
|
| 226 |
+
- [WeChat Group](https://work.weixin.qq.com/apph5/external_room/join/group_mng?plg_id=c417f99bd9014b5dd894daa8bfe19790&)
|
| 227 |
+
- [Discord](https://discord.gg/WX2R2uNp)
|
| 228 |
+
- [Telegram](https://t.me/+3T-I0pekOVIyNDBl)
|
| 229 |
+
- [Reddit](https://www.reddit.com/r/XiaomiMiMo_Official/)
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- macro render_value(value) -%}
|
| 2 |
+
{%- if value is string -%}
|
| 3 |
+
{{- value -}}
|
| 4 |
+
{%- else -%}
|
| 5 |
+
{{- value | tojson(ensure_ascii=False) -}}
|
| 6 |
+
{%- endif -%}
|
| 7 |
+
{%- endmacro -%}
|
| 8 |
+
|
| 9 |
+
{%- macro render_content(message_content) -%}
|
| 10 |
+
{%- if message_content is string -%}
|
| 11 |
+
{{- message_content -}}
|
| 12 |
+
{%- elif message_content is iterable -%}
|
| 13 |
+
{%- for part in message_content -%}
|
| 14 |
+
{%- if part is not mapping -%}
|
| 15 |
+
{{- part -}}
|
| 16 |
+
{%- elif part['type'] == 'image' or 'image' in part or 'image_url' in part -%}
|
| 17 |
+
{{- '<|vision_start|><|image_pad|><|vision_end|>' -}}
|
| 18 |
+
{%- elif part['type'] == 'audio' or part['type'] == 'input_audio' or 'audio' in part or 'audio_url' in part or 'input_audio' in part -%}
|
| 19 |
+
{{- '<|mimo_audio_start|><|audio_pad|><|mimo_audio_end|>' -}}
|
| 20 |
+
{%- elif part['type'] == 'video' or 'video' in part or 'video_url' in part -%}
|
| 21 |
+
{{- '<|vision_start|><|video_pad|><|vision_end|>' -}}
|
| 22 |
+
{%- elif 'text' in part -%}
|
| 23 |
+
{{- part['text'] -}}
|
| 24 |
+
{%- endif -%}
|
| 25 |
+
{%- endfor -%}
|
| 26 |
+
{%- endif -%}
|
| 27 |
+
{%- endmacro -%}
|
| 28 |
+
|
| 29 |
+
{%- macro render_tools(tools) -%}
|
| 30 |
+
{{- 'You are provided with the following tools:\n\n<tools>' -}}
|
| 31 |
+
{%- for tool in tools -%}
|
| 32 |
+
{{- '\n' ~ (tool | tojson(ensure_ascii=False)) -}}
|
| 33 |
+
{%- endfor -%}
|
| 34 |
+
{{- '\n</tools>' -}}
|
| 35 |
+
{%- endmacro -%}
|
| 36 |
+
|
| 37 |
+
{%- macro render_tool_calls(tool_calls) -%}
|
| 38 |
+
{%- for tool_call in tool_calls -%}
|
| 39 |
+
{%- if tool_call.function is defined -%}
|
| 40 |
+
{%- set tool_call = tool_call.function -%}
|
| 41 |
+
{%- elif tool_call.custom is defined -%}
|
| 42 |
+
{%- set tool_call = tool_call.custom -%}
|
| 43 |
+
{%- endif -%}
|
| 44 |
+
{{- '<tool_call><function=' ~ tool_call.name ~ '>' -}}
|
| 45 |
+
{%- if tool_call.input is defined and tool_call.input is string -%}
|
| 46 |
+
{{- tool_call.input -}}
|
| 47 |
+
{%- elif tool_call.arguments -%}
|
| 48 |
+
{%- if tool_call.arguments is string -%}
|
| 49 |
+
{{- tool_call.arguments -}}
|
| 50 |
+
{%- else -%}
|
| 51 |
+
{%- for args_name, args_value in tool_call.arguments | items -%}
|
| 52 |
+
{{- '<parameter=' ~ args_name ~ '>' ~ render_value(args_value) ~ '</parameter>' -}}
|
| 53 |
+
{%- endfor -%}
|
| 54 |
+
{%- endif -%}
|
| 55 |
+
{%- endif -%}
|
| 56 |
+
{{- '</function></tool_call>' -}}
|
| 57 |
+
{%- endfor -%}
|
| 58 |
+
{%- endmacro -%}
|
| 59 |
+
|
| 60 |
+
{%- macro render_assistant_message(message) -%}
|
| 61 |
+
{%- set content = render_content(message.content) -%}
|
| 62 |
+
{%- set reasoning = message.reasoning_content if message.reasoning_content is string else '' -%}
|
| 63 |
+
{{- '<|im_start|>assistant\n<think>' ~ reasoning ~ '</think>' ~ content -}}
|
| 64 |
+
{%- if message.tool_calls is defined and message.tool_calls is iterable and message.tool_calls | length > 0 -%}
|
| 65 |
+
{{- render_tool_calls(message.tool_calls) -}}
|
| 66 |
+
{%- endif -%}
|
| 67 |
+
{{- '<|im_end|>' -}}
|
| 68 |
+
{%- endmacro -%}
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
{%- if tools is defined and tools is iterable and tools | length > 0 -%}
|
| 72 |
+
{{- '<|im_start|>system\n' ~ render_tools(tools) ~ '<|im_end|>' -}}
|
| 73 |
+
{%- endif -%}
|
| 74 |
+
|
| 75 |
+
{%- for message in messages -%}
|
| 76 |
+
{%- if message.role == 'assistant' -%}
|
| 77 |
+
{{- render_assistant_message(message) -}}
|
| 78 |
+
{%- else -%}
|
| 79 |
+
{%- set body = render_content(message.content) -%}
|
| 80 |
+
{{- '<|im_start|>' ~ message.role ~ '\n' ~ body -}}
|
| 81 |
+
{%- if message.tools is defined and message.tools is iterable and message.tools | length > 0 -%}
|
| 82 |
+
{%- if body -%}
|
| 83 |
+
{{- '\n\n' -}}
|
| 84 |
+
{%- endif -%}
|
| 85 |
+
{{- render_tools(message.tools) -}}
|
| 86 |
+
{%- endif -%}
|
| 87 |
+
{{- '<|im_end|>' -}}
|
| 88 |
+
{%- endif -%}
|
| 89 |
+
{%- endfor -%}
|
| 90 |
+
|
| 91 |
+
{%- if add_generation_prompt -%}
|
| 92 |
+
{{- '<|im_start|>assistant\n' -}}
|
| 93 |
+
{%- if enable_thinking is false -%}
|
| 94 |
+
{{- '<think></think>' -}}
|
| 95 |
+
{%- endif -%}
|
| 96 |
+
{%- endif -%}
|
config.json
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_full_attention_sink_bias": false,
|
| 3 |
+
"add_swa_attention_sink_bias": true,
|
| 4 |
+
"architectures": [
|
| 5 |
+
"MiMoV2ForCausalLM"
|
| 6 |
+
],
|
| 7 |
+
"attention_bias": false,
|
| 8 |
+
"attention_chunk_size": 128,
|
| 9 |
+
"attention_dropout": 0.0,
|
| 10 |
+
"attention_projection_layout": "fused_qkv",
|
| 11 |
+
"attention_value_scale": 0.707,
|
| 12 |
+
"moe_router_dtype": "bfloat16",
|
| 13 |
+
"audio_config": {
|
| 14 |
+
"add_post_norm": true,
|
| 15 |
+
"audio_channels": 20,
|
| 16 |
+
"audio_segment_size": 6000,
|
| 17 |
+
"group_size": 4,
|
| 18 |
+
"input_full_attention": true,
|
| 19 |
+
"input_local_attn_heads": 16,
|
| 20 |
+
"input_local_dim": 1024,
|
| 21 |
+
"input_local_head_dim": 64,
|
| 22 |
+
"input_local_hidden_dropout": 0.0,
|
| 23 |
+
"input_local_intermediate_size": 4096,
|
| 24 |
+
"input_local_layers": 6,
|
| 25 |
+
"out_hidden_size": 4096,
|
| 26 |
+
"partial_rotary_factor": 1.0,
|
| 27 |
+
"projection_layers": 2,
|
| 28 |
+
"rope_theta": 640000,
|
| 29 |
+
"speech_vocab_size": "1280",
|
| 30 |
+
"speech_zeroemb_idx": "1024"
|
| 31 |
+
},
|
| 32 |
+
"audio_end_token_id": 151674,
|
| 33 |
+
"audio_start_token_id": 151673,
|
| 34 |
+
"audio_token_id": 151669,
|
| 35 |
+
"auto_map": {
|
| 36 |
+
"AutoConfig": "configuration_mimo_v2.MiMoV2Config",
|
| 37 |
+
"AutoModel": "modeling_mimo_v2.MiMoV2Model",
|
| 38 |
+
"AutoModelForCausalLM": "modeling_mimo_v2.MiMoV2ForCausalLM"
|
| 39 |
+
},
|
| 40 |
+
"bos_token_id": null,
|
| 41 |
+
"dtype": "bfloat16",
|
| 42 |
+
"eos_token_id": 151645,
|
| 43 |
+
"head_dim": 192,
|
| 44 |
+
"hidden_act": "silu",
|
| 45 |
+
"hidden_size": 4096,
|
| 46 |
+
"hybrid_block_size": null,
|
| 47 |
+
"hybrid_layer_pattern": [
|
| 48 |
+
0,
|
| 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 |
+
1,
|
| 91 |
+
1,
|
| 92 |
+
1,
|
| 93 |
+
1,
|
| 94 |
+
1,
|
| 95 |
+
0
|
| 96 |
+
],
|
| 97 |
+
"image_token_id": 151655,
|
| 98 |
+
"initializer_range": 0.02,
|
| 99 |
+
"intermediate_size": 16384,
|
| 100 |
+
"layernorm_epsilon": 1e-06,
|
| 101 |
+
"max_position_embeddings": 1048576,
|
| 102 |
+
"model_type": "mimo_v2",
|
| 103 |
+
"moe_intermediate_size": 2048,
|
| 104 |
+
"moe_layer_freq": [
|
| 105 |
+
0,
|
| 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 |
+
1,
|
| 148 |
+
1,
|
| 149 |
+
1,
|
| 150 |
+
1,
|
| 151 |
+
1,
|
| 152 |
+
1
|
| 153 |
+
],
|
| 154 |
+
"n_group": 1,
|
| 155 |
+
"n_routed_experts": 256,
|
| 156 |
+
"n_shared_experts": null,
|
| 157 |
+
"norm_topk_prob": true,
|
| 158 |
+
"num_attention_heads": 64,
|
| 159 |
+
"num_experts_per_tok": 8,
|
| 160 |
+
"num_hidden_layers": 48,
|
| 161 |
+
"num_key_value_heads": 4,
|
| 162 |
+
"num_nextn_predict_layers": 3,
|
| 163 |
+
"pad_token_id": 151643,
|
| 164 |
+
"partial_rotary_factor": 0.334,
|
| 165 |
+
"processor_config": {
|
| 166 |
+
"audio_avg_pooler": 2,
|
| 167 |
+
"audio_channels": 20,
|
| 168 |
+
"audio_end_token_id": 151674,
|
| 169 |
+
"audio_fmax": null,
|
| 170 |
+
"audio_fmin": 0,
|
| 171 |
+
"audio_group_size": 4,
|
| 172 |
+
"audio_hop_length": 240,
|
| 173 |
+
"audio_input_id_per_second": 25.0,
|
| 174 |
+
"audio_kernel_size": 3,
|
| 175 |
+
"audio_n_mels": 128,
|
| 176 |
+
"audio_nfft": 960,
|
| 177 |
+
"audio_sampling_rate": 24000,
|
| 178 |
+
"audio_segment_size": 6000,
|
| 179 |
+
"audio_start_token_id": 151673,
|
| 180 |
+
"audio_stride_size": 2,
|
| 181 |
+
"audio_token_id": 151669,
|
| 182 |
+
"audio_window_size": 960,
|
| 183 |
+
"audio_zeroemb_idx": [
|
| 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 |
+
1024,
|
| 198 |
+
1024,
|
| 199 |
+
1024,
|
| 200 |
+
1024,
|
| 201 |
+
1024,
|
| 202 |
+
1024,
|
| 203 |
+
1024
|
| 204 |
+
],
|
| 205 |
+
"fps": 1.0,
|
| 206 |
+
"image_max_pixels": 8388608,
|
| 207 |
+
"image_min_pixels": 8192,
|
| 208 |
+
"image_token_id": 151655,
|
| 209 |
+
"max_frames": 3600,
|
| 210 |
+
"merge_size": 2,
|
| 211 |
+
"min_frames": null,
|
| 212 |
+
"num_frames": null,
|
| 213 |
+
"pad_token_id": 151643,
|
| 214 |
+
"patch_size": 16,
|
| 215 |
+
"rope_type": "rope",
|
| 216 |
+
"temporal_compression_ratio": 1,
|
| 217 |
+
"temporal_patch_size": 2,
|
| 218 |
+
"use_per_grid_t_timestamps": false,
|
| 219 |
+
"use_video_timestamps": true,
|
| 220 |
+
"video_audio_interleave_length": 0.0,
|
| 221 |
+
"video_end_token_id": 151671,
|
| 222 |
+
"video_max_pixels": 8388608,
|
| 223 |
+
"video_min_pixels": 8192,
|
| 224 |
+
"video_process_num_threads": 16,
|
| 225 |
+
"video_start_token_id": 151670,
|
| 226 |
+
"video_token_id": 151656,
|
| 227 |
+
"video_tokens_per_second": 2,
|
| 228 |
+
"video_total_max_pixels": 268435456,
|
| 229 |
+
"vision_end_token_id": 151653,
|
| 230 |
+
"vision_start_token_id": 151652
|
| 231 |
+
},
|
| 232 |
+
"quantization_config": {
|
| 233 |
+
"activation_scheme": "dynamic",
|
| 234 |
+
"fmt": "e4m3",
|
| 235 |
+
"ignored_layers": [
|
| 236 |
+
"model.layers.0.self_attn.o_proj",
|
| 237 |
+
"model.layers.1.self_attn.o_proj",
|
| 238 |
+
"model.layers.10.self_attn.o_proj",
|
| 239 |
+
"model.layers.11.self_attn.o_proj",
|
| 240 |
+
"model.layers.12.self_attn.o_proj",
|
| 241 |
+
"model.layers.13.self_attn.o_proj",
|
| 242 |
+
"model.layers.14.self_attn.o_proj",
|
| 243 |
+
"model.layers.15.self_attn.o_proj",
|
| 244 |
+
"model.layers.16.self_attn.o_proj",
|
| 245 |
+
"model.layers.17.self_attn.o_proj",
|
| 246 |
+
"model.layers.18.self_attn.o_proj",
|
| 247 |
+
"model.layers.19.self_attn.o_proj",
|
| 248 |
+
"model.layers.2.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.3.self_attn.o_proj",
|
| 260 |
+
"model.layers.30.self_attn.o_proj",
|
| 261 |
+
"model.layers.31.self_attn.o_proj",
|
| 262 |
+
"model.layers.32.self_attn.o_proj",
|
| 263 |
+
"model.layers.33.self_attn.o_proj",
|
| 264 |
+
"model.layers.34.self_attn.o_proj",
|
| 265 |
+
"model.layers.35.self_attn.o_proj",
|
| 266 |
+
"model.layers.36.self_attn.o_proj",
|
| 267 |
+
"model.layers.37.self_attn.o_proj",
|
| 268 |
+
"model.layers.38.self_attn.o_proj",
|
| 269 |
+
"model.layers.39.self_attn.o_proj",
|
| 270 |
+
"model.layers.4.self_attn.o_proj",
|
| 271 |
+
"model.layers.40.self_attn.o_proj",
|
| 272 |
+
"model.layers.41.self_attn.o_proj",
|
| 273 |
+
"model.layers.42.self_attn.o_proj",
|
| 274 |
+
"model.layers.43.self_attn.o_proj",
|
| 275 |
+
"model.layers.44.self_attn.o_proj",
|
| 276 |
+
"model.layers.45.self_attn.o_proj",
|
| 277 |
+
"model.layers.46.self_attn.o_proj",
|
| 278 |
+
"model.layers.47.self_attn.o_proj",
|
| 279 |
+
"model.layers.5.self_attn.o_proj",
|
| 280 |
+
"model.layers.6.self_attn.o_proj",
|
| 281 |
+
"model.layers.7.self_attn.o_proj",
|
| 282 |
+
"model.layers.8.self_attn.o_proj",
|
| 283 |
+
"model.layers.9.self_attn.o_proj",
|
| 284 |
+
"model.decoder.self_attn.o_proj"
|
| 285 |
+
],
|
| 286 |
+
"mxfp4_block_size": 32,
|
| 287 |
+
"quant_method": "fp8",
|
| 288 |
+
"store_dtype": "mxfp4",
|
| 289 |
+
"weight_block_size": [
|
| 290 |
+
128,
|
| 291 |
+
128
|
| 292 |
+
]
|
| 293 |
+
},
|
| 294 |
+
"rope_parameters": {
|
| 295 |
+
"partial_rotary_factor": 0.334,
|
| 296 |
+
"rope_theta": 10000000.0,
|
| 297 |
+
"rope_type": "default",
|
| 298 |
+
"type": "default"
|
| 299 |
+
},
|
| 300 |
+
"rope_theta": 10000000.0,
|
| 301 |
+
"routed_scaling_factor": null,
|
| 302 |
+
"scoring_func": "sigmoid",
|
| 303 |
+
"sliding_window": 128,
|
| 304 |
+
"sliding_window_size": 128,
|
| 305 |
+
"swa_head_dim": 192,
|
| 306 |
+
"swa_num_attention_heads": 64,
|
| 307 |
+
"swa_num_key_value_heads": 8,
|
| 308 |
+
"swa_rope_theta": 10000.0,
|
| 309 |
+
"swa_v_head_dim": 128,
|
| 310 |
+
"tie_word_embeddings": false,
|
| 311 |
+
"topk_group": 1,
|
| 312 |
+
"topk_method": "noaux_tc",
|
| 313 |
+
"transformers_version": "5.3.0",
|
| 314 |
+
"use_cache": true,
|
| 315 |
+
"v_head_dim": 128,
|
| 316 |
+
"video_token_id": 151656,
|
| 317 |
+
"vision_config": {
|
| 318 |
+
"depth": 28,
|
| 319 |
+
"fullatt_block_indexes": [
|
| 320 |
+
0,
|
| 321 |
+
9,
|
| 322 |
+
18,
|
| 323 |
+
27
|
| 324 |
+
],
|
| 325 |
+
"hidden_act": "silu",
|
| 326 |
+
"hidden_size": 1280,
|
| 327 |
+
"in_chans": 3,
|
| 328 |
+
"intermediate_size": 4608,
|
| 329 |
+
"num_heads": 32,
|
| 330 |
+
"num_key_value_heads": 8,
|
| 331 |
+
"num_query_groups": 4,
|
| 332 |
+
"out_hidden_size": 4096,
|
| 333 |
+
"patch_size": 16,
|
| 334 |
+
"spatial_merge_size": 2,
|
| 335 |
+
"spatial_patch_size": 16,
|
| 336 |
+
"temporal_patch_size": 2,
|
| 337 |
+
"tokens_per_second": 2,
|
| 338 |
+
"use_sink": true,
|
| 339 |
+
"visual_token_window_size": 64,
|
| 340 |
+
"vit_window_attn_types": [
|
| 341 |
+
-1,
|
| 342 |
+
0,
|
| 343 |
+
0,
|
| 344 |
+
0,
|
| 345 |
+
0,
|
| 346 |
+
1,
|
| 347 |
+
1,
|
| 348 |
+
1,
|
| 349 |
+
1,
|
| 350 |
+
-1,
|
| 351 |
+
0,
|
| 352 |
+
0,
|
| 353 |
+
0,
|
| 354 |
+
0,
|
| 355 |
+
1,
|
| 356 |
+
1,
|
| 357 |
+
1,
|
| 358 |
+
1,
|
| 359 |
+
-1,
|
| 360 |
+
0,
|
| 361 |
+
0,
|
| 362 |
+
0,
|
| 363 |
+
0,
|
| 364 |
+
1,
|
| 365 |
+
1,
|
| 366 |
+
1,
|
| 367 |
+
1,
|
| 368 |
+
-1
|
| 369 |
+
],
|
| 370 |
+
"window_size": 128
|
| 371 |
+
},
|
| 372 |
+
"vision_end_token_id": 151653,
|
| 373 |
+
"vision_model_type": "mimovl",
|
| 374 |
+
"vision_start_token_id": 151652,
|
| 375 |
+
"vocab_size": 152576
|
| 376 |
+
}
|
configuration_mimo_v2.py
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 copy import deepcopy
|
| 19 |
+
|
| 20 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 21 |
+
from transformers.modeling_rope_utils import rope_config_validation
|
| 22 |
+
from transformers.utils import logging
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
logger = logging.get_logger(__name__)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
_MIMOV2_ATTENTION_PROJECTION_LAYOUTS = {"split", "fused_qkv"}
|
| 29 |
+
|
| 30 |
+
_MIMOV2_SPLIT_TP_PLAN = {
|
| 31 |
+
"layers.*.self_attn.q_proj": "colwise",
|
| 32 |
+
"layers.*.self_attn.k_proj": "colwise",
|
| 33 |
+
"layers.*.self_attn.v_proj": "colwise",
|
| 34 |
+
"layers.*.self_attn.o_proj": "rowwise",
|
| 35 |
+
"layers.*.mlp.gate_proj": "colwise",
|
| 36 |
+
"layers.*.mlp.up_proj": "colwise",
|
| 37 |
+
"layers.*.mlp.down_proj": "rowwise",
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
_MIMOV2_FUSED_QKV_TP_PLAN = {
|
| 41 |
+
"layers.*.self_attn.qkv_proj": "colwise",
|
| 42 |
+
"layers.*.self_attn.o_proj": "rowwise",
|
| 43 |
+
"layers.*.mlp.gate_proj": "colwise",
|
| 44 |
+
"layers.*.mlp.up_proj": "colwise",
|
| 45 |
+
"layers.*.mlp.down_proj": "rowwise",
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
_MIMOV2_PP_PLAN = {
|
| 49 |
+
"embed_tokens": (["input_ids"], ["inputs_embeds"]),
|
| 50 |
+
"layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
|
| 51 |
+
"norm": (["hidden_states"], ["hidden_states"]),
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def _to_plain_dict(value):
|
| 56 |
+
if value is None:
|
| 57 |
+
return {}
|
| 58 |
+
if isinstance(value, dict):
|
| 59 |
+
return deepcopy(value)
|
| 60 |
+
if hasattr(value, "to_dict"):
|
| 61 |
+
return deepcopy(value.to_dict())
|
| 62 |
+
if hasattr(value, "__dict__"):
|
| 63 |
+
return deepcopy(vars(value))
|
| 64 |
+
raise TypeError(f"Unsupported config value type: {type(value)!r}")
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
class MiMoV2Config(PretrainedConfig):
|
| 68 |
+
|
| 69 |
+
model_type = "mimo_v2"
|
| 70 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 71 |
+
|
| 72 |
+
base_model_tp_plan = _MIMOV2_SPLIT_TP_PLAN
|
| 73 |
+
base_model_pp_plan = _MIMOV2_PP_PLAN
|
| 74 |
+
|
| 75 |
+
attribute_map = {
|
| 76 |
+
"num_local_experts": "n_routed_experts",
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
def __init__(
|
| 80 |
+
self,
|
| 81 |
+
vocab_size=151936,
|
| 82 |
+
hidden_size=4096,
|
| 83 |
+
intermediate_size=22016,
|
| 84 |
+
num_hidden_layers=32,
|
| 85 |
+
num_attention_heads=32,
|
| 86 |
+
num_key_value_heads=32,
|
| 87 |
+
hidden_act="silu",
|
| 88 |
+
max_position_embeddings=32768,
|
| 89 |
+
initializer_range=0.02,
|
| 90 |
+
layernorm_epsilon=1e-6,
|
| 91 |
+
use_cache=True,
|
| 92 |
+
tie_word_embeddings=False,
|
| 93 |
+
rope_theta=10000.0,
|
| 94 |
+
rope_scaling=None,
|
| 95 |
+
attention_dropout=0.0,
|
| 96 |
+
attention_bias=False,
|
| 97 |
+
attention_value_scale=None,
|
| 98 |
+
head_dim=None,
|
| 99 |
+
v_head_dim=None,
|
| 100 |
+
swa_num_attention_heads=None,
|
| 101 |
+
swa_num_key_value_heads=None,
|
| 102 |
+
swa_head_dim=None,
|
| 103 |
+
swa_v_head_dim=None,
|
| 104 |
+
swa_rope_theta=None,
|
| 105 |
+
sliding_window=None,
|
| 106 |
+
sliding_window_size=None,
|
| 107 |
+
add_full_attention_sink_bias=False,
|
| 108 |
+
add_swa_attention_sink_bias=False,
|
| 109 |
+
hybrid_block_size=None,
|
| 110 |
+
hybrid_layer_pattern=None,
|
| 111 |
+
partial_rotary_factor=1.0,
|
| 112 |
+
n_routed_experts=None,
|
| 113 |
+
moe_intermediate_size=None,
|
| 114 |
+
num_experts_per_tok=None,
|
| 115 |
+
routed_scaling_factor=None,
|
| 116 |
+
scoring_func="sigmoid",
|
| 117 |
+
topk_method="noaux_tc",
|
| 118 |
+
n_group=None,
|
| 119 |
+
topk_group=None,
|
| 120 |
+
norm_topk_prob=True,
|
| 121 |
+
moe_layer_freq=None,
|
| 122 |
+
attention_projection_layout="split",
|
| 123 |
+
vision_config=None,
|
| 124 |
+
audio_config=None,
|
| 125 |
+
processor_config=None,
|
| 126 |
+
image_token_id=None,
|
| 127 |
+
video_token_id=None,
|
| 128 |
+
vision_start_token_id=None,
|
| 129 |
+
vision_end_token_id=None,
|
| 130 |
+
vision_model_type=None,
|
| 131 |
+
**kwargs,
|
| 132 |
+
):
|
| 133 |
+
rope_parameters = kwargs.pop("rope_parameters", None)
|
| 134 |
+
if rope_scaling is None and rope_parameters is not None:
|
| 135 |
+
rope_scaling = rope_parameters
|
| 136 |
+
|
| 137 |
+
if attention_projection_layout is None:
|
| 138 |
+
attention_projection_layout = "split"
|
| 139 |
+
if attention_projection_layout not in _MIMOV2_ATTENTION_PROJECTION_LAYOUTS:
|
| 140 |
+
raise ValueError(f"Unsupported MiMoV2 attention projection layout: {attention_projection_layout}")
|
| 141 |
+
|
| 142 |
+
self.attention_projection_layout = attention_projection_layout
|
| 143 |
+
self.base_model_tp_plan = (
|
| 144 |
+
_MIMOV2_FUSED_QKV_TP_PLAN.copy()
|
| 145 |
+
if attention_projection_layout == "fused_qkv"
|
| 146 |
+
else _MIMOV2_SPLIT_TP_PLAN.copy()
|
| 147 |
+
)
|
| 148 |
+
self.base_model_pp_plan = _MIMOV2_PP_PLAN.copy()
|
| 149 |
+
|
| 150 |
+
self.vocab_size = vocab_size
|
| 151 |
+
self.max_position_embeddings = max_position_embeddings
|
| 152 |
+
self.hidden_size = hidden_size
|
| 153 |
+
self.intermediate_size = intermediate_size
|
| 154 |
+
self.num_hidden_layers = num_hidden_layers
|
| 155 |
+
self.num_attention_heads = num_attention_heads
|
| 156 |
+
|
| 157 |
+
if num_key_value_heads is None:
|
| 158 |
+
num_key_value_heads = num_attention_heads
|
| 159 |
+
if num_attention_heads % num_key_value_heads != 0:
|
| 160 |
+
raise ValueError("num_attention_heads must be divisible by num_key_value_heads")
|
| 161 |
+
|
| 162 |
+
self.num_key_value_heads = num_key_value_heads
|
| 163 |
+
self.hidden_act = hidden_act
|
| 164 |
+
self.initializer_range = initializer_range
|
| 165 |
+
self.layernorm_epsilon = layernorm_epsilon
|
| 166 |
+
self.use_cache = use_cache
|
| 167 |
+
self.rope_theta = rope_theta
|
| 168 |
+
self.rope_scaling = rope_scaling
|
| 169 |
+
self.attention_dropout = attention_dropout
|
| 170 |
+
self.attention_bias = attention_bias
|
| 171 |
+
self.attention_value_scale = attention_value_scale
|
| 172 |
+
|
| 173 |
+
self.head_dim = head_dim if head_dim is not None else hidden_size // num_attention_heads
|
| 174 |
+
self.v_head_dim = v_head_dim if v_head_dim is not None else self.head_dim
|
| 175 |
+
self.swa_num_attention_heads = (
|
| 176 |
+
swa_num_attention_heads if swa_num_attention_heads is not None else num_attention_heads
|
| 177 |
+
)
|
| 178 |
+
self.swa_num_key_value_heads = (
|
| 179 |
+
swa_num_key_value_heads if swa_num_key_value_heads is not None else num_key_value_heads
|
| 180 |
+
)
|
| 181 |
+
if self.swa_num_attention_heads % self.swa_num_key_value_heads != 0:
|
| 182 |
+
raise ValueError("swa_num_attention_heads must be divisible by swa_num_key_value_heads")
|
| 183 |
+
self.swa_head_dim = swa_head_dim if swa_head_dim is not None else self.head_dim
|
| 184 |
+
self.swa_v_head_dim = swa_v_head_dim if swa_v_head_dim is not None else self.swa_head_dim
|
| 185 |
+
self.swa_rope_theta = swa_rope_theta if swa_rope_theta is not None else rope_theta
|
| 186 |
+
|
| 187 |
+
if sliding_window is None:
|
| 188 |
+
sliding_window = sliding_window_size
|
| 189 |
+
self.sliding_window = sliding_window
|
| 190 |
+
self.sliding_window_size = sliding_window_size if sliding_window_size is not None else sliding_window
|
| 191 |
+
self.add_full_attention_sink_bias = add_full_attention_sink_bias
|
| 192 |
+
self.add_swa_attention_sink_bias = add_swa_attention_sink_bias
|
| 193 |
+
|
| 194 |
+
if hybrid_block_size is not None and hybrid_layer_pattern is None:
|
| 195 |
+
hybrid_layer_pattern = [0 if ((i + 1) % hybrid_block_size == 0) else 1 for i in range(num_hidden_layers)]
|
| 196 |
+
elif hybrid_layer_pattern is None:
|
| 197 |
+
hybrid_layer_pattern = [0] * num_hidden_layers
|
| 198 |
+
if len(hybrid_layer_pattern) != num_hidden_layers:
|
| 199 |
+
raise ValueError("hybrid_layer_pattern length must match num_hidden_layers")
|
| 200 |
+
self.hybrid_block_size = hybrid_block_size
|
| 201 |
+
self.hybrid_layer_pattern = hybrid_layer_pattern
|
| 202 |
+
|
| 203 |
+
self.partial_rotary_factor = partial_rotary_factor
|
| 204 |
+
|
| 205 |
+
self.n_routed_experts = n_routed_experts
|
| 206 |
+
self.moe_intermediate_size = moe_intermediate_size if moe_intermediate_size is not None else intermediate_size
|
| 207 |
+
self.num_experts_per_tok = num_experts_per_tok
|
| 208 |
+
self.routed_scaling_factor = routed_scaling_factor
|
| 209 |
+
self.scoring_func = scoring_func
|
| 210 |
+
self.topk_method = topk_method
|
| 211 |
+
self.n_group = n_group
|
| 212 |
+
self.topk_group = topk_group
|
| 213 |
+
self.norm_topk_prob = norm_topk_prob
|
| 214 |
+
if isinstance(moe_layer_freq, int):
|
| 215 |
+
moe_layer_freq = [moe_layer_freq > 0 and i % moe_layer_freq == 0 for i in range(num_hidden_layers)]
|
| 216 |
+
elif moe_layer_freq is None:
|
| 217 |
+
moe_layer_freq = [False] * num_hidden_layers
|
| 218 |
+
if len(moe_layer_freq) != num_hidden_layers:
|
| 219 |
+
raise ValueError("moe_layer_freq length must match num_hidden_layers")
|
| 220 |
+
self.moe_layer_freq = moe_layer_freq
|
| 221 |
+
|
| 222 |
+
self.vision_config = _to_plain_dict(vision_config)
|
| 223 |
+
self.audio_config = _to_plain_dict(audio_config)
|
| 224 |
+
self.processor_config = _to_plain_dict(processor_config)
|
| 225 |
+
self.image_token_id = image_token_id
|
| 226 |
+
self.video_token_id = video_token_id
|
| 227 |
+
self.vision_start_token_id = vision_start_token_id
|
| 228 |
+
self.vision_end_token_id = vision_end_token_id
|
| 229 |
+
self.vision_model_type = vision_model_type
|
| 230 |
+
self.audio_token_id = self.processor_config.get("audio_token_id", None) if self.processor_config else None
|
| 231 |
+
self.audio_start_token_id = (
|
| 232 |
+
self.processor_config.get("audio_start_token_id", None) if self.processor_config else None
|
| 233 |
+
)
|
| 234 |
+
self.audio_end_token_id = (
|
| 235 |
+
self.processor_config.get("audio_end_token_id", None) if self.processor_config else None
|
| 236 |
+
)
|
| 237 |
+
|
| 238 |
+
if self.rope_scaling is not None and "type" in self.rope_scaling:
|
| 239 |
+
self.rope_scaling["rope_type"] = self.rope_scaling["type"]
|
| 240 |
+
rope_config_validation(self)
|
| 241 |
+
|
| 242 |
+
super().__init__(
|
| 243 |
+
tie_word_embeddings=tie_word_embeddings,
|
| 244 |
+
**kwargs,
|
| 245 |
+
)
|
| 246 |
+
|
| 247 |
+
__all__ = ["MiMoV2Config"]
|
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
|
|
|
meta.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"format": "mimo-conv-v1", "repo": "XiaomiMiMo/MiMo-V2.6-Flash-RL", "created_utc": "2026-10-11T23:59:51Z", "n_layers": 48, "d_model": 4096, "n_experts": 256, "moe_intermediate": 2048, "std": {"file": "std.safetensors", "tensors": {"model.embed_tokens.weight": ["bfloat16", [152576, 4096], "1f82cd528be39df919b6d8798fb7c07f037b80519d26a88c7103edd7caa6d7b6"], "model.layers.0.self_attn.qkv_proj.weight": ["bfloat16", [13568, 4096], "a33387b149b66e108e46977156538c81c60ea1772d84da0f8dc117770ea24c8b"], "model.layers.0.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "6f3baeab0d2786cfa293326636f5f2ede098a426b8e9e08b391943fa56ef8eef"], "model.layers.0.mlp.gate_proj.weight": ["bfloat16", [16384, 4096], "203d2cb182f8aca1a4939fbe5cee5ef307ad7d40679ec3ae52a25d803214272c"], "model.layers.0.mlp.up_proj.weight": ["bfloat16", [16384, 4096], "990f9efa104460eb5e6e6a8465cd5e8baf782d64fd0bd7e865da5ac82a6a0aaf"], "model.layers.0.mlp.down_proj.weight": ["bfloat16", [4096, 16384], "e178f42c12110b98965b9e95aaca9a1b68c488ac59e83ec3868b0c106602d3bf"], "model.layers.0.input_layernorm.weight": ["bfloat16", [4096], "7c74734c28100cb789c6e79309d03a281fbf79c185e7bd235a2a405e70626fdd"], "model.layers.0.post_attention_layernorm.weight": ["bfloat16", [4096], "93867a16429c8e0153f8c9e30cadd0763103fcd787647f909b3198b6c9a3f1b5"], "model.layers.1.self_attn.attention_sink_bias": ["bfloat16", [64], "46426566a1f1aa78b85cff1d6d9846bc02bb154c31974367a8df1dd9cbd0c531"], "model.layers.1.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "f19f86a7b1779218526fe69b2f4e9fa7d5b106baf995d8c7fa23c1c8a372379b"], "model.layers.1.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "9b138626fd4ecd18f338897a5920aee6c3f34e97314f659019c3e7657a96394f"], "model.layers.1.mlp.gate.weight": ["float32", [256, 4096], "aa341a3bcc3dfdbb64db23d47df60ece51acaeaa6b1316fa77ca68a874b8705c"], "model.layers.1.mlp.gate.e_score_correction_bias": ["float32", [256], "0d5cde5ee97785f2379b4234eff4b7a46fdc824864b62671c50b084bd97943c7"], "model.layers.1.input_layernorm.weight": ["bfloat16", [4096], "073e62cb5bf3d7147e3f7659ddf042e5322e92fe359d9a70968aaf62086e9401"], "model.layers.1.post_attention_layernorm.weight": ["bfloat16", [4096], "982eb16b00429c7b7bb526c80ad30d88a0e3f09ff1d3038027ce2e3e7699096b"], "model.layers.2.self_attn.attention_sink_bias": ["bfloat16", [64], "c63c33f8e5b1312a63ffe8270ee1f9151f1544146e3963d678c928c0ac260f79"], "model.layers.2.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "efc0f6c366441371f02501258fde2b3c29d5a6842fc10f71f7df886d641a0f82"], "model.layers.2.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "cb2a70316cc2e75a55481ed694910a6c13094cd5acb5880c139f21e65b0b0716"], "model.layers.2.mlp.gate.weight": ["float32", [256, 4096], "f023794bed0cd458d35d3981354acb7484eaa378a1ed21ac8ea44d55eeb3a884"], "model.layers.2.mlp.gate.e_score_correction_bias": ["float32", [256], "eee96b94a5daa405363a03576cdf57ce4b90c6db0cfca02e52fd6aee0872335f"], "model.layers.2.input_layernorm.weight": ["bfloat16", [4096], "31ae58fac9f0444546b311d382bb8771f8a93545bc4830a7fc101722dccdad18"], "model.layers.2.post_attention_layernorm.weight": ["bfloat16", [4096], "e81a7641617e57829371e3e9a987f2b967ec2acf50ed23b8e19285a28929a67a"], "model.layers.3.self_attn.attention_sink_bias": ["bfloat16", [64], "5a45518700b8722ac66ee5efd4aa0af5d28c26d0bb8c357caf86507842f9a5c6"], "model.layers.3.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "177aac1f42dd812ef2469d241084960edffc2afc41030f55c7e10d5d47e823e4"], "model.layers.3.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "ae5d923e2b838a1fa9c929a84f8bb7c9ad6a61644f28662b6a155eaac072550e"], "model.layers.3.mlp.gate.weight": ["float32", [256, 4096], "bf519b4107156e96b3fb7accaf324ef911f12fe14891fbaf6493211f440c6198"], "model.layers.3.mlp.gate.e_score_correction_bias": ["float32", [256], "e2e9f06a621de7643bccefa02eb579456d64c4700172cec597bd644ac62588ad"], "model.layers.3.input_layernorm.weight": ["bfloat16", [4096], "83d9db6eb1f0bb39a72335cb56bae29dc293888e119c40e64e19066a63d09510"], "model.layers.3.post_attention_layernorm.weight": ["bfloat16", [4096], "98784f7a6d41daea853d256c001602f36f60c48fa01bc022d3ca6499d5c01a48"], "model.layers.4.self_attn.attention_sink_bias": ["bfloat16", [64], "089739bf5c63e1b9f3970355813cc6aa4f08e0c1befc880426f81243a0f55547"], "model.layers.4.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "1c7de8ceb67d3bd7d31405db85132820820bf709581bbe60cef32b5bb96b180e"], "model.layers.4.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "9ddfccb05e8f1c0289715bad1277a8c7d86b286eea6dababa35d620ecfb3cc96"], "model.layers.4.mlp.gate.weight": ["float32", [256, 4096], "bd8f923d94cc3c9b3b2f10d2178cf9475cdf1dc62ac02bb8512198c387e04a77"], "model.layers.4.mlp.gate.e_score_correction_bias": ["float32", [256], "7685c5ed1fdce4a41a68c415347512604cff1ce4b732a8063b76a0b2d3023fbe"], "model.layers.4.input_layernorm.weight": ["bfloat16", [4096], "4891a0099a722eb32c3743befa55eaed4fa4c7eaad4032ac99a7012abc72f292"], "model.layers.4.post_attention_layernorm.weight": ["bfloat16", [4096], "1b75510d86bc88aae80df820da7e44aa2b82cec49f8e577e65ee73a0727f613a"], "model.layers.5.self_attn.qkv_proj.weight": ["bfloat16", [13568, 4096], "2b5b053b8ed827d36c13eb1bed0c91d7284706411ee131979cb59d195c37d06f"], "model.layers.5.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "a6398630d3dc99ca56d40e8284aeda3cb34912d276923bb141c2d7922605c4c2"], "model.layers.5.mlp.gate.weight": ["float32", [256, 4096], "9b6effa6dbf9e692c2c9e43df6a869ed70181685f3ab6cca080063a9bff2cc30"], "model.layers.5.mlp.gate.e_score_correction_bias": ["float32", [256], "6ccdac20924ad57f986741837ffccefe0b0584a316b3c02557cbcd45ab11fe13"], "model.layers.5.input_layernorm.weight": ["bfloat16", [4096], "4449e8c45c19db58df7895925fe628ce6dbfc62122fa5fce7c51401f7a70ca58"], "model.layers.5.post_attention_layernorm.weight": ["bfloat16", [4096], "e1de756b0fbc61e9dcdfa0cc478868b67f0e75d5bb8d186c38be596ef4799cb9"], "model.layers.6.self_attn.attention_sink_bias": ["bfloat16", [64], "08270e014a718a1f0e44c5bfe7abfa464a16587cda9eed1c5429d46cc80cc29a"], "model.layers.6.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "3faa54a3ac6cf21732111cd53ebd73ebffe41231a5f73dc49e2803a273813d00"], "model.layers.6.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "a8556922200706c69c498117869ff90948f937a12334033f0d693cafc2058796"], "model.layers.6.mlp.gate.weight": ["float32", [256, 4096], "2f89c619d3a8f9899c0646b4b530a804224fbf04279ee0ea3813387aa0194b08"], "model.layers.6.mlp.gate.e_score_correction_bias": ["float32", [256], "9d653f9719da0ded59e22b398395b804530008e8b342410fb6c773a918b6a67a"], "model.layers.6.input_layernorm.weight": ["bfloat16", [4096], "96aa65e7b68de2c481cf873cead41a24290f6685ac97e226146804c1b1b32583"], "model.layers.6.post_attention_layernorm.weight": ["bfloat16", [4096], "220e2d9cd671450ece314b10ef9c72007d27ce42e21179fc037b3a0c3c3956ae"], "model.layers.7.self_attn.attention_sink_bias": ["bfloat16", [64], "a7004e06078b298c70f9e034fd4c49859b0a054af838f7998e6a07c7f20ac89c"], "model.layers.7.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "087f3602740052ce2389b5562ca273b4327524e294c940bfe3e86f4fbc70ebc3"], "model.layers.7.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "1f214886dea019a8867934ef992a48f9a84dcddfb37dcffe24e5ff1073136ff5"], "model.layers.7.mlp.gate.weight": ["float32", [256, 4096], "ba9abb92aefa05b8fc5d35c94e3cf5e5818f55fb730d0f4196b6817888da77f6"], "model.layers.7.mlp.gate.e_score_correction_bias": ["float32", [256], "3bf53e257f76076e0b4c9c068b13fa8e7947f9802cd886ca311e3812f71f2bf2"], "model.layers.7.input_layernorm.weight": ["bfloat16", [4096], "f46364f47ba7cd3995ec63ef0cd813113fdfbded338d1473a5484ccf0485eada"], "model.layers.7.post_attention_layernorm.weight": ["bfloat16", [4096], "eac180a74b775b6d2cd2f9f99ae06aa6583df38f5a6d2ed7a522a31dfb4685d5"], "model.layers.8.self_attn.attention_sink_bias": ["bfloat16", [64], "8184ac751d9f8afb9c97508c1ce44061e93fa5da9e1496e474d54bee35b77d09"], "model.layers.8.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "3634922711f98bc88ddb0b62391939d3e40102f0b593cf01c91ebfff7c355bea"], "model.layers.8.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "1c4479b9357b1a5f5e170e9b3f1f92ba4f64e01eda6eeb0139d36ddd9cba1388"], "model.layers.8.mlp.gate.weight": ["float32", [256, 4096], "835c0148bcc14635641441605f0b021b0cbec1a59dfeea90b17df485ff2d68cc"], "model.layers.8.mlp.gate.e_score_correction_bias": ["float32", [256], "125ed9e7d5307032a7996b3a7ede760e4ea27cebb2a12df2048549da800d8af4"], "model.layers.8.input_layernorm.weight": ["bfloat16", [4096], "781389b4ec1c2423cf53050ae1527ebca9ea9e3a3cfa7ab822d8f78767479636"], "model.layers.8.post_attention_layernorm.weight": ["bfloat16", [4096], "03e1d11af8138817e81458918a59f6043365547a9ca67a9e043a9a6dddc04385"], "model.layers.9.self_attn.attention_sink_bias": ["bfloat16", [64], "03392bfa322baabbbb51e547b2539c9a3c7e53fa92f125a51725886c6d208844"], "model.layers.9.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "73e8ff2956c662660dd271004dc3a90a806dcfa8673d7c6257a5e374fda358a0"], "model.layers.9.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "d5af12908187a622081f65ddbe8866371eae03c1995c1b576a2b311fb2d4e178"], "model.layers.9.mlp.gate.weight": ["float32", [256, 4096], "68256c0656515563cf7fc066136d2c8ce5a8b75c72f2ead8bfc0bf4d9cc506aa"], "model.layers.9.mlp.gate.e_score_correction_bias": ["float32", [256], "a31b2fa3a4d01c410bf92b758b519432bbd00e20a2d57a17f77e70819809596c"], "model.layers.9.input_layernorm.weight": ["bfloat16", [4096], "e8e38bb92132094a42e4bb68a1b6b5ac3b873c8617674247527ec9070b64da7a"], "model.layers.9.post_attention_layernorm.weight": ["bfloat16", [4096], "193cc28122781d01b79f9abcb4b37d38045f90659c3a7038ebf755be2b9250e5"], "model.layers.10.self_attn.attention_sink_bias": ["bfloat16", [64], "6f13039ff85c2dc0a9ebf10a349e0b30f12936d7b769dd461d6b9483c4ee2b70"], "model.layers.10.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "a61054fd9de631384b536aacfc574ace9cd8094db0a0ec80d46efa519a6ffd35"], "model.layers.10.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "565406647f40ac76efe7cadded50ec2154b672cb9ee4e5eafcc4f3640469eb58"], "model.layers.10.mlp.gate.weight": ["float32", [256, 4096], "d21277b30e25d33a6e7f38177505cd2664a39743319c91a8c47adb500e27278f"], "model.layers.10.mlp.gate.e_score_correction_bias": ["float32", [256], "4197c7a29d7ea9461aa9ea1d0515b8198ec3b3a6d01f8ec516ead8baad6ba004"], "model.layers.10.input_layernorm.weight": ["bfloat16", [4096], "f1d101d90301f239d82d553b2c2b13a90ca506fa10354a4cce088482be17edfc"], "model.layers.10.post_attention_layernorm.weight": ["bfloat16", [4096], "75a77cb441b71f38d7440bab7a9092f0c928761ce08bcec3ce958c29e6162d93"], "model.layers.11.self_attn.qkv_proj.weight": ["bfloat16", [13568, 4096], "207856243222e1fd0503b92e1079329e7b175425545e855081b31ebcce3b8b0b"], "model.layers.11.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "84bea829d716a38e1592bf0dc4957c93f58549fe52e40febc40eebe1bb95d3c0"], "model.layers.11.mlp.gate.weight": ["float32", [256, 4096], "ef723ab026e853d0c6fdc3277fb4232b5657e1a0ddb8201fd023a93eac6f04a2"], "model.layers.11.mlp.gate.e_score_correction_bias": ["float32", [256], "f195d29450d150352d12bf595396158e83bbdf9413425952f059588099547d75"], "model.layers.11.input_layernorm.weight": ["bfloat16", [4096], "628eb98b810f57256db083d6b0e5c35227d7ab5dccfd89ae0d4c8128fe7b38fb"], "model.layers.11.post_attention_layernorm.weight": ["bfloat16", [4096], "47e02778b748a0060c4c8563597bcb5612525b67c257b27fb31cb08215d4ee54"], "model.layers.12.self_attn.attention_sink_bias": ["bfloat16", [64], "aeb2c5fe5d24262cbbfb1f521a9f138cbce81080636535c35f67fdbbf4ccd334"], "model.layers.12.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "c1781a3903caaec14bed287591b51f3afcd9eebbd120826eee1e2ec3dddc70ae"], "model.layers.12.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "3463a2bef102d6aff042cd482ef90eae4320c0a55de727768aa4a2f81118a9f0"], "model.layers.12.mlp.gate.weight": ["float32", [256, 4096], "c038291c9991a3dfc177ae1e6fe43d10d6b77d8c4dc9b901b5af947e2a79f50d"], "model.layers.12.mlp.gate.e_score_correction_bias": ["float32", [256], "d543fc7f4d40a91417500cfc3712dd203a4455d150e1ca342c298632e1e3636e"], "model.layers.12.input_layernorm.weight": ["bfloat16", [4096], "86336d398e5c34a9609e1507b9d151d2b5464ce11ed548a1b2559c72777e8e12"], "model.layers.12.post_attention_layernorm.weight": ["bfloat16", [4096], "e2978d26a7e088747f7e0c01b89b7309da87453b585225abd200783ee09f4939"], "model.layers.13.self_attn.attention_sink_bias": ["bfloat16", [64], "2c48b28718fcf4d57f8156773afcd0073c600956eb601f794eb57fc5062ea0c1"], "model.layers.13.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "58373481bdd6096d5a1f6910071863afde0b405c883ee415ec7840a06c731e33"], "model.layers.13.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "9005b73e16d4ba926c23deb06c03a08683260d62d902df80f1b1677445b0dc77"], "model.layers.13.mlp.gate.weight": ["float32", [256, 4096], "ddbfb71b9f22692f19e8a24aacb407b0535506894493925edbb163e08fd081e9"], "model.layers.13.mlp.gate.e_score_correction_bias": ["float32", [256], "75243b581c3dcd257d5d8fe21e1ed224aa46944d2b562b1f8802a12456a0de07"], "model.layers.13.input_layernorm.weight": ["bfloat16", [4096], "f7244edce0266b832c72af07d76a21771ed232057b5fc2fa636fab974bbd7609"], "model.layers.13.post_attention_layernorm.weight": ["bfloat16", [4096], "05b61086d1241baef761bdcc948ef517b241b112069f8fbcc38186b907b5b936"], "model.layers.14.self_attn.attention_sink_bias": ["bfloat16", [64], "c52f3da5e96b0f8d3eb12902bddbe52527cd987d15d3bad6d004e5727fe02b41"], "model.layers.14.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "26c379b11c55fd71d51c788392059604868cc90b95f45a48f73d8e6edbc77d39"], "model.layers.14.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "51ad391f6026e798987881c4a364bc4cf73b1eb61afce94cbfc5645ba3b8144f"], "model.layers.14.mlp.gate.weight": ["float32", [256, 4096], "759c4820f4ca5681704e5b8153c7387675351dad755e93b24ea21a893dd9efb2"], "model.layers.14.mlp.gate.e_score_correction_bias": ["float32", [256], "24e6e28b467c245e3b45da33a4af28f77bc6051647062a596fe137e39fe0d6f8"], "model.layers.14.input_layernorm.weight": ["bfloat16", [4096], "840ea209c0254941578aae1aa49659a346005e06b8975e472c4c296fc776af09"], "model.layers.14.post_attention_layernorm.weight": ["bfloat16", [4096], "8316d1e2ded02d9c58712b76076e6ebe2342b1a0389c99ccf1779d2bfb260f94"], "model.layers.15.self_attn.attention_sink_bias": ["bfloat16", [64], "29fdea28688fe85696eecf0cb3b7bfe0a8bf2b4031c6d50ef2593402dff5f475"], "model.layers.15.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "12a0d86a672c82a430df8cc6cbfd3f4d71593aa45fc4415b5e759fdcb01118ae"], "model.layers.15.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "51cf1e000dbdd560d93a4eeb3cd8999347542514fc4b7356652ea6c3b67f6b9b"], "model.layers.15.mlp.gate.weight": ["float32", [256, 4096], "cab6e1e3a070f405446eb455316c3f17614a8ee51005e8534d027f632a0779eb"], "model.layers.15.mlp.gate.e_score_correction_bias": ["float32", [256], "3c939e4a731e8c287e38a7531499907581f1f3d7b5c22a75ba08725dc804c033"], "model.layers.15.input_layernorm.weight": ["bfloat16", [4096], "fcde81cddb8a5ad12ae247e054cf41b3aac60edef62761c8fbcd7291625f134a"], "model.layers.15.post_attention_layernorm.weight": ["bfloat16", [4096], "d101eef4aa4741275e06e2c774685e85ba4b24e7799c3929aab1c500f4d044e8"], "model.layers.16.self_attn.attention_sink_bias": ["bfloat16", [64], "228d1fc5c2fccea6a997a022e2e2d4d0a8ce0e3deb1543468c0f4d001be0c8cb"], "model.layers.16.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "e6de5d7fcc515495c4578887c8e588faebbb35b5c72a6c11f64121b9534f9c53"], "model.layers.16.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "c68ddf477f236e7f41ee291a4b2e21971ab5345461106b2270523db5b5ae5f7a"], "model.layers.16.mlp.gate.weight": ["float32", [256, 4096], "e9b7cd0b0d372a41e4757567feed6bc6626c6bac0c91c2d49db333940cdd94e4"], "model.layers.16.mlp.gate.e_score_correction_bias": ["float32", [256], "81ad256018d8f5d0144ca6eeb5a9ee4c698f23e51cfe2cba852f0b4628cd766b"], "model.layers.16.input_layernorm.weight": ["bfloat16", [4096], "5733311e31fb7debdf7f925cdb1e9a90083be9df188491b276ca60cf976c7f78"], "model.layers.16.post_attention_layernorm.weight": ["bfloat16", [4096], "7c228c41db9c700f462f189221b66821762a75b57d4c7864a56cacfb7c42acc3"], "model.layers.17.self_attn.qkv_proj.weight": ["bfloat16", [13568, 4096], "07b983d7e86fdb15ca599976c57a0608b5a66fba2ef7a5c596bf0b5f76427fb2"], "model.layers.17.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "ac6eb2987b5aede75ece674c12ca1eb5670b8d6e8f166b22a0773db9b49b8768"], "model.layers.17.mlp.gate.weight": ["float32", [256, 4096], "82d0f6868a013a2a5cf05dcc02aca4c0582af7c320ecd7d56645d0a985c3f1cc"], "model.layers.17.mlp.gate.e_score_correction_bias": ["float32", [256], "1ef3f3cd733335e1947fa4c746183c4fb2d5154ba523cecfa0b0b9ea3d165b5c"], "model.layers.17.input_layernorm.weight": ["bfloat16", [4096], "76de967a62d11a76c38ab4688415923109ee7c01fc5a032dcc9c1569708531ba"], "model.layers.17.post_attention_layernorm.weight": ["bfloat16", [4096], "88c634a0f93426451a90daaf2e6938f3d2836d87fc63c558290cc8fe3eec8e90"], "model.layers.18.self_attn.attention_sink_bias": ["bfloat16", [64], "fc48608b0437ac5a1c2fda9a681b20367681502e572762ac4527dbad04260567"], "model.layers.18.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "763231da632d4aceda9310db00cda2defa2b1acc8541e8f995a50ed92e2abb28"], "model.layers.18.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "db8c7a99a6671d833b20357eb170267e82b9147c406aba768abac635095fd9e9"], "model.layers.18.mlp.gate.weight": ["float32", [256, 4096], "94c29ddf55192fa37b90e4e1236787b07c0fbed7e5a1e5a2037a8e806c76d0d4"], "model.layers.18.mlp.gate.e_score_correction_bias": ["float32", [256], "76f2a69839c7a0bd4e7238ac5196765b68daca6ff5eb2f57a1eb6cbe439cd24c"], "model.layers.18.input_layernorm.weight": ["bfloat16", [4096], "c469c311de8a159b7a5085aeaeebb6ee4b858cfa04f7ce81f935e422ca3f4a97"], "model.layers.18.post_attention_layernorm.weight": ["bfloat16", [4096], "77c288762d7450fa869da5d0a06b5d7e0f8c33c75159c0e8a6d15967b4edc223"], "model.layers.19.self_attn.attention_sink_bias": ["bfloat16", [64], "8a6a89e29c584fb0cee49cbe314991ab9cb762dd3ddec065831db1b540b144a2"], "model.layers.19.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "190fa55968d887239487c9ce724cf16ffec2df6ebb96e5e7d63f80f348d22a95"], "model.layers.19.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "9a004e845223165b1fbdf50dc6ee34e023ca35075354f81b02a029cb4cc7637d"], "model.layers.19.mlp.gate.weight": ["float32", [256, 4096], "7b967366c73e4668c10b254ae56a3d6d31bf9a40ccbdb7277b588fc57bdd6e76"], "model.layers.19.mlp.gate.e_score_correction_bias": ["float32", [256], "f37b7d47a12a68f6723d28188919663b729dfd6b46ad42753e1518cf6e4ea5ac"], "model.layers.19.input_layernorm.weight": ["bfloat16", [4096], "fb6c812926354dacd2f79addf98210508dc9d0fe73a21c3c2ac781be7bbf6e98"], "model.layers.19.post_attention_layernorm.weight": ["bfloat16", [4096], "36746673ac1c0d4137b245b310e490d979c78c301f5d519aaebbfe88c0deb920"], "model.layers.20.self_attn.attention_sink_bias": ["bfloat16", [64], "3fdd3b5dca4a284c615bf17e76dd4bfc9edb05e178648f8f6ae8a537d08869a4"], "model.layers.20.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "7ddaa203fb211a483d578ec65d32d803e0fe254b251798e01ce7f8c0823f74df"], "model.layers.20.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "67a131c38378c7aab108e0018bc728b3dba025811ec779715d2ea8ffc2f798ab"], "model.layers.20.mlp.gate.weight": ["float32", [256, 4096], "929640897320768b63fc720544e6f1f8fc1abd61a8357ee75ed17bbdf8fea186"], "model.layers.20.mlp.gate.e_score_correction_bias": ["float32", [256], "003160a5164d700d3df442745e06940ff1797b7496dbe15f3e1469eb43d1003a"], "model.layers.20.input_layernorm.weight": ["bfloat16", [4096], "a3473a97550c83b7f896c85e74a32247d26d2f6a1f499a2cd288a9dad518d1b6"], "model.layers.20.post_attention_layernorm.weight": ["bfloat16", [4096], "6e03602ea5540cbe04c67c66e4a14f31d59e0aecf0989f1340a414c98b1aa78a"], "model.layers.21.self_attn.attention_sink_bias": ["bfloat16", [64], "7acbc0327cadde0daba59dcd5e567ce8830defa4cbb3bc5c1c946b0219fcbad1"], "model.layers.21.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "99afb23c513ac41573d3113a21b20f7ed5d3fc8d18236aeb592ebb8015ee1263"], "model.layers.21.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "ab092d136c8e9b5a2717afb251a48a5468850bc66871f5f0ec367543c8dfe529"], "model.layers.21.mlp.gate.weight": ["float32", [256, 4096], "b1ae598c8b61f0baaa671d90c64edbd27631a1e258c472eae247ff2873c90fa5"], "model.layers.21.mlp.gate.e_score_correction_bias": ["float32", [256], "f7b8656fdc8bcab0484c740601a00b27c3d14de1c196761348e05e450dd0cc8a"], "model.layers.21.input_layernorm.weight": ["bfloat16", [4096], "d6956decaed094e95511eb47f371bbe0a5ea69b12d80b323fb52b196805440cd"], "model.layers.21.post_attention_layernorm.weight": ["bfloat16", [4096], "e55b2ee1e9b125b4a3575c73c6eab21eb5d7e7ea30e21be22c298fccc7c536e2"], "model.layers.22.self_attn.attention_sink_bias": ["bfloat16", [64], "39ef3bb17b309a3cf766874b08a70e9ff8e1d1d489b3db05a6662ef2800a7861"], "model.layers.22.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "f6db872868722fc0e07235ea606c692ed5c4beae3fd9804842065132f22a3d72"], "model.layers.22.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "0fb49c88613ab0f2cd4260c8eed97708d926e1a12717b1199b627434a4a7f02e"], "model.layers.22.mlp.gate.weight": ["float32", [256, 4096], "49f286008023d582999d9d9abf977f2aa77e46ce3dd47c038444cf98c941d2e2"], "model.layers.22.mlp.gate.e_score_correction_bias": ["float32", [256], "52a635d866068deb7b2a2b09fab3137ea763282d8f8a5db8a2a75ad1dd6921dd"], "model.layers.22.input_layernorm.weight": ["bfloat16", [4096], "a7d13c962a40b3e5f635a3472081fb3e98d8951e4dc9beb5d4cb7e2716b86a0f"], "model.layers.22.post_attention_layernorm.weight": ["bfloat16", [4096], "b46a9d127647bbe423e794215ac6c2c550bbd4f7d15d7045d111d134a300a740"], "model.layers.23.self_attn.qkv_proj.weight": ["bfloat16", [13568, 4096], "b1fce6b7e121fdeb87c1e152a99c9723f4267eeacb4f6d2ec576703a513f0fff"], "model.layers.23.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "b4a0bde8b2f216a8e491daf7f267b7f6179b4090c1efd1d7786ec43d8fc52493"], "model.layers.23.mlp.gate.weight": ["float32", [256, 4096], "48a48caf552c309a06e7fdfa21ddf8aa4cc43f635bc97fe5c58aa3e0ee0eb0a3"], "model.layers.23.mlp.gate.e_score_correction_bias": ["float32", [256], "dc6bf7304be2123dea554b9fcf386e290bf094d3ffa702f7cde11a98b85b296d"], "model.layers.23.input_layernorm.weight": ["bfloat16", [4096], "2b8b91ad9af222872275d158205ed0dbbe42d1bc08a2ee33c3ae568fc7086e1f"], "model.layers.23.post_attention_layernorm.weight": ["bfloat16", [4096], "277636a9a8e744d66486fa126b7dde3044bc1a5012268a410816e69567133cdb"], "model.layers.24.self_attn.attention_sink_bias": ["bfloat16", [64], "d3efdd6857ac205d007baf796bb15d2d674c8dd40644212e10f016acd229a454"], "model.layers.24.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "7c0ab1d50327afe5d100343fb3a0ae036e7431ca0917f1d432bc8847a143c026"], "model.layers.24.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "889a682b88c48828dee98c710a734088bcf98d9bba2bc8319121ad2a557fa61a"], "model.layers.24.mlp.gate.weight": ["float32", [256, 4096], "e484c9b92739ade988c9ad3f82816b893afda53a14e8bc77cd1dd6e07a2818ab"], "model.layers.24.mlp.gate.e_score_correction_bias": ["float32", [256], "2e9ae90b76a9b64f9b6d475227c0c0ba3dddac842a69b3c2edfd3dae56c80ba0"], "model.layers.24.input_layernorm.weight": ["bfloat16", [4096], "72d647202b22f2365df41161ede6af01a295838dca4f5c083739393b914e3a01"], "model.layers.24.post_attention_layernorm.weight": ["bfloat16", [4096], "a76a19e0b94d3ee28da606c218bbbae8cd6a8dacc8a20ac182b2b10eac88f905"], "model.layers.25.self_attn.attention_sink_bias": ["bfloat16", [64], "fe85bc50c5cb79b74685885df0897af13fcf4bcd70069f2a73e34d4b3edd104a"], "model.layers.25.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "acd9e0d333d43c8076bbe9537552a7300470c51c889243d07bc8ec9a5ab19848"], "model.layers.25.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "8fd1bb3c0ed02d46e905f769f3457ef4abe60ce23894f69158b2aeffddfae756"], "model.layers.25.mlp.gate.weight": ["float32", [256, 4096], "134534ebcf1f28fda229b8745c786810a7a6d79070315fc45f0700b47d518796"], "model.layers.25.mlp.gate.e_score_correction_bias": ["float32", [256], "f5386100a4e24aafddc131260274ee23c7cc64142dde433fc4c29f8fe613d9de"], "model.layers.25.input_layernorm.weight": ["bfloat16", [4096], "9dd3342646cad0bc8d8f3d77d40276ad051bd546e9e052170eb9f17bedfbc833"], "model.layers.25.post_attention_layernorm.weight": ["bfloat16", [4096], "246160cda431c97f6a1fff5553327409a40492896e0db6bad3d94117cc9b6f9c"], "model.layers.26.self_attn.attention_sink_bias": ["bfloat16", [64], "3fd6f4525011e9a108b9200e6e5d6f508f167822b1dee909924f4205939417aa"], "model.layers.26.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "a3e525254d3db3dfc3c57659d78d6d2ade6650089cfec95f738c8ed2460be389"], "model.layers.26.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "86d3ddb84a62273da913b81930ec828519ad693ee48a91a234acd60f9d2fc224"], "model.layers.26.mlp.gate.weight": ["float32", [256, 4096], "46f392a2bad28873c05fb6b1e174f1e5d8892a231cc43fb4a5a6edd54c706266"], "model.layers.26.mlp.gate.e_score_correction_bias": ["float32", [256], "2392033301ee4f2501ce1664474ea844a5b349d6671d2bb18d4663ed496f9869"], "model.layers.26.input_layernorm.weight": ["bfloat16", [4096], "09dccbd15bd199c64fb1192142ec20ada5e5c1bd36a346072ea591c4799573ac"], "model.layers.26.post_attention_layernorm.weight": ["bfloat16", [4096], "0a84237a216a44ec0932b48311e72c164344eddcba8741f66c86db84d406a044"], "model.layers.27.self_attn.attention_sink_bias": ["bfloat16", [64], "9aa25da617e820984999be8ab4d1933c67e6b03b0fd242ef07885fd55d7c8641"], "model.layers.27.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "0aed4e370eb0ee7a6d71a26233214fe929f3d29b15a63e3ddb37e6238e771218"], "model.layers.27.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "774f9857658e33585009a6763e356ee84314e742a295068f3c8b10ed5a8d786c"], "model.layers.27.mlp.gate.weight": ["float32", [256, 4096], "89b63bc4d95bb7bedbdf37d1f22dee49a4e37d99e43f7c05335420728d0f55f5"], "model.layers.27.mlp.gate.e_score_correction_bias": ["float32", [256], "ccc02a04dce8c393b197703ba5b290b6b50abb3cfd6c51e118ab2673e7662bcb"], "model.layers.27.input_layernorm.weight": ["bfloat16", [4096], "f89ed4cee6bd19f271cfff64058e5c1c16b84da0bbcd2592689a578fecb1c9c9"], "model.layers.27.post_attention_layernorm.weight": ["bfloat16", [4096], "8be8819c0d438813e7be12453009326f640a9b8f136a3459296b548a0eb12f8d"], "model.layers.28.self_attn.attention_sink_bias": ["bfloat16", [64], "27c2213020e35d89ad4e4058d169cef36a2af370272800ea58f4058cdba7a592"], "model.layers.28.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "f0ed15986aee5a19439796b4fc814e832c8c8fc9f0c2f1fc1054e68cc9022c29"], "model.layers.28.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "268962ffc79c2445fe9be0ed960b6ff41606388a1a182c8d329589e1accd90c0"], "model.layers.28.mlp.gate.weight": ["float32", [256, 4096], "ef58e717d1e0f55b803ecb98843b93816a640946a8c01682942fd84ee7ede2e8"], "model.layers.28.mlp.gate.e_score_correction_bias": ["float32", [256], "1dc4096120f7907057ec8d2f799b856b74dc00689f438261ab13e6f489a89278"], "model.layers.28.input_layernorm.weight": ["bfloat16", [4096], "5336c00ec963c2cc871de726abf34eeea6939b0bdb7ce31bd723bbd38269298a"], "model.layers.28.post_attention_layernorm.weight": ["bfloat16", [4096], "593e155511fe22c907f8484e6ff61f690abddc12e7a73ef47384016e5a3ad820"], "model.layers.29.self_attn.qkv_proj.weight": ["bfloat16", [13568, 4096], "b389fc287a16752fa49b6cc8f40f38cb00ed3ecc36a27a97aaddb0d788f9be36"], "model.layers.29.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "de2f8ad0934fbf7d7bf30844374b8f60200567fb7ad705ee99f0c2d8da5573c8"], "model.layers.29.mlp.gate.weight": ["float32", [256, 4096], "89a01626ecc9b0b0f5a433abee0fd830baba58b4298e83092e9348fb67bdc60a"], "model.layers.29.mlp.gate.e_score_correction_bias": ["float32", [256], "50863e20f916569379963e0b20f67dfcfa9f9b2feb2e51137aab9a5b3d1e5385"], "model.layers.29.input_layernorm.weight": ["bfloat16", [4096], "39fc36895106c50b56d4002102e2978d4c6a91905a9fbf39a2a1475c5ef97a3a"], "model.layers.29.post_attention_layernorm.weight": ["bfloat16", [4096], "50bcc3d7b7a5e6f599d5133ee1095eac01b767f70097c4a086d5cd323a48912c"], "model.layers.30.self_attn.attention_sink_bias": ["bfloat16", [64], "886dc18fe038197f0fd666bce267d6c7c101b418a697777ddba28c04dbc77bfb"], "model.layers.30.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "a4e675cfcdd72eaff24e221b75f1ef371e90b9c13072ff0a9865380d50b89067"], "model.layers.30.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "f2b59e79ca1e7a612c3501bbdb6b314943b2ba55917d8efa3bf853f4d17ed252"], "model.layers.30.mlp.gate.weight": ["float32", [256, 4096], "4c2c859eff3d32eab45f9635512ed4c192af88aa3ae4a3f7eb84acf697305dfd"], "model.layers.30.mlp.gate.e_score_correction_bias": ["float32", [256], "ff1e3f29954232df86d72a59c3c87d42c7ddeaa5b2d7640ae68fb84afd9004b4"], "model.layers.30.input_layernorm.weight": ["bfloat16", [4096], "23618adb389ff890e0f9b2c89e98e90f19ee392af479b47c08257b27c0569a4f"], "model.layers.30.post_attention_layernorm.weight": ["bfloat16", [4096], "d07af5c0f57e3c3b2efb3f81652438240b27340145a146a1fde7f288d717d6c0"], "model.layers.31.self_attn.attention_sink_bias": ["bfloat16", [64], "ffcf01df5de274e6958a150a028c055c1aa605dbebab332f4d7cf00927d541f3"], "model.layers.31.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "1740a74ced1531aa2871254accdbdec897ad382389df1ef12c7b09c880ee4fcf"], "model.layers.31.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "d976ac90c1f5432322a83da397dfdba89d1c9c3f2fe507990d3021b987883f05"], "model.layers.31.mlp.gate.weight": ["float32", [256, 4096], "c1f648c9a83ed68ac0edc67841e93eab4282250585de6b4eb52759750538d676"], "model.layers.31.mlp.gate.e_score_correction_bias": ["float32", [256], "37b8b1dffd2e899947c2ec5052d3e53c6af6a5dbf49b4a099681678e14cc2bda"], "model.layers.31.input_layernorm.weight": ["bfloat16", [4096], "a6594554e4656c11995508f6a05a69d1fcfbdabe13bf093641a4ad5005813006"], "model.layers.31.post_attention_layernorm.weight": ["bfloat16", [4096], "fdd2314c7ed6f2d94ae24073c824542c2daecef4bd59b09717d86c89d63abad3"], "model.layers.32.self_attn.attention_sink_bias": ["bfloat16", [64], "92ee78cb4519be52c96ba5b1aff98ef7670c1e95ce853f6082cf01197316d638"], "model.layers.32.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "c5053d51b873a0e8f4969a2d248290cbfd8b18d189e7322570281b860db05d60"], "model.layers.32.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "e7a4b354d21594ec45fc6c85c7b7c1cfb001fa4d5b367897274a6a69d9038a9a"], "model.layers.32.mlp.gate.weight": ["float32", [256, 4096], "7f93bccc2fbdfbebc534def31dd0820d80332495ec6cd86e6947be2237024927"], "model.layers.32.mlp.gate.e_score_correction_bias": ["float32", [256], "043886f3c0c0223e7933fd0fe8f8e8fd1fec24e1d057eb9853d7dd311935f911"], "model.layers.32.input_layernorm.weight": ["bfloat16", [4096], "5b290dc26599a45212ea6e4d6f02560d56b3e89e5cf57c37eac90c56985c48f5"], "model.layers.32.post_attention_layernorm.weight": ["bfloat16", [4096], "842b205ac452c36220f516b88c6da29fbaa736190bdec064067cd6ada9060612"], "model.layers.33.self_attn.attention_sink_bias": ["bfloat16", [64], "07eb399040c567189637bbb921d45ee61bc56027efbb29732f45f2dcb6f361a6"], "model.layers.33.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "3425c62b50777762ffe23d72054ba909cabfc7d8fbe57d44847d9902845f905e"], "model.layers.33.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "aa4d9d25b5047f68b3190ee09bbcab7c49113eea2f3d5a55958ade6b05a16d03"], "model.layers.33.mlp.gate.weight": ["float32", [256, 4096], "6547b016dafc206cb2d0ee97036323ba50e4af584f23dc5c25e450327bfc4398"], "model.layers.33.mlp.gate.e_score_correction_bias": ["float32", [256], "5b5aa6674d716666ac586dc4c825639d06d5d2b15fbf6e869481c1f3cff183f2"], "model.layers.33.input_layernorm.weight": ["bfloat16", [4096], "c1a9e1c09815ac30b048b2bdfc708eb3fa17aeecdf794fe1dee1f5b08db2177c"], "model.layers.33.post_attention_layernorm.weight": ["bfloat16", [4096], "8d552186951945ace67086a12a5847e28682ae2eb1d7395d823267c576393751"], "model.layers.34.self_attn.attention_sink_bias": ["bfloat16", [64], "f68858a9feee22a0a9ea404d585f25ebcce69fb8667a3d486aee4eeabaaeadc9"], "model.layers.34.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "135cb1772cd762bc73fb4534a1706c91c08cd7144fdf9f2a5918c998d96cf864"], "model.layers.34.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "c4c97fe6011aa21d734405805ea31b8cf03ae75101684d6e94424845d243b4c8"], "model.layers.34.mlp.gate.weight": ["float32", [256, 4096], "6a72aca831f88075d364f2c69e3c672118838d1d9ee9c8196952c3e54544c4cb"], "model.layers.34.mlp.gate.e_score_correction_bias": ["float32", [256], "979ccd10dc9b76128c9bc58bb1a8a974b53b86b062117c7fc246e384b695d360"], "model.layers.34.input_layernorm.weight": ["bfloat16", [4096], "be478f53dfb7d7d4f3f5eb21274d3e26f10981643717021852e8ff4529899533"], "model.layers.34.post_attention_layernorm.weight": ["bfloat16", [4096], "7cbe9afb22a356290920c7546bb1ecc635e87f53cac98282c713c10c6e92d3e2"], "model.layers.35.self_attn.qkv_proj.weight": ["bfloat16", [13568, 4096], "dd459319026ed4e6b7afc9d3183f5b4790188f1f79c1bd5745044b1daa88638c"], "model.layers.35.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "5e0933dbf7d3f7e5905536b8264801ba8ea4df8f54dbea5e3b3af8ef3e2870db"], "model.layers.35.mlp.gate.weight": ["float32", [256, 4096], "b2b491a012591293f54aa82993e54fde3435296b3345220162c04724acae001f"], "model.layers.35.mlp.gate.e_score_correction_bias": ["float32", [256], "896f7be0e09de7635b568e7d41dec6639463926d84b6451564ed37417989d9aa"], "model.layers.35.input_layernorm.weight": ["bfloat16", [4096], "6dcf0a6e6502ef4a2fbe5cac085dfe65028a32c637febb9036d708a07b5ff25c"], "model.layers.35.post_attention_layernorm.weight": ["bfloat16", [4096], "91ced3966b362557beb4bfeb3f7580e9191e7fe280a4d9e019aada12522ea506"], "model.layers.36.self_attn.attention_sink_bias": ["bfloat16", [64], "2794736183ebf5a08ddce8bce4a5f2033999014ebefdd4906bbff54539bf3584"], "model.layers.36.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "62e9d4c57421d4fe8658387a2947b0a0b05db503ee66a22c232391abc49ab989"], "model.layers.36.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "1acb3b1b4e8bd40f4e32054836f4353d7dec87f0ec729d439b4996427459bcf2"], "model.layers.36.mlp.gate.weight": ["float32", [256, 4096], "2eb2c4b927c4a0463cbf3788b2870041cfd4fe030e214eb03d49d29d848a6845"], "model.layers.36.mlp.gate.e_score_correction_bias": ["float32", [256], "03215169c5af9f7ed362a27bdb1d7133992a8b9b58e1006f84da103f5b06b065"], "model.layers.36.input_layernorm.weight": ["bfloat16", [4096], "d84fe03c86451dbf644ea31e5c1726a2f045786bb283af557fee293556cbd7bf"], "model.layers.36.post_attention_layernorm.weight": ["bfloat16", [4096], "b031865587e02cf509f9251de59e48007820f6df1b5948abcfce28e4effe3ea1"], "model.layers.37.self_attn.attention_sink_bias": ["bfloat16", [64], "ebe10169d10ac189956127d28d148d39edb97cd7baf38b0369eb4ad80b785bbb"], "model.layers.37.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "cec021da3f85e12197af53d3f4c91fd5f7f27548bf659424c0b73db50beea9c6"], "model.layers.37.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "d272bab52584c51822a0b9cbba7728c529683f24b3ae7915cda739a4121ac019"], "model.layers.37.mlp.gate.weight": ["float32", [256, 4096], "871d0d3dab75ef0443a8d8425d24f97b7f2ae840fc3b22b403bbf57849728fe3"], "model.layers.37.mlp.gate.e_score_correction_bias": ["float32", [256], "9658a8ad25bb30a6c2a72b58d7f6ea3133242988ab052f2ca61295b068682942"], "model.layers.37.input_layernorm.weight": ["bfloat16", [4096], "41c5b979b67af1bd23f38e3659761df31dd81411b4fdf1fd265fb2451eed9f9e"], "model.layers.37.post_attention_layernorm.weight": ["bfloat16", [4096], "32b9460224e06acf9b2996ada76576a7b30dbf342d2fcb9248b650e85cb9e50c"], "model.layers.38.self_attn.attention_sink_bias": ["bfloat16", [64], "69167feaad4b7d839021bfb7f3a4e8023a33525ca3de59b21f35e1d6cce8cd5a"], "model.layers.38.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "503afa03114fe0bf7ccc500a233492eb01048d94eafa7992a5507684a13fbe24"], "model.layers.38.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "6ff7057e07f8fcf6bf111fa1772fc95b97251121fcd1aae9ce3ef586cc824a95"], "model.layers.38.mlp.gate.weight": ["float32", [256, 4096], "624d4c82face7c4dee0fbc113cf75af26b0070c4072d55a10e972c4b8b91a2e9"], "model.layers.38.mlp.gate.e_score_correction_bias": ["float32", [256], "9ff2bc2fba0be431e8423a280888c327aa72194f471105f9f89b3aee518820f6"], "model.layers.38.input_layernorm.weight": ["bfloat16", [4096], "72888d50b13f0f42dd80fb46278a371d505a95d55c9b15a85b2b866fa9d071f7"], "model.layers.38.post_attention_layernorm.weight": ["bfloat16", [4096], "08f2c8b2591ac63b4120e44c5140d0bb4bb0f4e21c3fd1a968a3b4de36d996fc"], "model.layers.39.self_attn.attention_sink_bias": ["bfloat16", [64], "a0e00c9b1dc6670ac46977d563a2c801614c74d816b163fcf8605c9d4158b0f2"], "model.layers.39.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "470356df385236431bacf288e5b39f02a104abe2db04607e27b7d541e064c867"], "model.layers.39.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "a839d1ec1d0abb14053bda32d33f0d15c3f13389857d66293a073a8d7c016113"], "model.layers.39.mlp.gate.weight": ["float32", [256, 4096], "7f03a2341b0f9149f55d0b2c97a089edc1bb8cd78f64ae856dd6a72c6fd7fb4c"], "model.layers.39.mlp.gate.e_score_correction_bias": ["float32", [256], "782b0f0dd483622915f4c0435ce4f05a26d508dff96f0b173e693d6da4e672d2"], "model.layers.39.input_layernorm.weight": ["bfloat16", [4096], "7b749f574af64db6735ea0c744dd4454bc924617d1ea7de978064dc235ef650e"], "model.layers.39.post_attention_layernorm.weight": ["bfloat16", [4096], "fd8adf3dc6e493f7aff7152be96bb0225914373d6af14219407fb30a0f1fa466"], "model.layers.40.self_attn.attention_sink_bias": ["bfloat16", [64], "88a9b0fa3f8be0dab6450e5ff57f29608ebb2733973740dde4317e6da1458775"], "model.layers.40.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "ca0395a6232b292750929aa10351494ba812ebac42eb1321b8020260d8091984"], "model.layers.40.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "ec489dadfd36722b5ec96fc54a60f96829daf023a18f0835d0a98bfd2549cc0d"], "model.layers.40.mlp.gate.weight": ["float32", [256, 4096], "37ac11d862cce2e8f16445b63819ea9cdaa9c8f8267a7195dda1c1f05a70355c"], "model.layers.40.mlp.gate.e_score_correction_bias": ["float32", [256], "6cd0a0a0f7a73923113bfecad193591525f3f3dc718bdac40437ca5c470f468c"], "model.layers.40.input_layernorm.weight": ["bfloat16", [4096], "76960f2228a7d3ebaf5252a33d6d89b1e3d4efe788b827a7b452fdf05129c16b"], "model.layers.40.post_attention_layernorm.weight": ["bfloat16", [4096], "9192432d97e6666d8af13ee278872875cbccf2ed00acfbe31837e8bcc00586b7"], "model.layers.41.self_attn.qkv_proj.weight": ["bfloat16", [13568, 4096], "73acd99e82581d1b40e6d20f1b33efb7834364d22fa4514bbb51ee850094cf76"], "model.layers.41.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "0f97a49d76b1b5951aaf5202464ab9099a9f579e16996096aa1e12e24c5a3470"], "model.layers.41.mlp.gate.weight": ["float32", [256, 4096], "610a784fc4fcbcc1a264f43bdc7b37d8a6aa0fb70f793352799166b682a2e5bd"], "model.layers.41.mlp.gate.e_score_correction_bias": ["float32", [256], "84ba8196c34e0ff28d30d6d98638d5c4b5826b2bc7ce74e009c52d7e4b07177b"], "model.layers.41.input_layernorm.weight": ["bfloat16", [4096], "4cd86aff498a68cf97967906bcf9ab64e72728a3d85679b4172d134d50447201"], "model.layers.41.post_attention_layernorm.weight": ["bfloat16", [4096], "4dc7fb02c9104c7e8015499dab3611afe1b7fa5cd6349950afc8af69b96fdf2d"], "model.layers.42.self_attn.attention_sink_bias": ["bfloat16", [64], "20992205ecbb61ebfb787bede9f78e9d5ed3cc1e3af10884db05df10bc01e46a"], "model.layers.42.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "10f80ea48e45fd81da7b177b5a7f0a17aeaff4390a39d8dfc0ad52bf0be24530"], "model.layers.42.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "2593c43a6eb1abd104c01e318504a9453838df8caa29b5eec6a931ee30081649"], "model.layers.42.mlp.gate.weight": ["float32", [256, 4096], "bd1cc0f0dfd2a8fc564769cd8cf496fefc4db2ab5b7a7e439275fcc7830aca2d"], "model.layers.42.mlp.gate.e_score_correction_bias": ["float32", [256], "521145367e5cd161adfe4ca4437854bc3e7ea43b93fc1fcd4599d01f5ae55c4d"], "model.layers.42.input_layernorm.weight": ["bfloat16", [4096], "3cf399d784f8bfd16ed1971ec4ef5c170b9fe1f423c4703d67cef57e15752a33"], "model.layers.42.post_attention_layernorm.weight": ["bfloat16", [4096], "d418ed8ba5ec01b1614b28b534edd0227c5f50a615e3a503a715407e49175ec7"], "model.layers.43.self_attn.attention_sink_bias": ["bfloat16", [64], "55554ccf9089102bdd7ef967eb486288f425bf345dd06074ff0c4de4f0f1290b"], "model.layers.43.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "0fa08368ad66de7bad6490ff0340aa7d4e3a0ec462a12ec55b078ae1afcd044d"], "model.layers.43.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "b0221cddbc574f48904c10ef78782c3009b2e0b2f46425c72ff9998cc9a70e13"], "model.layers.43.mlp.gate.weight": ["float32", [256, 4096], "d8bdf1785eada1542272738f4c6873b9ccd2f807d280c5d12ac2f180a41afebd"], "model.layers.43.mlp.gate.e_score_correction_bias": ["float32", [256], "aec987415ff17d25a69fc41eb60f6ee8578a013353c2ce17618423df4ada94e7"], "model.layers.43.input_layernorm.weight": ["bfloat16", [4096], "c87ad28305de4d3c15704b4b49ede0ac42d19a2a2ee8384746885ac5258236c2"], "model.layers.43.post_attention_layernorm.weight": ["bfloat16", [4096], "375a1ec94df538830601535c8347f415561526baf2b536f315a825d837e84b82"], "model.layers.44.self_attn.attention_sink_bias": ["bfloat16", [64], "38d73e5cf9cef6df02d79dbee2a4e384efc86d613d88e9e873b3fcf5070af838"], "model.layers.44.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "9fb1f28a605a3f66070a9de58d9d6b00b0e6146db48860a2ebe034e39d52085e"], "model.layers.44.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "c58ab4a006e46596c827d466fcfd86d058f4376ecb5b90a0a2bbe25cb1d942fc"], "model.layers.44.mlp.gate.weight": ["float32", [256, 4096], "4f3ce3559851690a82561ec5527e7cecf8d31ad2921231aa78f71bdce1ec6fd3"], "model.layers.44.mlp.gate.e_score_correction_bias": ["float32", [256], "0f6eac4af79cceecb9e041913def8cc5601985a95392a35c7dd7de682ddd31e9"], "model.layers.44.input_layernorm.weight": ["bfloat16", [4096], "ab7d93adf3019e64ed1350527a7d7622b72f36872af69f89d8eef3db70e8c21a"], "model.layers.44.post_attention_layernorm.weight": ["bfloat16", [4096], "df9ea265f5c2c9ce7926fca646f5b8bf388fab294ffc3bc8fb824cb69a474b3c"], "model.layers.45.self_attn.attention_sink_bias": ["bfloat16", [64], "85b7b2f4b1a95133eadee9fa57f5b5c1bc6e34a154decb7818d4430ff48612aa"], "model.layers.45.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "823106f42222a42a00b09fa2132bb09dd7bd2fae2f55b11521a818d55727b4ff"], "model.layers.45.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "37bb14aafc0368ec013988841159c7629a2d761e93a479602910b1d6cb3b7933"], "model.layers.45.mlp.gate.weight": ["float32", [256, 4096], "5bd0b67b9db4a0259377db8ec9024f9b18bce25d718a79186742c8548b480995"], "model.layers.45.mlp.gate.e_score_correction_bias": ["float32", [256], "88be9bcb575102fa47dda53e59e58d8b24dbcb2cabac916a69b78c1830b0a903"], "model.layers.45.input_layernorm.weight": ["bfloat16", [4096], "07d11bedec2ebe538db03fe17f5cb471a2db6c6f64f8b3f7ec90e3373a8cbf52"], "model.layers.45.post_attention_layernorm.weight": ["bfloat16", [4096], "9c8b170011983174489b1c68d882a29896f4a030043bb72bb5d023f08cf5d52d"], "model.layers.46.self_attn.attention_sink_bias": ["bfloat16", [64], "80129d86c1257b1f914745726b8285fffa209907c182bb3166372623bd64e159"], "model.layers.46.self_attn.qkv_proj.weight": ["bfloat16", [14848, 4096], "2363977cd8c91f3f2e18707c75043a011b1b445f32fc5186887b737b87fd2864"], "model.layers.46.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "de4c6d075faf6e200b975672049dd8d7d52847a88d253b70fcdbabb43ba5c9b9"], "model.layers.46.mlp.gate.weight": ["float32", [256, 4096], "1557b2a96a0b5b43a2eecdb72bd12799d09ff1b0eb674a3f06c7bbc180aca6f9"], "model.layers.46.mlp.gate.e_score_correction_bias": ["float32", [256], "14e7ecfa232a5a34bd695fe10e6ee5bbf39d9e4496eff4703796698cba97e181"], "model.layers.46.input_layernorm.weight": ["bfloat16", [4096], "8fbf27112450f711dc5e034f4844d0d9c4d580fb97ea9964d17ecc32029ad584"], "model.layers.46.post_attention_layernorm.weight": ["bfloat16", [4096], "2c8661381f9a7e33d838a7f40b9db9a207545ae50ce60919c5a7da0a6e2f8d14"], "model.layers.47.self_attn.qkv_proj.weight": ["bfloat16", [13568, 4096], "3d930511b6fc007752d934fb0c28144ad9948503041ce348266f18d7d4f85f27"], "model.layers.47.self_attn.o_proj.weight": ["bfloat16", [4096, 8192], "775dc1c25d0f61e7552606623b9a1f0b4a2114e2d16c942aa823b3787be6ea05"], "model.layers.47.mlp.gate.weight": ["float32", [256, 4096], "8cff9c1c1ecdb898843c188d28b9fc8716bc9b979e6a7e470a2c0543ba414c14"], "model.layers.47.mlp.gate.e_score_correction_bias": ["float32", [256], "df28e469655c7c8d771749acc3459163b96db4c48e4fe0ff59fd3e0e6af4429e"], "model.layers.47.input_layernorm.weight": ["bfloat16", [4096], "bbaeba3d05e5ef74ebb6b1f183b9bc1a8bca4fd0b7a0d1746ebc145c44e19959"], "model.layers.47.post_attention_layernorm.weight": ["bfloat16", [4096], "0f69e5e0bf76f7cf9a0b8f8a06a0abcb7ba37256e7ef9e87cd3b429f00f98626"], "model.norm.weight": ["bfloat16", [4096], "f038efcec6944108fe18d50a19f1a9abf3d71c39dacf8ca4b808e1c2942459bb"], "lm_head.weight": ["bfloat16", [152576, 4096], "d74a930467736a47b5e798145b6c28ce16dc6ec868691da80fdea0288e09e8e3"]}}, "moe": {"1": {"file": "moe_L01.safetensors", "sha256": {"wg": "ab8e6dbe7d3ce34ff4f25f3c54e2ba1217dfa0293e44d2e259b7e783a0f2cb22", "sg": "927a341fa3c7a4253a61e0ac01a23f4a13ecfa39efa1f6fb348d2ef503af9719", "wu": "89452a2f24a96c6a6407d3ab3f17fc2344f7080568660030bc8b7a010fed934a", "su": "90cc54c33d5bf1c0163b4b2554ace7b7a6cc6f79c1e4b8e276ed03c63152842b", "wd": "b7e3ebb539a41c929de5576952ff1b9820970a6c03ad7ac3cd742fd577e18121", "sd": "ed6965a484a0fc8321b4fce69bfe8e00fa25af233d0f35381d26af2fb8e103fe"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "2": {"file": "moe_L02.safetensors", "sha256": {"wg": "b922aaebf17b4cf69964812b1a5f2927e31e08b23328e377ef0af41a95832b64", "sg": "9e8317e466712d80a5a437834a4dc31a027cb56f729b180fb48010d4a631f657", "wu": "04a00f744b741f413303b2c3f8c7e296c65ccb763cbcc6bb57434cf1d13d8b1a", "su": "dc5a6a62610cdee70a71a6211b8f5ffe303c6dfe1c69e3f23b85399d57f8096f", "wd": "a2ff0f31c34e1dd63299e27240ce12dfbade703d511f94d3a3631e2c935df52a", "sd": "a3fbfd4268ddd5e9c9bdb8852577f9f26ff6870d13bf58ca990b47aff57efa1c"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "3": {"file": "moe_L03.safetensors", "sha256": {"wg": "1ad65b31c764a6ed4034544bc69cdc78804dbae524c0f3e0b36a31dcbca95de3", "sg": "f7d8f0d41bebdd45734ce440163cac97506a855140d919c1f8c90e72742311e7", "wu": "d619f25671a547c8b764c0ca51c30c31feca963ce1e9377b9ec2940a399eecae", "su": "713fc375e3b1bf204e98a7f081d3997143cdcebe3750607d664b6e6603489a85", "wd": "3b3e78f03fa90e90fcbf06eefea4bc4e8635af9b4d2d67ed29885d9647d38629", "sd": "a3a6ca3a0f3f060cd205658f500e18f5e69a31ae5d02ecdd7c98d97e7e4bb13a"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "4": {"file": "moe_L04.safetensors", "sha256": {"wg": "b4d5495fa661a7c906088f3c1e0a9a932d5da4e0aaae72f8b721610de4b4623b", "sg": "140ce89a843c025e7f08cbc5e4b8d86999641bb36dc0bb79a5568bba63da738a", "wu": "0d159a0297ecc3f84d297a7b0348ba8e4ab1f61a22e47dddaa1af587a521451d", "su": "0ceb93ecebc487b3be3bef21036a387827dbd47d8e2eb671498f5c759bf7e96c", "wd": "9f3bf97c711255953565677e6f4d8d4a43f471594bff3346090581bfb85ef505", "sd": "5c880aa5846f684dd9feffca546ad088194d9cadba54c720735a906625840569"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "5": {"file": "moe_L05.safetensors", "sha256": {"wg": "2f1f0c2e950dcabcfdee4297c6abdd33a53ee63a6a9a7cf3b9359a0409fb0459", "sg": "528432dbcaec83f777687dddcb935700c52d3839d65174cb2950928a021784c0", "wu": "51d7df8e8e3cdc0291640af887f52807705c3dd1b37887d3d555e43db5cdd9e8", "su": "d075cf744cc69e0541d3c80460cc70270920ba77a482da944bc31704190d3745", "wd": "3f7382d6780420f93249424633d60e3795c97abbf5766b6711f8332002f7bc3a", "sd": "ba3a20b991022a512f4225f9494169fbfffbc9bdc09a51460b350606abd4ba3b"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "6": {"file": "moe_L06.safetensors", "sha256": {"wg": "d3bcce533efe46e951f53ce6ce62cc905bc63fe22dd0a1def672a31756183800", "sg": "91bedffc2b40bdf1767dfe735541691bdc80e8538ca7dc04c11202f317b71081", "wu": "7559c480bc6b1fe0b5da1050fe46f422d92f99d51f9c23ca0dabd7cc253a64c0", "su": "2e6fdd937abbaeeb48bebe70ca96171126bf1f60303fd70f33aa83b76de5f7a5", "wd": "dc1ed390ae8cf476108f4ec62e39ec0d2c94f85fe6b6864463bd1013f85ea4f1", "sd": "57343ec1db6dceea8cd93bb7059366f5736a505e962794cf0fac7846d25bd1d2"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "7": {"file": "moe_L07.safetensors", "sha256": {"wg": "170eb4c1b21757c76e9f6e727acbafae43fcaa4dc20d73061ab007a08fc6ab5b", "sg": "2c06ff13358e52fc3d8e3a743d38c535ec937d129ccb8d6390f0a6c984e8979e", "wu": "5ba9b8f8ac7a2b5d55e80be24f5bf8b439a45c8bb35f9a3a302c9b258f210355", "su": "14b446c0ff4b54aac5f3958d44650b2524ca3b2a835f9b701f634b3a5f88b5e7", "wd": "7f4fdcbbedd7f1f43f45dc2302d06d1be859cf5511f92593c673bc58f58257d7", "sd": "e95e10c845a544a5ac8a0793efd01836d609db8f2db62e88ab03c6332728a2bd"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "8": {"file": "moe_L08.safetensors", "sha256": {"wg": "8c11b5c1e22366ccfd6027f34e7cb57a2f6464041a40486a0754215055df2a2d", "sg": "1d4dced78d2649efc2b031b64707d5c6ba447c784f33f905a3f9f477b9a5dd04", "wu": "8b7a60d4039640bb8e05c4c75a619fc740c1df822c870d498c003c91fc232c1c", "su": "f0fe56c2020be58ec3a97d85431f20eab11f9bd152932e9b4fcc31d779b511f6", "wd": "60bd058c43a6730670848ed4d9a89eb4b4c149841d262e40332ebe65b7355997", "sd": "89a073f85cc471eaa55ead8a02e228dec6fe326535f3f5c2ec18e5c1e63c6a53"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "9": {"file": "moe_L09.safetensors", "sha256": {"wg": "f88868aa3fd35c198c7f771ce489b66c7adac2d26fe2f3efcd2ba3b0daff5b76", "sg": "70e292c35972b0ffea74c9a7c002fbcb4c9111dee4411ea5d630c70dcb8ff0cc", "wu": "30f62d2e890ccafd8e960d1ca146642a00a382861dea748076bcd520d1ffc18c", "su": "1c1052a8f0db5f1f0c51348adcc1bb8ed8835eff6fe63dc756d577f40383b2c8", "wd": "422b877a46c53194e03949e20e0fb889abd0aae2b1a02a2eaca46a9eae5f4d08", "sd": "ae65541bf7dace8cbac0e6aee38086ddef9be287d81732a1a709e277c894e7eb"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "10": {"file": "moe_L10.safetensors", "sha256": {"wg": "176783bdc830a954e818242452f4c5d12438be121d4551650552aac79413f396", "sg": "b3c9aadb85f2308b993cdf0ef401efa0d3af2f43f50e88a7969de11381e5d11b", "wu": "36e78b6303d97191a6e79e52d4e59373e2a6d67af44fa3352192c4893cd93355", "su": "97ca2180294054c422c4fd4287eb9016da68f220b5597f24930447f6e49efbe0", "wd": "030d823d362f1735ecc6f2e30ae33e65361e0a1862ca5401addcd3d7f12ac4e1", "sd": "5e5944450d7199fadb074358a9c2611c09f708e08dde3a3cf8a67fd4e9cf0159"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "11": {"file": "moe_L11.safetensors", "sha256": {"wg": "a2c25c54bff80748facec5822cc1af38a54184fec0f1370e198be124d932f35d", "sg": "06f56cbf4596f9ad2218958c6f91c4211b40ad27c680a370f076d26d50e89ae1", "wu": "86cfdae077123be0149c1fbf08f2093f1ad20a2452bcea5902e4dda650fcc002", "su": "ab76e68dfeade48d5c49de4013e72923c434ea150d1474eff94921e443c8f9b0", "wd": "66ae2c073deb2836dfb85226912ce587851b77a1e82ed54f4136362693ad0ae7", "sd": "47d67e5a8462d4fbcd2e400465d32be945cd0b3656538cdc9d26102a4b20e8b1"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "12": {"file": "moe_L12.safetensors", "sha256": {"wg": "4efec34d6bef7611278d88ce7ad1f367c6c71d248298b2e45b6f4a6849a300a2", "sg": "06a5460befc819e5f1aa5c7730264ce0667bb66fd948488f9348ffd91751db05", "wu": "857955af4892adc60473eaae8ea5a77b0dc339ac02bb334f6b3504ecdc1a4d0f", "su": "b0f2c3c12a3bef4db18c86c66aee885a0042ed11f637f4343ce7827c2bb76293", "wd": "55d1737ee2dbe099781556e3a879f98ddddfe1e5d87bcc43396f6484cf3cf582", "sd": "e4b58c0e904bd9ce92c757767bda6e885a7fe320808731bc0b2b0b2bf7b896ce"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "13": {"file": "moe_L13.safetensors", "sha256": {"wg": "bc4c9a0e532a34eadace0f4b22bfb88fd7b6522e8f14c201845b2d37b6db8fcf", "sg": "6a7a9756c426922972a1029e3487c9748db2b09f2c7de49f440f88b72f9d458e", "wu": "b75e9d1ec9845497751b7824449bc8a600f4f31dea4ca9c11c0976eff7ac13cc", "su": "903271606e692f1099cb4ffb2d0685824ef7fe17200d275fc61f991c2556dad8", "wd": "0f52f149b9161fafc9f4a5af58f6909346b514d96ff1671edc6a92f8a7f978d9", "sd": "f13047bb634dcc877ddcda4600942cb749413bbcb8454234adc97aa740ef1db0"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "14": {"file": "moe_L14.safetensors", "sha256": {"wg": "f6e7554c9f1b5920c5b4afcf50d71db405488ffc4afe866dace6177868a995d5", "sg": "fd61c5c57d7e3214da4764ee1ffdbb1e6de37b0ad501a12c2b97ee6fe9e62480", "wu": "edea561737b23dd9762510e99739aa2ee8d4fbadd221f7573a910260df612d06", "su": "66f348e462e98a4adc3689c3f5b36b20aefa2aa318b901b00fe0b01cd268d299", "wd": "6a3d330e3d4ccbe837ffe394b863ff2258e27fff42730eea80ce77378be5db48", "sd": "a2c4431263137b8ea73d405cbdab5e12d367da7aa010d49b8c88dc6088d24bc4"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "15": {"file": "moe_L15.safetensors", "sha256": {"wg": "9b6eb02579ee092763734f16e4a517899cb2b16b7835a975a8a26366e6f92705", "sg": "611ad86c5cbeab7cc3d4dfd09e7508b4f651e64aa3190c8ac0d933222bc0ca22", "wu": "768af351f5a341519b8c2f5fd3cf98c396b76ec450946a73a52e5e580935d624", "su": "c1e81ea2cc7e9cfc823a369f1a478a761f1ce5ce4deb2cd6a751ec606fb207cd", "wd": "b19b50ebfeef711d588eb19d5e5d55d2e3b596ea437677178972065cfe5af401", "sd": "b1d182945b2dd04d1b4588283e0b97c99d80f922da4da68c9a3e28ac8797919d"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "16": {"file": "moe_L16.safetensors", "sha256": {"wg": "d74e4db1f6c56e05e07de3726cd0ce332f96129187d34b686570c23ab510edd9", "sg": "e1085e94e763294c4232aac71880ab2a5559d9d8ac9bda6fcfce53895018ae6e", "wu": "0eae82dd6a00ae054fa49366b22efa43714fdfcd7b04bd89ec62a361b6ae4768", "su": "d0c510204d3db66f47f3ab51439e2197e57c06b990c3a65e004d54c25d371b94", "wd": "62975b17f47308b895470e7baa3f536ec011f6a033d2212654ca9a9ab1534d00", "sd": "4d70fe2a05074d6a567e7d5625ea6c94f08155cb4b00824670abab636993e018"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "17": {"file": "moe_L17.safetensors", "sha256": {"wg": "11aa976d768646d126986197ae39ac1160526d0805b5af1e43d241a867dbc245", "sg": "986575d003787372ebc2e8baf68b66a0c0d1938935c9da2a2abc54ddeb5a6b54", "wu": "92f60892ceae39408bf343a1e2114b035eb78dd252d95766ce8f21256b88a40b", "su": "81fd7da108cde39ad3d3ad38e194290ba0b18fcc2ef5c2ce6a2da5bcd5a86961", "wd": "61a9913f96101712b2638f5c9767561472649b22281df8a47cacc16c61f1031d", "sd": "af22bf370d434c09cb6d2cb210774b7dbe91ea4b3f1cf8b37c65560f3d6b5c81"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "18": {"file": "moe_L18.safetensors", "sha256": {"wg": "a41008f09354263768ec056856463a39deb94189f291bf709cdf6e9a7794a224", "sg": "4816e7ee78914f3af86e828ea0a146d3243330655352b53416f94cf47c7b8042", "wu": "e2eb1d617f1cd5b8993d0a7999e07970060d0dd939b7fbc843c0bf0a3b3da9c4", "su": "36eeda912b495f47b0c529cd7134dcd98165f4604ebd3bb1757c9cf97081bf69", "wd": "c23443bcba84d39da5b5ac35263c113e89e2d0571ef957b6e37d0cf9c0a0e557", "sd": "dcbc2e08c110166f1199122bbbd016eb60d502c81e0fc340f6b4eeacd540610d"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "19": {"file": "moe_L19.safetensors", "sha256": {"wg": "eb9ccb018990933eef9992046dfcda7467c055a3dd1ead3e2fffec1ea34d7be9", "sg": "83730dcf933b16053846dee242251f49207b6d2a11ad089558380ef8f3ef8b90", "wu": "385e842d850d71964d8f8facb2aede87da1f936753a51de3c0d58857cb710f30", "su": "1f9260b5d805c39fffbe2484e59873354f9f3648e3bd55de3455268ee57a0e2f", "wd": "01c379eac15c5d5e3dcf37984c19e4e0f96d7ab69173258c74f7e14fe7b2ffd3", "sd": "e4593c6370d6af529482765c6b7d52d600e7acdbc1e8d4379278b809d0f93cce"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "20": {"file": "moe_L20.safetensors", "sha256": {"wg": "f9b3cccbf18257fc6d154f5761bfaa71609f8afe1972e1a653f27294c4cfa89e", "sg": "55494ab5b378c99d5e1e63c4a3e66ec889cad2fbef45be67b3e721afa9d6f203", "wu": "f5441de77ab1b227056ca3b5e236b5bf1ca0575747d1e8878561ec1576933465", "su": "f4dc8a059d1b1842d772de4e58669fa49f98a4bc52f4609677fc099190d9314f", "wd": "4155ae1113fb447ad2818f9ba3cd9b1a12d8dd85c11a70dd27b506fdc21004fe", "sd": "79b302cafbcabbc8331a4b6697146880a0b2a3fbad733b2f7daecee025d40013"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "21": {"file": "moe_L21.safetensors", "sha256": {"wg": "de770101d18f01c09af250d8a470a412b38a198005982294a65520dafb470a94", "sg": "1e4ac74a87b0432dfd13ae97668220bc3f1428a7daab091834b9d5df2ead39a5", "wu": "764bc45234ee0043c72b086740a2c7bbfd83eddfc116ab5016015e74f4e3bb80", "su": "7683c674fe62687cceee90bb36802618b34fabb77eb0415057968f1e87fedb5e", "wd": "a57e08348284a6b91aa395da4a8caeeaafb394206c8e5e99bc595470c63ec378", "sd": "77841d8d03f2e4bcffd610cfa7e4dc91da0a93f66dadc5bd93dda846343f1d92"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "22": {"file": "moe_L22.safetensors", "sha256": {"wg": "8c5a7c93d381c3449545b6c3d945b8ec5667b147608e8a2bc30057e616975ba5", "sg": "fcb873f995c0f40100948d48365e6a6c0b7076bbaa7a739264db440ede8df8d7", "wu": "de48c9cd70025b5f34cd62f4968db23dd86176123f4f5c75f1246020ec080cfb", "su": "859ec7b3f23865ed8db1e3863970a0fe3dc4cfbfa952673559b14e75c0b20440", "wd": "c12b3e1c6d5a547330a17a28ce1a372ff56fd1b83db64072bbc5b5f152456f38", "sd": "c2bca0b48cd2cc83a6b0bac417f6efbfca63fdb8f8e640d74cf69a4f5b02be4f"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "23": {"file": "moe_L23.safetensors", "sha256": {"wg": "c376f7de7fed940d7d3bd917cfec7d43ee64dcefc85ba5688e3d03bdb14fccfc", "sg": "25fd58047329a808ac8665759687196f05c26cb68a539966d1b54fd379951fc1", "wu": "c577aa4bc7131ffdbb9f1533138a15a8c150e51a9904586859988de4ddbd50b0", "su": "3dd908171c8e94e777313d342ed7418cab427270b8b453fe16d43f7eabe0af19", "wd": "ecae091358c5330bf48404c185434a2bcb824b564184b0c0d441097f7b9fe853", "sd": "a8a96ba7740bbe4c38c0b64008b55d53633ffd2393083caa239a1292c6843977"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "24": {"file": "moe_L24.safetensors", "sha256": {"wg": "8d95c358ab909b82453e3107a515c0976ea0dd7f3ad0dfb9bb350694eff1f4e3", "sg": "95821bcdd762a97f4015777777923019c972a227a80dafa46c8d5d3a351756d3", "wu": "9a7e225ae919b27fdcfef70e11aa6da441aa4ec69e60da7daa2c63e8b59a86b1", "su": "a948323f6501d214a7d5940bef90ca885ad5ae9ecb501bebd516284d186cb9c0", "wd": "955ef784400bfafb02642cd9222e52c1a00030f11c04d3262049b8449bcc00ba", "sd": "f24c62a137eeb7e57763261ebf41a06e8e479dee58136f138deb2fafb95c8a8d"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "25": {"file": "moe_L25.safetensors", "sha256": {"wg": "6564e457d68ff5c550f118b8c700151a8c311a3289f545e5e9eb80bf815e7caa", "sg": "53f854594fae3ccbbb12e91eabc40839d06fc391da8c37cf0b2e0ece030ca9c3", "wu": "96ebcfd0a1d9f52670ff0cd15ad92c2a65bfd6a7b1b9cdd312f81e2685bd7aaa", "su": "a50d4e3efcf6dd33fd38722c73926993addbc6627f6219039f8b029ed27c4813", "wd": "2895acb18f40d02d23fe0d24080b94ab69227128d95faad68d5873e2293bbad2", "sd": "965462d0b8b7e3c975f5f134b781307c92837e4a8d7d62508674e2b80d7192bd"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "26": {"file": "moe_L26.safetensors", "sha256": {"wg": "feab418f9d727cc34e1b5d76f3d17ac27a37ed967a7cf1d4e7250b3be5586566", "sg": "972c6050fb3bbe5f0dc6e94c6f1026adbd51cbc99fba01596a9696ffa876f6cb", "wu": "17074da0a85833a42f9cfcac509d2d227054c33316ab080ac580ddbf2209d8bf", "su": "7f8fa0f18df2fef89bdfa79b892467b86f80850104c84db89d2f7a28cb17d479", "wd": "4e20c93304aff7762651039b169e9fe9920d47bbf87849418682b8214e1b6e73", "sd": "06b75263d7d87d64ea0ee5b6427d8521b212c0360f4390a46bba4301bddf394e"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "27": {"file": "moe_L27.safetensors", "sha256": {"wg": "ab746de5684285b202af6052ddd01d083e290a6b8a30b2475510fce0117d7769", "sg": "ed0c8e09221dcfc3a7ee3003a4e886e696c114d0afa2839578e1016c32084e3b", "wu": "d9fe47a221859994f16c71a332276ed8c2c2a8e4b27ecc06635b76bf7db9aec5", "su": "31a089ac6118953392cc32eae7cdcfa88999d1a241eea6a37eb76d6132c308e6", "wd": "0ad2a9b249437e17b8dd9c0f67a885ecaccdfd447b1b78920413a7069a0f3dc7", "sd": "648243a007aab856a13d1ae4aeabad2b2e30d97a3053d7e20723386e4594f101"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "28": {"file": "moe_L28.safetensors", "sha256": {"wg": "2c03e1427cdc59916f67bc50a170939d8170df5ac533d7caf5ba09d4e5a9a5c5", "sg": "67382d0230297a6a99d886b96357d7b6198441a6df6b161dc3fb2b0e65a83584", "wu": "2d32a7cb71b61b8a0c6c46c66d6f752e69671033c525e963027257c3dc78dd22", "su": "d2d5fa182a99ea24da349df6035364646d86bdb422b6dd4a6fc16231667bad54", "wd": "7b2c29774b752bf43857dd5903d8dc81671f7b1fc835839ddc4f51f640e8bbb4", "sd": "b2abf81efaf0a2ddb1acd7e94cfaaf373e3661750fe42cf1133ad5eea72281e5"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "29": {"file": "moe_L29.safetensors", "sha256": {"wg": "06b30062cdc5a433fa4a60ce18136ca568fcb147d0f34bcb9e4604ed603ae163", "sg": "29ec892a39fba87e50400618189af848011f26da6c3fb9ea3d2b8b628b835c69", "wu": "7e72573d273f7fbafb40b24ac97fb1f1c994b56a17e51d2b3a2ea6f8587ea7d2", "su": "67e7ceb4ab242305070131dc086b583d6c21740640ec43cc79902e6b181c3c13", "wd": "e8a62691c6b548c7f61f3db4f4bf4ab7af5481c91bfa716f8f03851dca053ec0", "sd": "6710cf9d3d01623337cdb1a8bef452622b0fd88e61292cf2ea3b475189f8c51c"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "30": {"file": "moe_L30.safetensors", "sha256": {"wg": "e09093616202cbbd5364262b311ad23701c99ea1f5fe8572f15325d75b7cb650", "sg": "e7cd13156c035c4f4382c49172fae8a516cdd4f70cf297e648d6912e6a92ae86", "wu": "db06fea0bc5212dd7c244babaf605af1041b1c4891961fcdd4e2b61a9bd9dc47", "su": "b784bef677af484e167769936e5bbcecbd84c3949a3d79aac87caa794401a45c", "wd": "fad14887ad4b711e0eddd3a8796a2d7821dfb2ea5c16be3f8763d9678e215ecf", "sd": "385124ad6463ba3139c9f7c87a28bcc696640baa4389208dceb5a74b3ed410dc"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "31": {"file": "moe_L31.safetensors", "sha256": {"wg": "8f7ec4ed264f4f888faa27f3ab23c49293653689a30ed7681d09cf7402e7f3f3", "sg": "e8efd8635d3efe2d3b39c6c0a45e45fd54b23d3339e63930fdf62c4c2c510c36", "wu": "4b8ef60eccb36ee3ea7a87e40dfc2f991b5a8f29ef9852f8070cd306cd5acc5b", "su": "e349e88e78d81bee568396b97f2e439afb64a2f074493fc236af1c1508fa5f31", "wd": "99f1650779ef5b56ff8269a812b7d56350140309e32a862dafc68d7f9a5ea3fa", "sd": "67a817799e44fe3716ebe2ca79d5ecc55ee071e78fe7b7553ef367d14c613b13"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "32": {"file": "moe_L32.safetensors", "sha256": {"wg": "fa694ade8e175006a15e6bc466979f92780effd4e0c61ececc814a6667059886", "sg": "1c5ffe36c27295db737a4c5e3840c513e7c3e647c97a3d4fa07b8854b6522633", "wu": "383df69d46df298fc5f4220aa61380c426141b6d720e2ece677eb725f3843cbc", "su": "f964d1677292c8aac96b2210801396cfaa33524bedc16921bd40fb32f5e608e0", "wd": "7e5d725de60ecd24482f22da270bced32b3cbe0ce24c992151768417bc8dbccc", "sd": "4cf56ec0667f63954326b65250d81e3ce7465b66354963b245890720cbe95c33"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "33": {"file": "moe_L33.safetensors", "sha256": {"wg": "f4b26ca670ba0f8bf699f870ee78c411fab6c2b1df22c93a7ed403d6adf9e650", "sg": "52aa0cfd333688934d649a25665e80fdb36b33e0015b4532aa258d1e64a0d416", "wu": "b384cefcbe8399affa38c72cbdc82435bf195ca7f3912def3f5747aac76ab708", "su": "370d665de67f0477cf7a6575b2b4428042b0a7c9df913fc4364def00bf297366", "wd": "896f3c1df6aa0126fce234378da6c36e73d9c37e96882e9fdcbcc90823544930", "sd": "22567e4ddc1432aa96c272c604062296350b5b0c41794e80539cd6a73cf8490f"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "34": {"file": "moe_L34.safetensors", "sha256": {"wg": "99768e1aa5a967cd5c28e72790a1dcc0b39a11265b5f542ebddaaf8cb97d59a3", "sg": "a11e06399a20aeee4f9d729801075558d4ab7844cb197a8202df435550d7376e", "wu": "13a90877527879c941a9526b9fe5c29ce70535fbf095f726ef8eddec1efc2920", "su": "fbd88a2e3e39e33b762a9ca7911cea969c12101f61a2c9170d23ba0f0fa28f25", "wd": "279a77557644eae91997a70ad7bb535b919ccd8934bd6e74343b46a6f357e394", "sd": "333f90a2a1cc62fcfaa1a65ee0a64a63756e70c59d803ae08e3a2c2f612a2914"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "35": {"file": "moe_L35.safetensors", "sha256": {"wg": "24719ccfc9f5451c07714986e334f0cb1ec72cb30243ac2321f6a32cd74f541b", "sg": "04b554fce5a8cce83e38955718a802d2d16e861520dfafae253ec70ac41907c6", "wu": "e418f7a669d39f4e43e0d16d814f8de0b3000b5636cfbae095867b9fddaa0bd0", "su": "2d44254efedb4820a1c616da3d1a13c47b219a41c8c81ffb8003f3545a430cc7", "wd": "a722c496fd19608e1b21eab2f10d57e0dd9150deee2f01efba422820a6314442", "sd": "031ea07c9f2742bbf10dfbd1a7df0d8e298f91bf7e28f27fb55dde88e466985c"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "36": {"file": "moe_L36.safetensors", "sha256": {"wg": "2809cd971176b5be6f24693a28705741b5b61c47e37230e59aa2871e54344977", "sg": "4028bd290f3756d38a0247a14ec6ab687bb4f46802146e8d75207f32e5f5c60c", "wu": "e756d3f0d988f81096df865d25922a06d202966288ebffddc110ed95afe5c33f", "su": "526721ed694c1372586dd7807eae6f4ed5145279aae0a308bdcce24c58af5374", "wd": "f1427952d9ca520787231f4d313004b8cc8f8fd70c30fe7316ab387e67d3188f", "sd": "069743c661ad1252dd51a1651ef6b3598c3c78ddb6f2b08bf1596d09c15b9058"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "37": {"file": "moe_L37.safetensors", "sha256": {"wg": "eda9bf4a7791252f7d4a760d12007449f8063eb77b5aee904976483f5d99d524", "sg": "03bfa628e7b439c5e446e46f41c40528a101757066eaa16442ce020148b60465", "wu": "b75e57adab5c6e789f07d181f676448c036e6afecb2a020c950e9b6ed1a0e2ad", "su": "3b87503797fdfea72b4be8c6e0456c225180a01c35ca9ee84059dd423326bba2", "wd": "3fa609341ac5ba6b85290a6bd8cd6764014239507ade6a5413265eeb3b8073c9", "sd": "456c5259374c92fb2cfa506a9a063912bb35b60b0cb3fc6bcf5cfe0f5a696aa0"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "38": {"file": "moe_L38.safetensors", "sha256": {"wg": "0ebfcc47f94d384d911777eb5b7173265c68da503e40a6ccf221648a74f71fdf", "sg": "29ffcb68bc1399d143d00f97c213bcc5389cff90f3a678461169f0378759a040", "wu": "a0273cfa771d9624df598638ed3ae0b23427eae8e4d33fed16e32e3ca309e82e", "su": "4bbd35970435384e06244319ff22bd82321f2643e208876b18c4bf3da3a6007c", "wd": "d61565b604c056003eae50280113f170b65c82f10d41fec1cef96ebf80e13dc9", "sd": "c9cdef2910a828600085f5bb8e495785086bd9cb08fb4f22eddbdb757d0787ac"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "39": {"file": "moe_L39.safetensors", "sha256": {"wg": "fae293335be5b30f4a9ffc8ee156c6cd334cd2f4ccfd78231a3957247e7ab83b", "sg": "2bd4a3fd1d4d9dec8246b6d7781c9fa137286b30661759636e34bc5c861709e3", "wu": "14952c590f9e63ff4ca44977c521da8e1858823c2113ab031f731aa392c79f4e", "su": "dd1c440f136d416abbb8b1facfd6f64025cdba5462171789e3948afaf8582235", "wd": "eb996606ca18c74921f365a089d60bacae363e06684158c37911118cf42cbd14", "sd": "7362782f7496ab71b1fdd952535c65b420161fa6c8b9e03b6b010c15a5658c72"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "40": {"file": "moe_L40.safetensors", "sha256": {"wg": "11f17102015f73b9a390e5709244aad67485219ee0a7aea8c5a2f8303027dd96", "sg": "4b5ed22430a3989066c3791fde76f0c227f54f5e7042a3ab42154fa08a5d1506", "wu": "67b24bafc5e7bdb3c714672584bb9cbeee60ded584146cf23b6276145c349476", "su": "de99445c6dd336086ea3d47bf418a19e54bba58e49c194955646d6853069a145", "wd": "3a6b3325bb9ac1645a198cd2f73f46e7638a213a4290346ae0f46b4eef403ca8", "sd": "d4e8de98904929f3af58093b2642649b471ceef10ca980fda27ee6829446e679"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "41": {"file": "moe_L41.safetensors", "sha256": {"wg": "741224c44c3876e6565437af71b948d2c4bdc2891df23ad2db33e2b89fd4ce2c", "sg": "a3cb010092e9aae319eac7d375a1a01d9a691c58356cf604de618a19920ffb5b", "wu": "9b7421cc2515238efe6806d013df77f192aba19f192479bb562adae56f1343e6", "su": "48a29c08e08ec225a83926822909f756235e79c812d098cf0c620b995b38472c", "wd": "7d0a5a9c9f71fdf46419b3d2db3e63a94634142764b0315797d7b9674f1be833", "sd": "1c9f70d20e0f84d8ee6d49bb3bbc82f6c54d1734fec9e3e4b2ebfbef56a9b38c"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "42": {"file": "moe_L42.safetensors", "sha256": {"wg": "26342f5d2082dc4a51de6e6a1b3eb98b891191a309ca44a57cdfcd86f388a82a", "sg": "ccea413fd62f7c918ff16373d2670e9993fc2402748e672835121ab2e596f248", "wu": "9f1d9fc7f952830436f242ef54b410e889531a52112a806d3c31cdbb6f63f70e", "su": "60800c9b1614a61834ba3cb7e6733ccb69c5ea9e0481ecc6454a62297a952e1f", "wd": "51f8357cf0c99c953073b6938288bce05ea1919aa4f68b154c2742e5cb68f573", "sd": "aab78a70a9608efefc24ae27c98933da54e18ba878ada680d5bcbfec98922089"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "43": {"file": "moe_L43.safetensors", "sha256": {"wg": "aaba6ea947f4279340b1656dc8c1ddc0e3ac9cfd3c3e446cabdc6d9d526fbfbb", "sg": "90698810e23c11b8c2e9a64f62aac9e305b404ee0ba20e0b151ac09570b71844", "wu": "7a16127bc09da36118a7106a32e9ceebee0141cb2afe320d46f61111aef1c579", "su": "83aad1fd310a09dc4695968fb996a1fcea235213019b42d41e9e2988e6dda29e", "wd": "4d36cd9d2648afcf83aca776717fe11ce6e54bf240e03fe48b7ffc486a53ce51", "sd": "e9e237b2de6c9596d1c504f0245223c9359df50a652f9f78844ebd94c89b8c10"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "44": {"file": "moe_L44.safetensors", "sha256": {"wg": "5283069f0ca1f254d5058ba2c4b5946ede71f3338eadd09acac3bc518ebb6f7b", "sg": "48d5e8b331e315dc0d81bae86d6562baae0dc45cf274507c1a2577a2ea6867fb", "wu": "c21baad35dee51bb6ccd3361073e87806d4c14ee66ae859392325e7bfc9cd792", "su": "9b6f5491631cefbfb41ae9a4bcce26bce43ac0e1f7ef7c27ca7e4acb2dc58461", "wd": "ff45f41d49569f8120dfc9850ff616fb564448a0630db7a27c439a8cc6addf80", "sd": "1d2bd6c9a93375becb4b40b89d4fe0a0a670037e4f9d71e6a609e6b2a6dcc7a7"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "45": {"file": "moe_L45.safetensors", "sha256": {"wg": "99aa58c3eab739a92104fac12a9bd74a6d6f3a19adeca498ef1b96a972ee65d8", "sg": "2efe5ab60e611104fa47b58b1bf4afdf9504220c873da950c7094ccb857355b2", "wu": "c3341163808d546eef61b9de38a9e5b207e83a59324638a31142689a818fbb2d", "su": "41aa675f0a0c75e4ac25f748d962e52e8cff45bfb44768c658e2d84ede58f912", "wd": "8e46970ba888e7dfbfc8285a1b5410f820e5ceec405e8749d94d4527151d0605", "sd": "141480407b212f2c55511a09b81bcc27eddfddb7fc36c85eb04a36eb8c131ec3"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "46": {"file": "moe_L46.safetensors", "sha256": {"wg": "c9443af48728ae3cc641c9b7d9fbd10cd8d124217fe417da996cf42cebd02ed1", "sg": "08604ed3a0c30bc7fc7cb8e819d58ed2d1da984b81be8d501d65d45ae388043e", "wu": "720539425ae7baeaa07a48c5e40de87ce46d7ad7ac0156cc8daaa70baaecc930", "su": "02f76b3c2471fb8499bb6ab74579e67009d85f1182d0f2c8935e9dfdf0495525", "wd": "bb0e3169f22f86c509995ff64db0b75154154cae5d1cfe6759f9bd6a5f28ce62", "sd": "c46698fe77432c2d31a61f503eff797edcfef9182425092f4ab3e7108778d9cd"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}, "47": {"file": "moe_L47.safetensors", "sha256": {"wg": "336992f61d7047d131676462d88929fc2b8d9327b5f596083eb9b8711aaa3c78", "sg": "f875e1b7c7a1bb3e6460f0ac110d63290e65dec3aca9b1db2a73bb51a63f55de", "wu": "59e504610b42d650b77f8270d5701ab24879c0cdf2d53ba29330fc7af2d9116a", "su": "c6c75343f397ca1b786cf3aa5f75fef4a88bb547d2d0ef07f7806a62bc352b9d", "wd": "f9649e3e7f203d36fc91e09ece6ae2e25498f0f5a9b6a7225255f1e42a3fbe89", "sd": "cb44041111b63a785f99e4b2b32012ce9a5178e9ca20f06135ab9f41ebe2fd35"}, "shape": {"wg": [256, 2048, 2048], "sg": [256, 2048, 128], "wu": [256, 2048, 2048], "su": [256, 2048, 128], "wd": [256, 4096, 1024], "sd": [256, 4096, 64]}, "dtype": {"wg": "int8", "sg": "uint8", "wu": "int8", "su": "uint8", "wd": "int8", "sd": "uint8"}}}}
|
model.safetensors.index.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
modeling_mimo_v2.py
ADDED
|
@@ -0,0 +1,1878 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
import math
|
| 19 |
+
from copy import copy
|
| 20 |
+
from types import SimpleNamespace
|
| 21 |
+
from typing import Callable, Optional, Union
|
| 22 |
+
|
| 23 |
+
import torch
|
| 24 |
+
import torch.nn as nn
|
| 25 |
+
import torch.nn.functional as F
|
| 26 |
+
|
| 27 |
+
from transformers.activations import ACT2FN
|
| 28 |
+
from transformers.cache_utils import Cache, DynamicCache
|
| 29 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 30 |
+
from transformers.generation import GenerationMixin
|
| 31 |
+
from transformers.integrations import use_kernel_forward_from_hub
|
| 32 |
+
from transformers.masking_utils import create_causal_mask, create_sliding_window_causal_mask
|
| 33 |
+
from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast
|
| 34 |
+
from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS, dynamic_rope_update
|
| 35 |
+
from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
|
| 36 |
+
from transformers.models.qwen2.configuration_qwen2 import Qwen2Config
|
| 37 |
+
from transformers.models.qwen2.modeling_qwen2 import Qwen2Model
|
| 38 |
+
from transformers.processing_utils import Unpack
|
| 39 |
+
from transformers.utils import TransformersKwargs, can_return_tuple, logging
|
| 40 |
+
|
| 41 |
+
from .configuration_mimo_v2 import MiMoV2Config
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
logger = logging.get_logger(__name__)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def rotate_half(x):
|
| 48 |
+
"""Rotates half the hidden dims of the input."""
|
| 49 |
+
x1 = x[..., : x.shape[-1] // 2]
|
| 50 |
+
x2 = x[..., x.shape[-1] // 2 :]
|
| 51 |
+
return torch.cat((-x2, x1), dim=-1)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
|
| 55 |
+
"""Applies rotary position embedding to query and key tensors."""
|
| 56 |
+
cos = cos.unsqueeze(unsqueeze_dim)
|
| 57 |
+
sin = sin.unsqueeze(unsqueeze_dim)
|
| 58 |
+
q_embed = (q * cos) + (rotate_half(q) * sin)
|
| 59 |
+
k_embed = (k * cos) + (rotate_half(k) * sin)
|
| 60 |
+
return q_embed, k_embed
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
|
| 64 |
+
batch, num_key_value_heads, slen, head_dim = hidden_states.shape
|
| 65 |
+
if n_rep == 1:
|
| 66 |
+
return hidden_states
|
| 67 |
+
hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
|
| 68 |
+
return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def eager_attention_forward(
|
| 72 |
+
module: nn.Module,
|
| 73 |
+
query: torch.Tensor,
|
| 74 |
+
key: torch.Tensor,
|
| 75 |
+
value: torch.Tensor,
|
| 76 |
+
attention_mask: Optional[torch.Tensor],
|
| 77 |
+
scaling: float,
|
| 78 |
+
dropout: float = 0.0,
|
| 79 |
+
sinks: Optional[torch.Tensor] = None,
|
| 80 |
+
**kwargs,
|
| 81 |
+
):
|
| 82 |
+
key_states = repeat_kv(key, module.num_key_value_groups)
|
| 83 |
+
value_states = repeat_kv(value, module.num_key_value_groups)
|
| 84 |
+
attn_weights = torch.matmul(query, key_states.transpose(2, 3)) * scaling
|
| 85 |
+
if attention_mask is not None:
|
| 86 |
+
causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
|
| 87 |
+
attn_weights = attn_weights + causal_mask
|
| 88 |
+
|
| 89 |
+
if sinks is not None:
|
| 90 |
+
sinks = module.attention_sink_bias.reshape(1, -1, 1, 1).expand(query.shape[0], -1, query.shape[-2], -1)
|
| 91 |
+
attn_weights = torch.cat([attn_weights, sinks], dim=-1)
|
| 92 |
+
|
| 93 |
+
attn_weights = attn_weights - attn_weights.max(dim=-1, keepdim=True).values
|
| 94 |
+
probs = F.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query.dtype)
|
| 95 |
+
|
| 96 |
+
if sinks is not None:
|
| 97 |
+
probs = probs[..., :-1]
|
| 98 |
+
|
| 99 |
+
attn_weights = nn.functional.dropout(probs, p=dropout, training=module.training)
|
| 100 |
+
attn_output = torch.matmul(attn_weights, value_states)
|
| 101 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
| 102 |
+
return attn_output, attn_weights
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
@use_kernel_forward_from_hub("RMSNorm")
|
| 106 |
+
class MiMoV2RMSNorm(nn.Module):
|
| 107 |
+
def __init__(self, hidden_size, eps=1e-6):
|
| 108 |
+
super().__init__()
|
| 109 |
+
self.weight = nn.Parameter(torch.ones(hidden_size))
|
| 110 |
+
self.variance_epsilon = eps
|
| 111 |
+
|
| 112 |
+
def forward(self, hidden_states):
|
| 113 |
+
input_dtype = hidden_states.dtype
|
| 114 |
+
hidden_states = hidden_states.to(torch.float32)
|
| 115 |
+
variance = hidden_states.pow(2).mean(-1, keepdim=True)
|
| 116 |
+
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
|
| 117 |
+
return self.weight * hidden_states.to(input_dtype)
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
class MiMoV2MLP(nn.Module):
|
| 121 |
+
def __init__(self, config, intermediate_size=None):
|
| 122 |
+
super().__init__()
|
| 123 |
+
self.config = config
|
| 124 |
+
self.hidden_size = config.hidden_size
|
| 125 |
+
self.intermediate_size = config.intermediate_size if intermediate_size is None else intermediate_size
|
| 126 |
+
self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
|
| 127 |
+
self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
|
| 128 |
+
self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False)
|
| 129 |
+
self.act_fn = ACT2FN[config.hidden_act]
|
| 130 |
+
|
| 131 |
+
def forward(self, hidden_states):
|
| 132 |
+
return self.down_proj(self.act_fn(self.gate_proj(hidden_states)) * self.up_proj(hidden_states))
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
class MiMoV2MoEGate(nn.Module):
|
| 136 |
+
def __init__(self, config):
|
| 137 |
+
super().__init__()
|
| 138 |
+
self.config = config
|
| 139 |
+
self.top_k = config.num_experts_per_tok
|
| 140 |
+
self.n_routed_experts = config.n_routed_experts
|
| 141 |
+
self.routed_scaling_factor = config.routed_scaling_factor if config.routed_scaling_factor is not None else 1.0
|
| 142 |
+
self.scoring_func = config.scoring_func
|
| 143 |
+
self.topk_method = config.topk_method
|
| 144 |
+
self.n_group = config.n_group
|
| 145 |
+
self.topk_group = config.topk_group
|
| 146 |
+
self.norm_topk_prob = config.norm_topk_prob
|
| 147 |
+
self.gating_dim = config.hidden_size
|
| 148 |
+
self.weight = nn.Parameter(torch.empty((self.n_routed_experts, self.gating_dim)))
|
| 149 |
+
if self.topk_method == "noaux_tc":
|
| 150 |
+
self.e_score_correction_bias = nn.Parameter(torch.empty((self.n_routed_experts)))
|
| 151 |
+
|
| 152 |
+
def forward(self, hidden_states):
|
| 153 |
+
bsz, seq_len, h = hidden_states.shape
|
| 154 |
+
hidden_states = hidden_states.view(-1, h)
|
| 155 |
+
logits = F.linear(hidden_states.type(torch.float32), self.weight.type(torch.float32), None)
|
| 156 |
+
if self.scoring_func == "sigmoid":
|
| 157 |
+
scores = logits.sigmoid()
|
| 158 |
+
else:
|
| 159 |
+
raise NotImplementedError(f"Unsupported scoring function for MoE gating: {self.scoring_func}")
|
| 160 |
+
|
| 161 |
+
if self.topk_method == "noaux_tc":
|
| 162 |
+
if self.training:
|
| 163 |
+
raise ValueError("MiMoV2 noaux_tc routing is only implemented for inference.")
|
| 164 |
+
scores_for_choice = scores.view(bsz * seq_len, -1) + self.e_score_correction_bias.unsqueeze(0)
|
| 165 |
+
group_scores = scores_for_choice.view(bsz * seq_len, self.n_group, -1).topk(2, dim=-1)[0].sum(dim=-1)
|
| 166 |
+
group_idx = torch.topk(group_scores, k=self.topk_group, dim=-1, sorted=False)[1]
|
| 167 |
+
group_mask = torch.zeros_like(group_scores)
|
| 168 |
+
group_mask.scatter_(1, group_idx, 1)
|
| 169 |
+
score_mask = (
|
| 170 |
+
group_mask.unsqueeze(-1)
|
| 171 |
+
.expand(bsz * seq_len, self.n_group, self.n_routed_experts // self.n_group)
|
| 172 |
+
.reshape(bsz * seq_len, -1)
|
| 173 |
+
)
|
| 174 |
+
tmp_scores = scores_for_choice.masked_fill(~score_mask.bool(), float("-inf"))
|
| 175 |
+
_, topk_idx = torch.topk(tmp_scores, k=self.top_k, dim=-1, sorted=False)
|
| 176 |
+
topk_weight = scores.gather(1, topk_idx)
|
| 177 |
+
else:
|
| 178 |
+
raise NotImplementedError(f"Unsupported TopK function for MoE gating: {self.topk_method}")
|
| 179 |
+
|
| 180 |
+
if self.top_k > 1 and self.norm_topk_prob:
|
| 181 |
+
denominator = topk_weight.sum(dim=-1, keepdim=True) + 1e-20
|
| 182 |
+
topk_weight = topk_weight / denominator
|
| 183 |
+
topk_weight = topk_weight * self.routed_scaling_factor
|
| 184 |
+
return topk_idx, topk_weight
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
class MiMoV2MoE(nn.Module):
|
| 188 |
+
def __init__(self, config):
|
| 189 |
+
super().__init__()
|
| 190 |
+
self.config = config
|
| 191 |
+
self.experts = nn.ModuleList(
|
| 192 |
+
[MiMoV2MLP(config, intermediate_size=config.moe_intermediate_size) for _ in range(config.n_routed_experts)]
|
| 193 |
+
)
|
| 194 |
+
self.gate = MiMoV2MoEGate(config)
|
| 195 |
+
|
| 196 |
+
def moe(self, hidden_states: torch.Tensor, topk_indices: torch.Tensor, topk_weights: torch.Tensor):
|
| 197 |
+
final_hidden_states = torch.zeros_like(hidden_states, dtype=topk_weights.dtype)
|
| 198 |
+
expert_mask = torch.nn.functional.one_hot(topk_indices, num_classes=len(self.experts))
|
| 199 |
+
expert_mask = expert_mask.permute(2, 0, 1)
|
| 200 |
+
|
| 201 |
+
for expert_idx, expert in enumerate(self.experts):
|
| 202 |
+
mask = expert_mask[expert_idx]
|
| 203 |
+
token_indices, weight_indices = torch.where(mask)
|
| 204 |
+
if token_indices.numel() > 0:
|
| 205 |
+
expert_weights = topk_weights[token_indices, weight_indices]
|
| 206 |
+
expert_input = hidden_states[token_indices]
|
| 207 |
+
expert_output = expert(expert_input)
|
| 208 |
+
final_hidden_states.index_add_(0, token_indices, expert_output * expert_weights.unsqueeze(-1))
|
| 209 |
+
|
| 210 |
+
return final_hidden_states.type(hidden_states.dtype)
|
| 211 |
+
|
| 212 |
+
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
|
| 213 |
+
orig_shape = hidden_states.shape
|
| 214 |
+
topk_indices, topk_weights = self.gate(hidden_states)
|
| 215 |
+
hidden_states = hidden_states.view(-1, hidden_states.shape[-1])
|
| 216 |
+
hidden_states = self.moe(hidden_states, topk_indices, topk_weights).view(*orig_shape)
|
| 217 |
+
return hidden_states
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
class MiMoV2Attention(nn.Module):
|
| 221 |
+
"""MiMoV2 attention.
|
| 222 |
+
|
| 223 |
+
`projection_layout` only controls how checkpoint weights are named and
|
| 224 |
+
stored: Flash uses separate q/k/v projections, while Pro uses fused qkv.
|
| 225 |
+
The attention computation after projection is shared.
|
| 226 |
+
"""
|
| 227 |
+
|
| 228 |
+
def __init__(self, config, is_swa: bool, layer_idx: int, projection_layout: str = "split"):
|
| 229 |
+
super().__init__()
|
| 230 |
+
if projection_layout not in {"split", "fused_qkv"}:
|
| 231 |
+
raise ValueError(f"Unsupported MiMoV2 attention projection layout: {projection_layout}")
|
| 232 |
+
|
| 233 |
+
self.config = config
|
| 234 |
+
self.layer_idx = layer_idx
|
| 235 |
+
self.is_swa = is_swa
|
| 236 |
+
self.is_causal = True
|
| 237 |
+
self.projection_layout = projection_layout
|
| 238 |
+
|
| 239 |
+
default_head_dim = config.hidden_size // config.num_attention_heads
|
| 240 |
+
default_v_head_dim = getattr(config, "v_head_dim", default_head_dim)
|
| 241 |
+
|
| 242 |
+
if is_swa:
|
| 243 |
+
self.head_dim = getattr(config, "swa_head_dim", getattr(config, "head_dim", default_head_dim))
|
| 244 |
+
self.v_head_dim = getattr(config, "swa_v_head_dim", default_v_head_dim)
|
| 245 |
+
self.num_attention_heads = getattr(config, "swa_num_attention_heads", config.num_attention_heads)
|
| 246 |
+
self.num_key_value_heads = getattr(config, "swa_num_key_value_heads", config.num_key_value_heads)
|
| 247 |
+
else:
|
| 248 |
+
self.head_dim = getattr(config, "head_dim", default_head_dim)
|
| 249 |
+
self.v_head_dim = getattr(config, "v_head_dim", self.head_dim)
|
| 250 |
+
self.num_attention_heads = config.num_attention_heads
|
| 251 |
+
self.num_key_value_heads = config.num_key_value_heads
|
| 252 |
+
|
| 253 |
+
self.rope_dim = int(self.head_dim * getattr(config, "partial_rotary_factor", 1.0))
|
| 254 |
+
if self.rope_dim % 2 != 0:
|
| 255 |
+
raise ValueError(
|
| 256 |
+
f"MiMoV2 rotary dimension must be even, got {self.rope_dim} from "
|
| 257 |
+
f"head_dim={self.head_dim} and partial_rotary_factor={getattr(config, 'partial_rotary_factor', 1.0)}"
|
| 258 |
+
)
|
| 259 |
+
self.num_key_value_groups = self.num_attention_heads // self.num_key_value_heads
|
| 260 |
+
self.attention_dropout = getattr(config, "attention_dropout", 0.0)
|
| 261 |
+
self.scaling = self.head_dim**-0.5
|
| 262 |
+
self.sliding_window = getattr(config, "sliding_window", None) if is_swa else None
|
| 263 |
+
self.q_size = self.num_attention_heads * self.head_dim
|
| 264 |
+
self.k_size = self.num_key_value_heads * self.head_dim
|
| 265 |
+
self.v_size = self.num_key_value_heads * self.v_head_dim
|
| 266 |
+
self.o_hidden_size = self.num_attention_heads * self.v_head_dim
|
| 267 |
+
self.v_scale = getattr(config, "attention_value_scale", None)
|
| 268 |
+
self.attention_sink_bias = (
|
| 269 |
+
nn.Parameter(torch.empty(self.num_attention_heads), requires_grad=False)
|
| 270 |
+
if (
|
| 271 |
+
(getattr(config, "add_full_attention_sink_bias", False) and not is_swa)
|
| 272 |
+
or (getattr(config, "add_swa_attention_sink_bias", False) and is_swa)
|
| 273 |
+
)
|
| 274 |
+
else None
|
| 275 |
+
)
|
| 276 |
+
|
| 277 |
+
attention_bias = getattr(config, "attention_bias", False)
|
| 278 |
+
if self.projection_layout == "fused_qkv":
|
| 279 |
+
self.qkv_proj = nn.Linear(
|
| 280 |
+
config.hidden_size,
|
| 281 |
+
self.q_size + self.k_size + self.v_size,
|
| 282 |
+
bias=attention_bias,
|
| 283 |
+
)
|
| 284 |
+
else:
|
| 285 |
+
self.q_proj = nn.Linear(config.hidden_size, self.q_size, bias=attention_bias)
|
| 286 |
+
self.k_proj = nn.Linear(config.hidden_size, self.k_size, bias=attention_bias)
|
| 287 |
+
self.v_proj = nn.Linear(config.hidden_size, self.v_size, bias=attention_bias)
|
| 288 |
+
self.o_proj = nn.Linear(self.o_hidden_size, config.hidden_size, bias=False)
|
| 289 |
+
|
| 290 |
+
def _forward_attention(
|
| 291 |
+
self,
|
| 292 |
+
query_states: torch.Tensor,
|
| 293 |
+
key_states: torch.Tensor,
|
| 294 |
+
value_states: torch.Tensor,
|
| 295 |
+
input_shape: torch.Size,
|
| 296 |
+
position_embeddings: tuple[torch.Tensor, torch.Tensor],
|
| 297 |
+
attention_mask: Optional[torch.Tensor],
|
| 298 |
+
past_key_values: Optional[Cache] = None,
|
| 299 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 300 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 301 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 302 |
+
if self.v_scale is not None:
|
| 303 |
+
value_states = value_states * self.v_scale
|
| 304 |
+
|
| 305 |
+
cos, sin = position_embeddings
|
| 306 |
+
query_rope, query_nope = query_states.split([self.rope_dim, self.head_dim - self.rope_dim], dim=-1)
|
| 307 |
+
key_rope, key_nope = key_states.split([self.rope_dim, self.head_dim - self.rope_dim], dim=-1)
|
| 308 |
+
query_rope, key_rope = apply_rotary_pos_emb(query_rope, key_rope, cos, sin)
|
| 309 |
+
query_states = torch.cat([query_rope, query_nope], dim=-1)
|
| 310 |
+
key_states = torch.cat([key_rope, key_nope], dim=-1)
|
| 311 |
+
|
| 312 |
+
if past_key_values is not None:
|
| 313 |
+
cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
|
| 314 |
+
key_states, value_states = past_key_values.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
| 315 |
+
|
| 316 |
+
attn_implementation = self.config._attn_implementation
|
| 317 |
+
if attn_implementation is not None and attn_implementation.startswith("paged|"):
|
| 318 |
+
raise ValueError(
|
| 319 |
+
"MiMoV2 remote code does not support paged attention cache. "
|
| 320 |
+
"Please use eager, sdpa, flex_attention, or flash_attention_2."
|
| 321 |
+
)
|
| 322 |
+
|
| 323 |
+
attention_interface: Callable = ALL_ATTENTION_FUNCTIONS.get_interface(
|
| 324 |
+
attn_implementation, eager_attention_forward
|
| 325 |
+
)
|
| 326 |
+
if self.attention_sink_bias is not None and attn_implementation == "sdpa":
|
| 327 |
+
logger.warning_once(
|
| 328 |
+
"MiMoV2 attention sink bias is not supported by SDPA; falling back to eager attention for correctness."
|
| 329 |
+
)
|
| 330 |
+
attention_interface = eager_attention_forward
|
| 331 |
+
|
| 332 |
+
attention_kwargs = {
|
| 333 |
+
"dropout": 0.0 if not self.training else self.attention_dropout,
|
| 334 |
+
"scaling": self.scaling,
|
| 335 |
+
"position_ids": position_ids,
|
| 336 |
+
"is_causal": self.is_causal,
|
| 337 |
+
}
|
| 338 |
+
if attention_interface is eager_attention_forward:
|
| 339 |
+
attention_kwargs["sinks"] = self.attention_sink_bias
|
| 340 |
+
else:
|
| 341 |
+
if self.attention_sink_bias is not None:
|
| 342 |
+
attention_kwargs["s_aux"] = self.attention_sink_bias
|
| 343 |
+
if self.sliding_window is not None:
|
| 344 |
+
attention_kwargs["sliding_window"] = self.sliding_window
|
| 345 |
+
|
| 346 |
+
attn_output, attn_weights = attention_interface(
|
| 347 |
+
self,
|
| 348 |
+
query_states,
|
| 349 |
+
key_states,
|
| 350 |
+
value_states,
|
| 351 |
+
attention_mask,
|
| 352 |
+
**attention_kwargs,
|
| 353 |
+
)
|
| 354 |
+
attn_output = attn_output.reshape(*input_shape, -1).contiguous()
|
| 355 |
+
attn_output = self.o_proj(attn_output)
|
| 356 |
+
return attn_output, attn_weights
|
| 357 |
+
|
| 358 |
+
def forward(
|
| 359 |
+
self,
|
| 360 |
+
hidden_states: torch.Tensor,
|
| 361 |
+
position_embeddings: tuple[torch.Tensor, torch.Tensor],
|
| 362 |
+
attention_mask: Optional[torch.Tensor],
|
| 363 |
+
past_key_values: Optional[Cache] = None,
|
| 364 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 365 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 366 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 367 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 368 |
+
input_shape = hidden_states.shape[:-1]
|
| 369 |
+
|
| 370 |
+
if self.projection_layout == "fused_qkv":
|
| 371 |
+
qkv_states = self.qkv_proj(hidden_states)
|
| 372 |
+
query_states, key_states, value_states = qkv_states.split([self.q_size, self.k_size, self.v_size], dim=-1)
|
| 373 |
+
else:
|
| 374 |
+
query_states = self.q_proj(hidden_states)
|
| 375 |
+
key_states = self.k_proj(hidden_states)
|
| 376 |
+
value_states = self.v_proj(hidden_states)
|
| 377 |
+
|
| 378 |
+
query_states = query_states.view(*input_shape, self.num_attention_heads, self.head_dim).transpose(1, 2)
|
| 379 |
+
key_states = key_states.view(*input_shape, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 380 |
+
value_states = value_states.view(*input_shape, self.num_key_value_heads, self.v_head_dim).transpose(1, 2)
|
| 381 |
+
return self._forward_attention(
|
| 382 |
+
query_states,
|
| 383 |
+
key_states,
|
| 384 |
+
value_states,
|
| 385 |
+
input_shape,
|
| 386 |
+
position_embeddings,
|
| 387 |
+
attention_mask,
|
| 388 |
+
past_key_values=past_key_values,
|
| 389 |
+
cache_position=cache_position,
|
| 390 |
+
position_ids=position_ids,
|
| 391 |
+
)
|
| 392 |
+
|
| 393 |
+
|
| 394 |
+
class MiMoV2DecoderLayer(nn.Module):
|
| 395 |
+
attention_projection_layout = "split"
|
| 396 |
+
|
| 397 |
+
def __init__(self, config, layer_idx: int, attention_projection_layout: Optional[str] = None):
|
| 398 |
+
super().__init__()
|
| 399 |
+
attention_projection_layout = attention_projection_layout or self.attention_projection_layout
|
| 400 |
+
is_swa_layer = config.hybrid_layer_pattern[layer_idx] == 1
|
| 401 |
+
self.attention_type = "sliding_window_attention" if is_swa_layer else "full_attention"
|
| 402 |
+
self.self_attn = MiMoV2Attention(
|
| 403 |
+
config, is_swa_layer, layer_idx, projection_layout=attention_projection_layout
|
| 404 |
+
)
|
| 405 |
+
self.mlp = (
|
| 406 |
+
MiMoV2MoE(config)
|
| 407 |
+
if getattr(config, "n_routed_experts", None) is not None and config.moe_layer_freq[layer_idx]
|
| 408 |
+
else MiMoV2MLP(config)
|
| 409 |
+
)
|
| 410 |
+
self.input_layernorm = MiMoV2RMSNorm(config.hidden_size, eps=config.layernorm_epsilon)
|
| 411 |
+
self.post_attention_layernorm = MiMoV2RMSNorm(config.hidden_size, eps=config.layernorm_epsilon)
|
| 412 |
+
|
| 413 |
+
def forward(
|
| 414 |
+
self,
|
| 415 |
+
hidden_states: torch.Tensor,
|
| 416 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 417 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 418 |
+
past_key_values: Optional[Cache] = None,
|
| 419 |
+
use_cache: Optional[bool] = False,
|
| 420 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 421 |
+
position_embeddings: Optional[tuple[torch.Tensor, torch.Tensor]] = None,
|
| 422 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 423 |
+
) -> torch.Tensor:
|
| 424 |
+
residual = hidden_states
|
| 425 |
+
hidden_states = self.input_layernorm(hidden_states)
|
| 426 |
+
hidden_states, _ = self.self_attn(
|
| 427 |
+
hidden_states=hidden_states,
|
| 428 |
+
attention_mask=attention_mask,
|
| 429 |
+
position_ids=position_ids,
|
| 430 |
+
past_key_values=past_key_values,
|
| 431 |
+
use_cache=use_cache,
|
| 432 |
+
cache_position=cache_position,
|
| 433 |
+
position_embeddings=position_embeddings,
|
| 434 |
+
**kwargs,
|
| 435 |
+
)
|
| 436 |
+
hidden_states = residual + hidden_states
|
| 437 |
+
|
| 438 |
+
residual = hidden_states
|
| 439 |
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
| 440 |
+
hidden_states = self.mlp(hidden_states)
|
| 441 |
+
hidden_states = residual + hidden_states
|
| 442 |
+
return hidden_states
|
| 443 |
+
|
| 444 |
+
|
| 445 |
+
class MiMoV2RotaryEmbedding(nn.Module):
|
| 446 |
+
inv_freq: torch.Tensor
|
| 447 |
+
|
| 448 |
+
def __init__(self, config, is_swa: bool, device=None):
|
| 449 |
+
super().__init__()
|
| 450 |
+
if hasattr(config, "rope_scaling") and isinstance(config.rope_scaling, dict):
|
| 451 |
+
self.rope_type = config.rope_scaling.get("rope_type", config.rope_scaling.get("type", "default"))
|
| 452 |
+
else:
|
| 453 |
+
self.rope_type = "default"
|
| 454 |
+
self.max_seq_len_cached = config.max_position_embeddings
|
| 455 |
+
self.original_max_seq_len = config.max_position_embeddings
|
| 456 |
+
|
| 457 |
+
self.config = copy(config)
|
| 458 |
+
self.config.rope_parameters = copy(getattr(config, "rope_parameters", None) or {})
|
| 459 |
+
if is_swa:
|
| 460 |
+
self.config.rope_theta = getattr(config, "swa_rope_theta", config.rope_theta)
|
| 461 |
+
self.config.head_dim = getattr(config, "swa_head_dim", getattr(config, "head_dim", None))
|
| 462 |
+
if self.config.rope_parameters:
|
| 463 |
+
self.config.rope_parameters["rope_theta"] = self.config.rope_theta
|
| 464 |
+
self.rope_init_fn = (
|
| 465 |
+
self.compute_default_rope_parameters
|
| 466 |
+
if self.rope_type == "default"
|
| 467 |
+
else ROPE_INIT_FUNCTIONS[self.rope_type]
|
| 468 |
+
)
|
| 469 |
+
|
| 470 |
+
inv_freq, self.attention_scaling = self.rope_init_fn(self.config, device)
|
| 471 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
| 472 |
+
self.original_inv_freq = self.inv_freq
|
| 473 |
+
|
| 474 |
+
@staticmethod
|
| 475 |
+
def compute_default_rope_parameters(config, device=None, seq_len=None, layer_type=None):
|
| 476 |
+
config.standardize_rope_params()
|
| 477 |
+
rope_parameters = config.rope_parameters[layer_type] if layer_type is not None else config.rope_parameters
|
| 478 |
+
base = rope_parameters["rope_theta"]
|
| 479 |
+
partial_rotary_factor = rope_parameters.get("partial_rotary_factor", 1.0)
|
| 480 |
+
head_dim = getattr(config, "head_dim", None) or config.hidden_size // config.num_attention_heads
|
| 481 |
+
dim = int(head_dim * partial_rotary_factor)
|
| 482 |
+
if dim % 2 != 0:
|
| 483 |
+
raise ValueError(
|
| 484 |
+
f"MiMoV2 rotary dimension must be even, got {dim} from "
|
| 485 |
+
f"head_dim={head_dim} and partial_rotary_factor={partial_rotary_factor}"
|
| 486 |
+
)
|
| 487 |
+
inv_freq = 1.0 / (
|
| 488 |
+
base ** (torch.arange(0, dim, 2, dtype=torch.int64).to(device=device, dtype=torch.float) / dim)
|
| 489 |
+
)
|
| 490 |
+
return inv_freq, 1.0
|
| 491 |
+
|
| 492 |
+
@torch.no_grad()
|
| 493 |
+
@dynamic_rope_update
|
| 494 |
+
def forward(self, x, position_ids):
|
| 495 |
+
inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1).to(x.device)
|
| 496 |
+
position_ids_expanded = position_ids[:, None, :].float()
|
| 497 |
+
|
| 498 |
+
device_type = x.device.type if isinstance(x.device.type, str) and x.device.type != "mps" else "cpu"
|
| 499 |
+
with torch.autocast(device_type=device_type, enabled=False):
|
| 500 |
+
freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
|
| 501 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
| 502 |
+
cos = emb.cos() * self.attention_scaling
|
| 503 |
+
sin = emb.sin() * self.attention_scaling
|
| 504 |
+
|
| 505 |
+
return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
# ---------------------------------------------------------------------------
|
| 509 |
+
# Multimodal helpers
|
| 510 |
+
# ---------------------------------------------------------------------------
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
def _as_namespace(config_like):
|
| 514 |
+
if config_like is None:
|
| 515 |
+
return SimpleNamespace()
|
| 516 |
+
if isinstance(config_like, dict):
|
| 517 |
+
return SimpleNamespace(**config_like)
|
| 518 |
+
return config_like
|
| 519 |
+
|
| 520 |
+
|
| 521 |
+
def _parse_maybe_list(value: str | int, length: int) -> list[int]:
|
| 522 |
+
if isinstance(value, str) and "-" in value:
|
| 523 |
+
return [int(x) for x in value.split("-")]
|
| 524 |
+
return [int(value)] * length
|
| 525 |
+
|
| 526 |
+
|
| 527 |
+
def _build_speech_embeddings(config) -> nn.ModuleList:
|
| 528 |
+
audio_channels = getattr(config, "audio_channels")
|
| 529 |
+
input_local_dim = getattr(config, "input_local_dim")
|
| 530 |
+
speech_empty_ids = _parse_maybe_list(getattr(config, "speech_zeroemb_idx"), audio_channels)
|
| 531 |
+
speech_vocab_sizes = _parse_maybe_list(getattr(config, "speech_vocab_size"), audio_channels)
|
| 532 |
+
return nn.ModuleList(
|
| 533 |
+
[
|
| 534 |
+
nn.Embedding(speech_vocab_sizes[i], input_local_dim, padding_idx=speech_empty_ids[i])
|
| 535 |
+
for i in range(audio_channels)
|
| 536 |
+
]
|
| 537 |
+
)
|
| 538 |
+
|
| 539 |
+
|
| 540 |
+
def _pad_and_group_audio_codes(
|
| 541 |
+
audio_codes: torch.Tensor, audio_channels: int, group_size: int
|
| 542 |
+
) -> torch.Tensor:
|
| 543 |
+
"""Slice to `audio_channels`, pad to `group_size` boundary, reshape to [G, group_size, C]."""
|
| 544 |
+
if audio_codes.dim() != 2:
|
| 545 |
+
raise ValueError(f"`audio_codes` must be 2D [T, C], got shape={tuple(audio_codes.shape)}")
|
| 546 |
+
audio_codes = audio_codes[:, :audio_channels]
|
| 547 |
+
T = audio_codes.shape[0]
|
| 548 |
+
padded_T = ((T + group_size - 1) // group_size) * group_size
|
| 549 |
+
if padded_T > T:
|
| 550 |
+
audio_codes = torch.cat([audio_codes, audio_codes[-1:].expand(padded_T - T, -1)], dim=0)
|
| 551 |
+
return audio_codes.reshape(padded_T // group_size, group_size, audio_channels)
|
| 552 |
+
|
| 553 |
+
|
| 554 |
+
def _replace_modal_embeddings_inplace(
|
| 555 |
+
input_ids: torch.Tensor,
|
| 556 |
+
inputs_embeds: torch.Tensor,
|
| 557 |
+
token_id: int | None,
|
| 558 |
+
modal_embeds: torch.Tensor | None,
|
| 559 |
+
) -> None:
|
| 560 |
+
if token_id is None or modal_embeds is None:
|
| 561 |
+
return
|
| 562 |
+
|
| 563 |
+
if modal_embeds.dim() != 2:
|
| 564 |
+
raise ValueError(f"`modal_embeds` must be 2D [N, H], got shape={tuple(modal_embeds.shape)}")
|
| 565 |
+
|
| 566 |
+
mask = input_ids.eq(token_id)
|
| 567 |
+
num_slots = int(mask.sum().item())
|
| 568 |
+
if num_slots == 0:
|
| 569 |
+
return
|
| 570 |
+
|
| 571 |
+
if modal_embeds.shape[0] != num_slots:
|
| 572 |
+
raise ValueError(
|
| 573 |
+
f"Modal embedding count mismatch for token_id={token_id}: "
|
| 574 |
+
f"found {num_slots} placeholders but got {modal_embeds.shape[0]} embeddings."
|
| 575 |
+
)
|
| 576 |
+
|
| 577 |
+
inputs_embeds[mask] = modal_embeds.to(device=inputs_embeds.device, dtype=inputs_embeds.dtype)
|
| 578 |
+
|
| 579 |
+
|
| 580 |
+
# ---------------------------------------------------------------------------
|
| 581 |
+
# Vision encoder
|
| 582 |
+
# ---------------------------------------------------------------------------
|
| 583 |
+
|
| 584 |
+
|
| 585 |
+
def _rotate_half_vision(x: torch.Tensor) -> torch.Tensor:
|
| 586 |
+
x1 = x[..., : x.shape[-1] // 2]
|
| 587 |
+
x2 = x[..., x.shape[-1] // 2 :]
|
| 588 |
+
return torch.cat((-x2, x1), dim=-1)
|
| 589 |
+
|
| 590 |
+
|
| 591 |
+
def _apply_rotary_pos_emb_vision(
|
| 592 |
+
q: torch.Tensor, k: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor
|
| 593 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 594 |
+
orig_q_dtype, orig_k_dtype = q.dtype, k.dtype
|
| 595 |
+
q, k = q.float(), k.float()
|
| 596 |
+
cos, sin = cos.unsqueeze(-2).float(), sin.unsqueeze(-2).float()
|
| 597 |
+
q_embed = (q * cos) + (_rotate_half_vision(q) * sin)
|
| 598 |
+
k_embed = (k * cos) + (_rotate_half_vision(k) * sin)
|
| 599 |
+
return q_embed.to(orig_q_dtype), k_embed.to(orig_k_dtype)
|
| 600 |
+
|
| 601 |
+
|
| 602 |
+
class MiMoVisionRotaryEmbedding(nn.Module):
|
| 603 |
+
def __init__(self, dim: int, theta: float = 10000.0) -> None:
|
| 604 |
+
super().__init__()
|
| 605 |
+
inv_freq = 1.0 / (theta ** (torch.arange(0, dim, 2, dtype=torch.float) / dim))
|
| 606 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
| 607 |
+
|
| 608 |
+
def forward(self, seqlen: int) -> torch.Tensor:
|
| 609 |
+
seq = torch.arange(seqlen, device=self.inv_freq.device, dtype=self.inv_freq.dtype)
|
| 610 |
+
return torch.outer(seq, self.inv_freq)
|
| 611 |
+
|
| 612 |
+
|
| 613 |
+
class MiMoVisionPatchEmbed(nn.Module):
|
| 614 |
+
def __init__(
|
| 615 |
+
self, patch_size: int = 16, temporal_patch_size: int = 2, in_channels: int = 3, embed_dim: int = 1280
|
| 616 |
+
):
|
| 617 |
+
super().__init__()
|
| 618 |
+
self.patch_size = patch_size
|
| 619 |
+
self.temporal_patch_size = temporal_patch_size
|
| 620 |
+
self.in_channels = in_channels
|
| 621 |
+
self.embed_dim = embed_dim
|
| 622 |
+
kernel_size = [temporal_patch_size, patch_size, patch_size]
|
| 623 |
+
self.proj = nn.Conv3d(in_channels, embed_dim, kernel_size=kernel_size, stride=kernel_size, bias=False)
|
| 624 |
+
|
| 625 |
+
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
|
| 626 |
+
target_dtype = self.proj.weight.dtype
|
| 627 |
+
hidden_states = hidden_states.view(
|
| 628 |
+
-1, self.in_channels, self.temporal_patch_size, self.patch_size, self.patch_size
|
| 629 |
+
)
|
| 630 |
+
return self.proj(hidden_states.to(dtype=target_dtype)).view(-1, self.embed_dim)
|
| 631 |
+
|
| 632 |
+
|
| 633 |
+
class MiMoVisionSwiGLUMLP(nn.Module):
|
| 634 |
+
def __init__(self, dim: int, intermediate_dim: int, hidden_act: str = "silu"):
|
| 635 |
+
super().__init__()
|
| 636 |
+
self.gate_proj = nn.Linear(dim, intermediate_dim, bias=True)
|
| 637 |
+
self.up_proj = nn.Linear(dim, intermediate_dim, bias=True)
|
| 638 |
+
self.down_proj = nn.Linear(intermediate_dim, dim, bias=True)
|
| 639 |
+
self.act_fn = ACT2FN[hidden_act]
|
| 640 |
+
|
| 641 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 642 |
+
return self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
|
| 643 |
+
|
| 644 |
+
|
| 645 |
+
class MiMoVisionAttention(nn.Module):
|
| 646 |
+
def __init__(
|
| 647 |
+
self,
|
| 648 |
+
dim: int,
|
| 649 |
+
num_heads: int,
|
| 650 |
+
num_kv_heads: int | None = None,
|
| 651 |
+
head_dim: int | None = None,
|
| 652 |
+
use_sinks: bool = False,
|
| 653 |
+
window_size: int = -1,
|
| 654 |
+
):
|
| 655 |
+
super().__init__()
|
| 656 |
+
self.dim = dim
|
| 657 |
+
self.num_heads = num_heads
|
| 658 |
+
self.num_kv_heads = num_kv_heads if num_kv_heads is not None else num_heads
|
| 659 |
+
self.head_dim = head_dim if head_dim is not None else dim // num_heads
|
| 660 |
+
self.num_kv_groups = self.num_heads // self.num_kv_heads
|
| 661 |
+
self.scaling = self.head_dim**-0.5
|
| 662 |
+
self.window_size = window_size
|
| 663 |
+
|
| 664 |
+
qkv_dim = (self.num_heads + 2 * self.num_kv_heads) * self.head_dim
|
| 665 |
+
self.qkv = nn.Linear(dim, qkv_dim, bias=True)
|
| 666 |
+
self.proj = nn.Linear(self.num_heads * self.head_dim, dim, bias=True)
|
| 667 |
+
self.sinks = nn.Parameter(torch.zeros(self.num_heads)) if use_sinks else None
|
| 668 |
+
|
| 669 |
+
def _build_window_mask(self, seq_len: int, device: torch.device, dtype: torch.dtype) -> torch.Tensor | None:
|
| 670 |
+
if self.window_size <= 0:
|
| 671 |
+
return None
|
| 672 |
+
row_idx = torch.arange(seq_len, device=device).unsqueeze(1)
|
| 673 |
+
col_idx = torch.arange(seq_len, device=device).unsqueeze(0)
|
| 674 |
+
mask = torch.zeros(seq_len, seq_len, device=device, dtype=dtype)
|
| 675 |
+
mask = mask.masked_fill((row_idx - col_idx).abs() > self.window_size, float("-inf"))
|
| 676 |
+
return mask
|
| 677 |
+
|
| 678 |
+
def forward(
|
| 679 |
+
self,
|
| 680 |
+
hidden_states: torch.Tensor,
|
| 681 |
+
cu_seqlens: torch.Tensor,
|
| 682 |
+
position_embeddings: tuple[torch.Tensor, torch.Tensor],
|
| 683 |
+
full_attn: bool = False,
|
| 684 |
+
) -> torch.Tensor:
|
| 685 |
+
seq_len = hidden_states.shape[0]
|
| 686 |
+
qkv = self.qkv(hidden_states)
|
| 687 |
+
|
| 688 |
+
q_dim = self.num_heads * self.head_dim
|
| 689 |
+
kv_dim = self.num_kv_heads * self.head_dim
|
| 690 |
+
q = qkv[:, :q_dim].view(seq_len, self.num_heads, self.head_dim)
|
| 691 |
+
k = qkv[:, q_dim : q_dim + kv_dim].view(seq_len, self.num_kv_heads, self.head_dim)
|
| 692 |
+
v = qkv[:, q_dim + kv_dim :].view(seq_len, self.num_kv_heads, self.head_dim)
|
| 693 |
+
|
| 694 |
+
cos, sin = position_embeddings
|
| 695 |
+
q, k = _apply_rotary_pos_emb_vision(q, k, cos, sin)
|
| 696 |
+
|
| 697 |
+
lengths = cu_seqlens[1:] - cu_seqlens[:-1]
|
| 698 |
+
q_chunks = torch.split(q, lengths.tolist(), dim=0)
|
| 699 |
+
k_chunks = torch.split(k, lengths.tolist(), dim=0)
|
| 700 |
+
v_chunks = torch.split(v, lengths.tolist(), dim=0)
|
| 701 |
+
|
| 702 |
+
outputs = []
|
| 703 |
+
for q_c, k_c, v_c in zip(q_chunks, k_chunks, v_chunks):
|
| 704 |
+
q_c = q_c.unsqueeze(0).transpose(1, 2)
|
| 705 |
+
k_c = k_c.unsqueeze(0).transpose(1, 2)
|
| 706 |
+
v_c = v_c.unsqueeze(0).transpose(1, 2)
|
| 707 |
+
|
| 708 |
+
if self.num_kv_groups > 1:
|
| 709 |
+
k_c = k_c.repeat_interleave(self.num_kv_groups, dim=1)
|
| 710 |
+
v_c = v_c.repeat_interleave(self.num_kv_groups, dim=1)
|
| 711 |
+
|
| 712 |
+
attn_mask = None
|
| 713 |
+
if not full_attn:
|
| 714 |
+
attn_mask = self._build_window_mask(q_c.shape[2], q_c.device, q_c.dtype)
|
| 715 |
+
|
| 716 |
+
if self.sinks is not None:
|
| 717 |
+
sink_bias = torch.zeros(
|
| 718 |
+
1, self.num_heads, q_c.shape[2], k_c.shape[2], device=q_c.device, dtype=q_c.dtype
|
| 719 |
+
)
|
| 720 |
+
sink_bias[..., 0] = self.sinks.view(1, self.num_heads, 1)
|
| 721 |
+
attn_mask = sink_bias if attn_mask is None else attn_mask + sink_bias
|
| 722 |
+
|
| 723 |
+
attn_out = F.scaled_dot_product_attention(q_c, k_c, v_c, attn_mask=attn_mask, scale=self.scaling)
|
| 724 |
+
outputs.append(attn_out.squeeze(0).transpose(0, 1))
|
| 725 |
+
|
| 726 |
+
attn_output = torch.cat(outputs, dim=0)
|
| 727 |
+
attn_output = attn_output.reshape(seq_len, -1)
|
| 728 |
+
return self.proj(attn_output)
|
| 729 |
+
|
| 730 |
+
|
| 731 |
+
class MiMoVisionBlock(nn.Module):
|
| 732 |
+
def __init__(
|
| 733 |
+
self,
|
| 734 |
+
dim: int,
|
| 735 |
+
intermediate_dim: int,
|
| 736 |
+
num_heads: int,
|
| 737 |
+
num_kv_heads: int | None = None,
|
| 738 |
+
head_dim: int | None = None,
|
| 739 |
+
hidden_act: str = "silu",
|
| 740 |
+
rms_norm_eps: float = 1e-6,
|
| 741 |
+
use_sinks: bool = False,
|
| 742 |
+
window_size: int = -1,
|
| 743 |
+
):
|
| 744 |
+
super().__init__()
|
| 745 |
+
self.norm1 = nn.RMSNorm(dim, eps=rms_norm_eps)
|
| 746 |
+
self.norm2 = nn.RMSNorm(dim, eps=rms_norm_eps)
|
| 747 |
+
self.attn = MiMoVisionAttention(
|
| 748 |
+
dim=dim, num_heads=num_heads, num_kv_heads=num_kv_heads, head_dim=head_dim,
|
| 749 |
+
use_sinks=use_sinks, window_size=window_size,
|
| 750 |
+
)
|
| 751 |
+
self.mlp = MiMoVisionSwiGLUMLP(dim=dim, intermediate_dim=intermediate_dim, hidden_act=hidden_act)
|
| 752 |
+
|
| 753 |
+
def forward(
|
| 754 |
+
self,
|
| 755 |
+
hidden_states: torch.Tensor,
|
| 756 |
+
cu_seqlens: torch.Tensor,
|
| 757 |
+
position_embeddings: tuple[torch.Tensor, torch.Tensor],
|
| 758 |
+
full_attn: bool = False,
|
| 759 |
+
) -> torch.Tensor:
|
| 760 |
+
hidden_states = hidden_states + self.attn(
|
| 761 |
+
self.norm1(hidden_states), cu_seqlens=cu_seqlens,
|
| 762 |
+
position_embeddings=position_embeddings, full_attn=full_attn,
|
| 763 |
+
)
|
| 764 |
+
hidden_states = hidden_states + self.mlp(self.norm2(hidden_states))
|
| 765 |
+
return hidden_states
|
| 766 |
+
|
| 767 |
+
|
| 768 |
+
class MiMoVisionPatchMerger(nn.Module):
|
| 769 |
+
def __init__(self, dim: int, context_dim: int, spatial_merge_size: int = 2):
|
| 770 |
+
super().__init__()
|
| 771 |
+
self.hidden_size = context_dim * (spatial_merge_size**2)
|
| 772 |
+
self.ln_q = nn.LayerNorm(context_dim, eps=1e-6)
|
| 773 |
+
self.mlp = nn.Sequential(
|
| 774 |
+
nn.Linear(self.hidden_size, self.hidden_size),
|
| 775 |
+
nn.GELU(),
|
| 776 |
+
nn.Linear(self.hidden_size, dim),
|
| 777 |
+
)
|
| 778 |
+
|
| 779 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 780 |
+
return self.mlp(self.ln_q(x).view(-1, self.hidden_size))
|
| 781 |
+
|
| 782 |
+
|
| 783 |
+
class MiMoVisionTransformer(nn.Module):
|
| 784 |
+
def __init__(self, config):
|
| 785 |
+
super().__init__()
|
| 786 |
+
self.config = config
|
| 787 |
+
hidden_size = config.hidden_size
|
| 788 |
+
depth = config.depth
|
| 789 |
+
num_heads = config.num_heads
|
| 790 |
+
num_kv_heads = getattr(config, "num_key_value_heads", num_heads)
|
| 791 |
+
head_dim = getattr(config, "qk_channels", 64)
|
| 792 |
+
spatial_merge_size = getattr(config, "spatial_merge_size", 2)
|
| 793 |
+
rms_norm_eps = getattr(config, "rms_norm_eps", 1e-6)
|
| 794 |
+
self.fullatt_block_indexes = getattr(config, "fullatt_block_indexes", [])
|
| 795 |
+
use_sink = getattr(config, "use_sink", False)
|
| 796 |
+
visual_token_window_size = getattr(config, "visual_token_window_size", -1)
|
| 797 |
+
self.vit_window_attn_types = getattr(config, "vit_window_attn_types", None) or [-1] * depth
|
| 798 |
+
|
| 799 |
+
self.spatial_merge_size = spatial_merge_size
|
| 800 |
+
self.spatial_merge_unit = spatial_merge_size * spatial_merge_size
|
| 801 |
+
|
| 802 |
+
self.patch_embed = MiMoVisionPatchEmbed(
|
| 803 |
+
patch_size=config.patch_size,
|
| 804 |
+
temporal_patch_size=config.temporal_patch_size,
|
| 805 |
+
in_channels=getattr(config, "in_channels", None) or getattr(config, "in_chans", 3),
|
| 806 |
+
embed_dim=hidden_size,
|
| 807 |
+
)
|
| 808 |
+
|
| 809 |
+
self.rotary_pos_emb = MiMoVisionRotaryEmbedding(head_dim // 2)
|
| 810 |
+
|
| 811 |
+
self.blocks = nn.ModuleList(
|
| 812 |
+
[
|
| 813 |
+
MiMoVisionBlock(
|
| 814 |
+
dim=hidden_size,
|
| 815 |
+
intermediate_dim=config.intermediate_size,
|
| 816 |
+
num_heads=num_heads,
|
| 817 |
+
num_kv_heads=num_kv_heads,
|
| 818 |
+
head_dim=head_dim,
|
| 819 |
+
hidden_act=config.hidden_act,
|
| 820 |
+
rms_norm_eps=rms_norm_eps,
|
| 821 |
+
use_sinks=use_sink and (i not in self.fullatt_block_indexes),
|
| 822 |
+
window_size=visual_token_window_size,
|
| 823 |
+
)
|
| 824 |
+
for i in range(depth)
|
| 825 |
+
]
|
| 826 |
+
)
|
| 827 |
+
|
| 828 |
+
self.merger = MiMoVisionPatchMerger(
|
| 829 |
+
dim=config.out_hidden_size,
|
| 830 |
+
context_dim=hidden_size,
|
| 831 |
+
spatial_merge_size=spatial_merge_size,
|
| 832 |
+
)
|
| 833 |
+
|
| 834 |
+
@property
|
| 835 |
+
def dtype(self) -> torch.dtype:
|
| 836 |
+
return self.patch_embed.proj.weight.dtype
|
| 837 |
+
|
| 838 |
+
def apply_index(self, tensor: torch.Tensor, index: torch.Tensor) -> torch.Tensor:
|
| 839 |
+
tensor = tensor.unflatten(0, (-1, self.spatial_merge_unit))
|
| 840 |
+
tensor = tensor[index]
|
| 841 |
+
return tensor.flatten(0, 1)
|
| 842 |
+
|
| 843 |
+
def get_window_index_1d(self, grid_thw: torch.Tensor, col: bool = True) -> torch.Tensor:
|
| 844 |
+
window_index = []
|
| 845 |
+
window_index_id = 0
|
| 846 |
+
for grid_t, grid_h, grid_w in grid_thw:
|
| 847 |
+
llm_grid_h = grid_h // self.spatial_merge_size
|
| 848 |
+
llm_grid_w = grid_w // self.spatial_merge_size
|
| 849 |
+
index = torch.arange(grid_t * llm_grid_h * llm_grid_w).reshape(grid_t, llm_grid_h, llm_grid_w)
|
| 850 |
+
index_new = index.transpose(1, 2).reshape(-1) if col else index.reshape(-1)
|
| 851 |
+
window_index.append(index_new + window_index_id)
|
| 852 |
+
window_index_id += (grid_t * llm_grid_h * llm_grid_w).item()
|
| 853 |
+
return torch.cat(window_index, dim=0)
|
| 854 |
+
|
| 855 |
+
def rot_pos_emb(self, grid_thw: torch.Tensor) -> torch.Tensor:
|
| 856 |
+
pos_ids = []
|
| 857 |
+
for t, h, w in grid_thw:
|
| 858 |
+
hpos_ids = torch.arange(h).unsqueeze(1).expand(-1, w)
|
| 859 |
+
hpos_ids = hpos_ids.reshape(
|
| 860 |
+
h // self.spatial_merge_size, self.spatial_merge_size,
|
| 861 |
+
w // self.spatial_merge_size, self.spatial_merge_size,
|
| 862 |
+
)
|
| 863 |
+
hpos_ids = hpos_ids.permute(0, 2, 1, 3).flatten()
|
| 864 |
+
|
| 865 |
+
wpos_ids = torch.arange(w).unsqueeze(0).expand(h, -1)
|
| 866 |
+
wpos_ids = wpos_ids.reshape(
|
| 867 |
+
h // self.spatial_merge_size, self.spatial_merge_size,
|
| 868 |
+
w // self.spatial_merge_size, self.spatial_merge_size,
|
| 869 |
+
)
|
| 870 |
+
wpos_ids = wpos_ids.permute(0, 2, 1, 3).flatten()
|
| 871 |
+
|
| 872 |
+
pos_ids.append(torch.stack([hpos_ids, wpos_ids], dim=-1).repeat(t, 1))
|
| 873 |
+
pos_ids = torch.cat(pos_ids, dim=0)
|
| 874 |
+
max_grid_size = grid_thw[:, 1:].max()
|
| 875 |
+
rotary_pos_emb_full = self.rotary_pos_emb(max_grid_size)
|
| 876 |
+
return rotary_pos_emb_full[pos_ids].flatten(1)
|
| 877 |
+
|
| 878 |
+
def forward(self, pixel_values: torch.Tensor, grid_thw: torch.Tensor) -> torch.Tensor:
|
| 879 |
+
x = pixel_values.to(device=self.patch_embed.proj.weight.device, dtype=self.dtype)
|
| 880 |
+
x = self.patch_embed(x)
|
| 881 |
+
|
| 882 |
+
rotary_emb = self.rot_pos_emb(grid_thw)
|
| 883 |
+
rotary_emb = rotary_emb.to(device=x.device)
|
| 884 |
+
emb = torch.cat((rotary_emb, rotary_emb), dim=-1)
|
| 885 |
+
|
| 886 |
+
window_index_1d_col = self.get_window_index_1d(grid_thw, col=True).to(device=x.device)
|
| 887 |
+
reverse_window_index_1d_col = torch.argsort(window_index_1d_col).to(device=x.device)
|
| 888 |
+
|
| 889 |
+
row_based_embeddings = (emb.cos(), emb.sin())
|
| 890 |
+
col_emb = self.apply_index(emb, window_index_1d_col)
|
| 891 |
+
col_based_embeddings = (col_emb.cos(), col_emb.sin())
|
| 892 |
+
|
| 893 |
+
cu_seqlens = torch.repeat_interleave(grid_thw[:, 1] * grid_thw[:, 2], grid_thw[:, 0]).cumsum(
|
| 894 |
+
dim=0, dtype=torch.int32
|
| 895 |
+
)
|
| 896 |
+
cu_seqlens = F.pad(cu_seqlens, (1, 0), value=0).to(device=x.device)
|
| 897 |
+
|
| 898 |
+
for i, blk in enumerate(self.blocks):
|
| 899 |
+
window_attn_type = self.vit_window_attn_types[i]
|
| 900 |
+
|
| 901 |
+
if window_attn_type == 1 and (i == 0 or self.vit_window_attn_types[i - 1] != 1):
|
| 902 |
+
x = self.apply_index(x, window_index_1d_col)
|
| 903 |
+
|
| 904 |
+
if i > 0 and window_attn_type != 1 and self.vit_window_attn_types[i - 1] == 1:
|
| 905 |
+
x = self.apply_index(x, reverse_window_index_1d_col)
|
| 906 |
+
|
| 907 |
+
position_embeddings = col_based_embeddings if window_attn_type == 1 else row_based_embeddings
|
| 908 |
+
full_attn = i in self.fullatt_block_indexes
|
| 909 |
+
x = blk(x, cu_seqlens=cu_seqlens, position_embeddings=position_embeddings, full_attn=full_attn)
|
| 910 |
+
|
| 911 |
+
return self.merger(x)
|
| 912 |
+
|
| 913 |
+
|
| 914 |
+
# ---------------------------------------------------------------------------
|
| 915 |
+
# Audio encoder
|
| 916 |
+
# ---------------------------------------------------------------------------
|
| 917 |
+
|
| 918 |
+
|
| 919 |
+
class AudioProjection(nn.Module):
|
| 920 |
+
def __init__(self, input_size: int, hidden_size: int, output_size: int):
|
| 921 |
+
super().__init__()
|
| 922 |
+
self.mlp = nn.Sequential(
|
| 923 |
+
nn.Linear(input_size, hidden_size, bias=False),
|
| 924 |
+
nn.GELU(),
|
| 925 |
+
nn.Linear(hidden_size, output_size, bias=False),
|
| 926 |
+
)
|
| 927 |
+
|
| 928 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 929 |
+
return self.mlp(x)
|
| 930 |
+
|
| 931 |
+
|
| 932 |
+
class MiMoAudioEncoder(nn.Module):
|
| 933 |
+
def __init__(self, config):
|
| 934 |
+
super().__init__()
|
| 935 |
+
self.config = config
|
| 936 |
+
|
| 937 |
+
self.audio_channels = getattr(config, "audio_channels")
|
| 938 |
+
self.group_size = getattr(config, "group_size")
|
| 939 |
+
self.input_local_dim = getattr(config, "input_local_dim")
|
| 940 |
+
self.out_hidden_size = getattr(config, "out_hidden_size")
|
| 941 |
+
self.input_full_attention = getattr(config, "input_full_attention", True)
|
| 942 |
+
self.audio_segment_size = getattr(config, "audio_segment_size", 6000)
|
| 943 |
+
|
| 944 |
+
input_local_config = Qwen2Config(
|
| 945 |
+
hidden_size=getattr(config, "input_local_dim"),
|
| 946 |
+
num_hidden_layers=getattr(config, "input_local_layers"),
|
| 947 |
+
num_attention_heads=getattr(config, "input_local_attn_heads"),
|
| 948 |
+
num_key_value_heads=getattr(config, "input_local_attn_heads"),
|
| 949 |
+
intermediate_size=getattr(config, "input_local_intermediate_size"),
|
| 950 |
+
attention_dropout=getattr(config, "input_local_hidden_dropout", 0.0),
|
| 951 |
+
rope_theta=getattr(config, "rope_theta", 640000.0),
|
| 952 |
+
partial_rotary_factor=getattr(config, "partial_rotary_factor", 1.0),
|
| 953 |
+
)
|
| 954 |
+
self.input_local_transformer = Qwen2Model(input_local_config)
|
| 955 |
+
|
| 956 |
+
if not getattr(config, "add_post_norm", True):
|
| 957 |
+
self.input_local_transformer.norm = nn.Identity()
|
| 958 |
+
|
| 959 |
+
proj_in = self.input_local_dim * self.group_size
|
| 960 |
+
projection_layers = getattr(config, "projection_layers", 2)
|
| 961 |
+
if projection_layers == 1:
|
| 962 |
+
self.projection = nn.Linear(proj_in, self.out_hidden_size, bias=False)
|
| 963 |
+
elif projection_layers == 2:
|
| 964 |
+
self.projection = AudioProjection(proj_in, proj_in * 4, self.out_hidden_size)
|
| 965 |
+
else:
|
| 966 |
+
raise ValueError(f"Unsupported projection_layers={projection_layers}, expected 1 or 2.")
|
| 967 |
+
|
| 968 |
+
def _apply_speech_embeddings(self, audio_codes: torch.Tensor, speech_embeddings: nn.ModuleList) -> torch.Tensor:
|
| 969 |
+
num_segments = audio_codes.shape[0]
|
| 970 |
+
out = torch.zeros(
|
| 971 |
+
(num_segments, self.group_size, self.input_local_dim),
|
| 972 |
+
dtype=speech_embeddings[0].weight.dtype,
|
| 973 |
+
device=audio_codes.device,
|
| 974 |
+
)
|
| 975 |
+
for i in range(self.audio_channels):
|
| 976 |
+
out.add_(speech_embeddings[i](audio_codes[:, :, i].long()))
|
| 977 |
+
return out
|
| 978 |
+
|
| 979 |
+
def _apply_input_local_transformer(self, speech_embeddings: torch.Tensor) -> torch.Tensor:
|
| 980 |
+
output = self.input_local_transformer(
|
| 981 |
+
inputs_embeds=speech_embeddings, return_dict=True, use_cache=False,
|
| 982 |
+
is_causal=not self.input_full_attention,
|
| 983 |
+
)
|
| 984 |
+
return output.last_hidden_state
|
| 985 |
+
|
| 986 |
+
def _process_audio_codes(self, audio_codes: torch.Tensor, speech_embeddings: nn.ModuleList) -> torch.Tensor:
|
| 987 |
+
audio_codes = _pad_and_group_audio_codes(audio_codes, self.audio_channels, self.group_size)
|
| 988 |
+
audio_embs = self._apply_speech_embeddings(audio_codes, speech_embeddings)
|
| 989 |
+
audio_hidden = self._apply_input_local_transformer(audio_embs)
|
| 990 |
+
return self.projection(audio_hidden.reshape(audio_hidden.shape[0], -1))
|
| 991 |
+
|
| 992 |
+
def get_audio_feature(
|
| 993 |
+
self,
|
| 994 |
+
mels: list[torch.Tensor],
|
| 995 |
+
speech_embeddings: nn.ModuleList,
|
| 996 |
+
audio_tokenizer_encoder,
|
| 997 |
+
) -> torch.Tensor:
|
| 998 |
+
"""Full pipeline: mel spectrograms → tokenize → codes → embed → project."""
|
| 999 |
+
if not mels:
|
| 1000 |
+
device = next(self.projection.parameters()).device
|
| 1001 |
+
dtype = next(self.projection.parameters()).dtype
|
| 1002 |
+
return torch.empty(0, self.out_hidden_size, device=device, dtype=dtype)
|
| 1003 |
+
|
| 1004 |
+
device = next(audio_tokenizer_encoder.parameters()).device
|
| 1005 |
+
code_list = tokenize_audio_batch(
|
| 1006 |
+
mels, audio_tokenizer_encoder, segment_size=self.audio_segment_size, device=device,
|
| 1007 |
+
)
|
| 1008 |
+
|
| 1009 |
+
codecs_to_concat = []
|
| 1010 |
+
for codecs in code_list:
|
| 1011 |
+
codecs_to_concat.append(_pad_and_group_audio_codes(codecs, self.audio_channels, self.group_size))
|
| 1012 |
+
audio_codes = torch.cat(codecs_to_concat, dim=0)
|
| 1013 |
+
|
| 1014 |
+
audio_embs = self._apply_speech_embeddings(audio_codes, speech_embeddings)
|
| 1015 |
+
audio_hidden = self._apply_input_local_transformer(audio_embs)
|
| 1016 |
+
return self.projection(audio_hidden.reshape(audio_hidden.shape[0], -1))
|
| 1017 |
+
|
| 1018 |
+
def forward(
|
| 1019 |
+
self,
|
| 1020 |
+
speech_embeddings: nn.ModuleList,
|
| 1021 |
+
audio_codes: torch.Tensor | None = None,
|
| 1022 |
+
audio_embeds: torch.Tensor | None = None,
|
| 1023 |
+
) -> torch.Tensor:
|
| 1024 |
+
if audio_embeds is not None:
|
| 1025 |
+
if audio_embeds.dim() != 2:
|
| 1026 |
+
raise ValueError(f"`audio_embeds` must be 2D [N, H], got shape={tuple(audio_embeds.shape)}")
|
| 1027 |
+
if audio_embeds.shape[-1] != self.out_hidden_size:
|
| 1028 |
+
raise ValueError(
|
| 1029 |
+
f"Unexpected audio_embeds hidden size {audio_embeds.shape[-1]}, expected {self.out_hidden_size}"
|
| 1030 |
+
)
|
| 1031 |
+
return audio_embeds
|
| 1032 |
+
|
| 1033 |
+
if audio_codes is None:
|
| 1034 |
+
raise ValueError("Either `audio_codes` or `audio_embeds` must be provided.")
|
| 1035 |
+
|
| 1036 |
+
return self._process_audio_codes(audio_codes, speech_embeddings)
|
| 1037 |
+
|
| 1038 |
+
|
| 1039 |
+
# ---------------------------------------------------------------------------
|
| 1040 |
+
# Audio tokenizer (codec: mel → encoder → VQ → codes)
|
| 1041 |
+
# Adapted from https://github.com/XiaomiMiMo/MiMo-Audio-Tokenizer.git
|
| 1042 |
+
# ---------------------------------------------------------------------------
|
| 1043 |
+
|
| 1044 |
+
|
| 1045 |
+
class MiMoAudioTokenizerConfig(PretrainedConfig):
|
| 1046 |
+
model_type = "mimo_audio_tokenizer"
|
| 1047 |
+
|
| 1048 |
+
def __init__(
|
| 1049 |
+
self,
|
| 1050 |
+
max_audio_seconds: int = 1800,
|
| 1051 |
+
stride_size: int = 2,
|
| 1052 |
+
avg_pooler: int = 1,
|
| 1053 |
+
d_model: int = 768,
|
| 1054 |
+
scale_embedding: bool = True,
|
| 1055 |
+
kernel_size: int = 3,
|
| 1056 |
+
activation_function: str = "gelu",
|
| 1057 |
+
encoder_layers: int = 8,
|
| 1058 |
+
encoder_skip_layer_id: int = None,
|
| 1059 |
+
encoder_attention_heads: int = 12,
|
| 1060 |
+
encoder_ffn_dim: int = 3072,
|
| 1061 |
+
encoder_causal: bool = False,
|
| 1062 |
+
encoder_attn_window_size: list = None,
|
| 1063 |
+
decoder_layers: int = 8,
|
| 1064 |
+
decoder_attention_heads: int = 12,
|
| 1065 |
+
decoder_ffn_dim: int = 3072,
|
| 1066 |
+
decoder_kernel_size: int = 3,
|
| 1067 |
+
decoder_stride_size: int = 2,
|
| 1068 |
+
decoder_causal: bool = True,
|
| 1069 |
+
decoder_attn_window_size: list = None,
|
| 1070 |
+
nfft: int = 1024,
|
| 1071 |
+
vocoder_dim: int = 512,
|
| 1072 |
+
vocoder_intermediate_dim: int = 4096,
|
| 1073 |
+
vocoder_num_layers: int = 30,
|
| 1074 |
+
n_mels: int = 80,
|
| 1075 |
+
sampling_rate: int = 24000,
|
| 1076 |
+
hop_length: int = 240,
|
| 1077 |
+
window_size: int = 1024,
|
| 1078 |
+
vocoder_padding: str = "same",
|
| 1079 |
+
fmin: int = 0,
|
| 1080 |
+
fmax: int = None,
|
| 1081 |
+
num_quantizers: int = 12,
|
| 1082 |
+
codebook_size: list = None,
|
| 1083 |
+
threshold_ema_dead_code: int = 10,
|
| 1084 |
+
position_embedding_type: str = "rope",
|
| 1085 |
+
rope_theta: int = 10000,
|
| 1086 |
+
rope_type: str = "default",
|
| 1087 |
+
ln_type: str = "LayerNorm",
|
| 1088 |
+
vocoder_attention_heads: int = 4,
|
| 1089 |
+
vocoder_attn_window_size: list = None,
|
| 1090 |
+
use_istft_only: bool = False,
|
| 1091 |
+
hybrid_attention: bool = False,
|
| 1092 |
+
hybrid_block_size: int = 8,
|
| 1093 |
+
swa_per_block: int = 2,
|
| 1094 |
+
**kwargs,
|
| 1095 |
+
):
|
| 1096 |
+
super().__init__(**kwargs)
|
| 1097 |
+
self.max_audio_seconds = max_audio_seconds
|
| 1098 |
+
self.stride_size = stride_size
|
| 1099 |
+
self.avg_pooler = avg_pooler
|
| 1100 |
+
self.d_model = d_model
|
| 1101 |
+
self.scale_embedding = scale_embedding
|
| 1102 |
+
self.kernel_size = kernel_size
|
| 1103 |
+
self.activation_function = activation_function
|
| 1104 |
+
self.encoder_layers = encoder_layers
|
| 1105 |
+
self.encoder_skip_layer_id = encoder_skip_layer_id
|
| 1106 |
+
self.encoder_attention_heads = encoder_attention_heads
|
| 1107 |
+
self.encoder_ffn_dim = encoder_ffn_dim
|
| 1108 |
+
self.encoder_causal = encoder_causal
|
| 1109 |
+
self.encoder_attn_window_size = encoder_attn_window_size if encoder_attn_window_size is not None else [-1, -1]
|
| 1110 |
+
self.decoder_layers = decoder_layers
|
| 1111 |
+
self.decoder_attention_heads = decoder_attention_heads
|
| 1112 |
+
self.decoder_ffn_dim = decoder_ffn_dim
|
| 1113 |
+
self.decoder_kernel_size = decoder_kernel_size
|
| 1114 |
+
self.decoder_stride_size = decoder_stride_size
|
| 1115 |
+
self.decoder_causal = decoder_causal
|
| 1116 |
+
self.decoder_attn_window_size = decoder_attn_window_size if decoder_attn_window_size is not None else [-1, -1]
|
| 1117 |
+
self.nfft = nfft
|
| 1118 |
+
self.vocoder_dim = vocoder_dim
|
| 1119 |
+
self.vocoder_intermediate_dim = vocoder_intermediate_dim
|
| 1120 |
+
self.vocoder_num_layers = vocoder_num_layers
|
| 1121 |
+
self.n_mels = n_mels
|
| 1122 |
+
self.sampling_rate = sampling_rate
|
| 1123 |
+
self.hop_length = hop_length
|
| 1124 |
+
self.window_size = window_size
|
| 1125 |
+
self.vocoder_padding = vocoder_padding
|
| 1126 |
+
self.fmin = fmin
|
| 1127 |
+
self.fmax = fmax
|
| 1128 |
+
self.num_quantizers = num_quantizers
|
| 1129 |
+
self.codebook_size = codebook_size if codebook_size is not None else [1024]
|
| 1130 |
+
self.threshold_ema_dead_code = threshold_ema_dead_code
|
| 1131 |
+
self.position_embedding_type = position_embedding_type
|
| 1132 |
+
self.rope_theta = rope_theta
|
| 1133 |
+
self.rope_type = rope_type
|
| 1134 |
+
self.ln_type = ln_type
|
| 1135 |
+
self.vocoder_attention_heads = vocoder_attention_heads
|
| 1136 |
+
self.vocoder_attn_window_size = vocoder_attn_window_size if vocoder_attn_window_size is not None else [40, 10]
|
| 1137 |
+
self.use_istft_only = use_istft_only
|
| 1138 |
+
self.hybrid_attention = hybrid_attention
|
| 1139 |
+
self.hybrid_block_size = hybrid_block_size
|
| 1140 |
+
self.swa_per_block = swa_per_block
|
| 1141 |
+
|
| 1142 |
+
|
| 1143 |
+
class EuclideanCodebook(nn.Module):
|
| 1144 |
+
def __init__(self, dim: int, codebook_size: int, kmeans_init: bool = False, **kwargs):
|
| 1145 |
+
super().__init__()
|
| 1146 |
+
init_fn = torch.zeros if kmeans_init else self._uniform_init
|
| 1147 |
+
embed = init_fn(codebook_size, dim)
|
| 1148 |
+
self.codebook_size = codebook_size
|
| 1149 |
+
self.register_buffer("inited", torch.Tensor([not kmeans_init]))
|
| 1150 |
+
self.register_buffer("cluster_size", torch.zeros(codebook_size))
|
| 1151 |
+
self.register_buffer("embed", embed)
|
| 1152 |
+
self.register_buffer("embed_avg", embed.clone())
|
| 1153 |
+
|
| 1154 |
+
def quantize(self, x):
|
| 1155 |
+
embed = self.embed.t()
|
| 1156 |
+
dist = -(x.pow(2).sum(1, keepdim=True) - 2 * x @ embed + embed.pow(2).sum(0, keepdim=True))
|
| 1157 |
+
return dist.max(dim=-1).indices
|
| 1158 |
+
|
| 1159 |
+
def encode(self, x):
|
| 1160 |
+
shape = x.shape
|
| 1161 |
+
x = x.reshape(-1, x.shape[-1])
|
| 1162 |
+
embed_ind = self.quantize(x)
|
| 1163 |
+
return embed_ind.view(*shape[:-1])
|
| 1164 |
+
|
| 1165 |
+
def decode(self, embed_ind):
|
| 1166 |
+
return F.embedding(embed_ind, self.embed)
|
| 1167 |
+
|
| 1168 |
+
@staticmethod
|
| 1169 |
+
def _uniform_init(*shape: int):
|
| 1170 |
+
t = torch.empty(shape)
|
| 1171 |
+
nn.init.kaiming_uniform_(t)
|
| 1172 |
+
return t
|
| 1173 |
+
|
| 1174 |
+
|
| 1175 |
+
class VectorQuantization(nn.Module):
|
| 1176 |
+
def __init__(self, dim: int, codebook_size: int, codebook_dim: Optional[int] = None, kmeans_init: bool = True, **kwargs):
|
| 1177 |
+
super().__init__()
|
| 1178 |
+
_codebook_dim = codebook_dim if codebook_dim is not None else dim
|
| 1179 |
+
requires_projection = _codebook_dim != dim
|
| 1180 |
+
self.project_in = nn.Linear(dim, _codebook_dim) if requires_projection else nn.Identity()
|
| 1181 |
+
self.project_out = nn.Linear(_codebook_dim, dim) if requires_projection else nn.Identity()
|
| 1182 |
+
self._codebook = EuclideanCodebook(dim=_codebook_dim, codebook_size=codebook_size, kmeans_init=kmeans_init)
|
| 1183 |
+
self.codebook_size = codebook_size
|
| 1184 |
+
|
| 1185 |
+
def encode(self, x):
|
| 1186 |
+
return self._codebook.encode(self.project_in(x))
|
| 1187 |
+
|
| 1188 |
+
def decode(self, embed_ind):
|
| 1189 |
+
return self.project_out(self._codebook.decode(embed_ind))
|
| 1190 |
+
|
| 1191 |
+
|
| 1192 |
+
class ResidualVectorQuantization(nn.Module):
|
| 1193 |
+
def __init__(self, *, num_quantizers, codebook_size, **kwargs):
|
| 1194 |
+
super().__init__()
|
| 1195 |
+
if isinstance(codebook_size, int):
|
| 1196 |
+
codebook_size = [codebook_size] * num_quantizers
|
| 1197 |
+
elif len(codebook_size) < num_quantizers:
|
| 1198 |
+
codebook_size += [codebook_size[-1]] * (num_quantizers - len(codebook_size))
|
| 1199 |
+
self.layers = nn.ModuleList(
|
| 1200 |
+
[VectorQuantization(codebook_size=codebook_size[i], **kwargs) for i in range(num_quantizers)]
|
| 1201 |
+
)
|
| 1202 |
+
|
| 1203 |
+
def encode(self, x: torch.Tensor, n_q: Optional[int] = None, st: Optional[int] = None) -> torch.Tensor:
|
| 1204 |
+
residual = x
|
| 1205 |
+
all_indices = []
|
| 1206 |
+
n_q = len(self.layers) if n_q is None else n_q
|
| 1207 |
+
st = 0 if st is None else st
|
| 1208 |
+
for layer in self.layers[st:n_q]:
|
| 1209 |
+
indices = layer.encode(residual)
|
| 1210 |
+
quantized = layer.decode(indices)
|
| 1211 |
+
residual = residual - quantized
|
| 1212 |
+
all_indices.append(indices)
|
| 1213 |
+
return torch.stack(all_indices)
|
| 1214 |
+
|
| 1215 |
+
def decode(self, q_indices: torch.Tensor, st: int = 0) -> torch.Tensor:
|
| 1216 |
+
quantized_out = self.layers[st].decode(q_indices[0])
|
| 1217 |
+
for i in range(1, len(q_indices)):
|
| 1218 |
+
quantized_out = quantized_out + self.layers[st + i].decode(q_indices[i])
|
| 1219 |
+
return quantized_out
|
| 1220 |
+
|
| 1221 |
+
|
| 1222 |
+
class ResidualVectorQuantizer(nn.Module):
|
| 1223 |
+
def __init__(self, dimension: int = 256, n_q: int = 8, bins: int | list = 1024, kmeans_init: bool = True, **kwargs):
|
| 1224 |
+
super().__init__()
|
| 1225 |
+
self.n_q = n_q
|
| 1226 |
+
self.vq = ResidualVectorQuantization(dim=dimension, codebook_size=bins, num_quantizers=n_q, kmeans_init=kmeans_init)
|
| 1227 |
+
|
| 1228 |
+
def encode(self, x: torch.Tensor, n_q: Optional[int] = None, st: Optional[int] = None) -> torch.Tensor:
|
| 1229 |
+
return self.vq.encode(x, n_q=n_q or self.n_q, st=st or 0)
|
| 1230 |
+
|
| 1231 |
+
def decode(self, codes: torch.Tensor, st: int = 0) -> torch.Tensor:
|
| 1232 |
+
return self.vq.decode(codes, st=st)
|
| 1233 |
+
|
| 1234 |
+
|
| 1235 |
+
class AudioTokenizerRotaryEmbedding(nn.Module):
|
| 1236 |
+
def __init__(self, base, dim, max_seq_len, rope_type="default", device=None):
|
| 1237 |
+
super().__init__()
|
| 1238 |
+
self.attention_scaling = 1.0
|
| 1239 |
+
inv_freq = 1.0 / (base ** (torch.arange(0, dim, 2, dtype=torch.float, device=device) / dim))
|
| 1240 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
| 1241 |
+
|
| 1242 |
+
@torch.no_grad()
|
| 1243 |
+
def forward(self, x, position_ids):
|
| 1244 |
+
inv_freq_expanded = self.inv_freq[:, None].float().expand(-1, 1).to(x.device)
|
| 1245 |
+
position_ids_expanded = position_ids[None, :].float()
|
| 1246 |
+
with torch.autocast(device_type="cpu", enabled=False):
|
| 1247 |
+
freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(0, 1)
|
| 1248 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
| 1249 |
+
cos = emb.cos() * self.attention_scaling
|
| 1250 |
+
sin = emb.sin() * self.attention_scaling
|
| 1251 |
+
return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
|
| 1252 |
+
|
| 1253 |
+
|
| 1254 |
+
def _at_get_position_ids(lengths):
|
| 1255 |
+
total_len = lengths.sum()
|
| 1256 |
+
offset = torch.cat([torch.zeros(1, device=lengths.device, dtype=lengths.dtype), lengths[:-1].cumsum(dim=0)])
|
| 1257 |
+
offset = torch.repeat_interleave(offset, lengths)
|
| 1258 |
+
return torch.arange(0, total_len, device=lengths.device) - offset
|
| 1259 |
+
|
| 1260 |
+
|
| 1261 |
+
def _at_get_sequence_mask(inputs, inputs_length):
|
| 1262 |
+
if inputs.dim() == 3:
|
| 1263 |
+
bsz, tgt_len, _ = inputs.size()
|
| 1264 |
+
else:
|
| 1265 |
+
bsz, tgt_len = inputs_length.shape[0], torch.max(inputs_length)
|
| 1266 |
+
sequence_mask = torch.arange(0, tgt_len, device=inputs.device)
|
| 1267 |
+
sequence_mask = torch.lt(sequence_mask, inputs_length.reshape(bsz, 1)).view(bsz, tgt_len, 1)
|
| 1268 |
+
unpacking_index = torch.cumsum(sequence_mask.to(torch.int64).view(-1), dim=0) - 1
|
| 1269 |
+
return sequence_mask, unpacking_index
|
| 1270 |
+
|
| 1271 |
+
|
| 1272 |
+
def _at_unpack_hidden_states(hidden_states, lengths, sequence_mask=None, unpacking_index=None):
|
| 1273 |
+
bsz = lengths.shape[0]
|
| 1274 |
+
if sequence_mask is None or unpacking_index is None:
|
| 1275 |
+
sequence_mask, unpacking_index = _at_get_sequence_mask(hidden_states, lengths)
|
| 1276 |
+
hidden_states = torch.index_select(hidden_states, 0, unpacking_index).view(
|
| 1277 |
+
bsz, torch.max(lengths), hidden_states.shape[-1]
|
| 1278 |
+
)
|
| 1279 |
+
return torch.where(sequence_mask, hidden_states, 0)
|
| 1280 |
+
|
| 1281 |
+
|
| 1282 |
+
def _at_rotate_half(x):
|
| 1283 |
+
x1 = x[..., : x.shape[-1] // 2]
|
| 1284 |
+
x2 = x[..., x.shape[-1] // 2 :]
|
| 1285 |
+
return torch.cat((-x2, x1), dim=-1)
|
| 1286 |
+
|
| 1287 |
+
|
| 1288 |
+
def _at_apply_rotary_pos_emb(q, k, cos, sin, unsqueeze_dim=1):
|
| 1289 |
+
cos = cos.unsqueeze(unsqueeze_dim)
|
| 1290 |
+
sin = sin.unsqueeze(unsqueeze_dim)
|
| 1291 |
+
return (q * cos) + (_at_rotate_half(q) * sin), (k * cos) + (_at_rotate_half(k) * sin)
|
| 1292 |
+
|
| 1293 |
+
|
| 1294 |
+
_AT_LAYER_NORM = {"LayerNorm": nn.LayerNorm}
|
| 1295 |
+
|
| 1296 |
+
|
| 1297 |
+
class AudioTokenizerAttention(nn.Module):
|
| 1298 |
+
def __init__(self, embed_dim: int, num_heads: int, window_size: tuple[int, int] = (-1, -1), causal: bool = False):
|
| 1299 |
+
super().__init__()
|
| 1300 |
+
self.embed_dim = embed_dim
|
| 1301 |
+
self.num_heads = num_heads
|
| 1302 |
+
self.head_dim = embed_dim // num_heads
|
| 1303 |
+
self.window_size = window_size
|
| 1304 |
+
self.causal = causal
|
| 1305 |
+
self.scaling = self.head_dim**-0.5
|
| 1306 |
+
|
| 1307 |
+
self.k_proj = nn.Linear(embed_dim, embed_dim, bias=False)
|
| 1308 |
+
self.v_proj = nn.Linear(embed_dim, embed_dim, bias=True)
|
| 1309 |
+
self.q_proj = nn.Linear(embed_dim, embed_dim, bias=True)
|
| 1310 |
+
self.out_proj = nn.Linear(embed_dim, embed_dim, bias=True)
|
| 1311 |
+
|
| 1312 |
+
def _build_attn_mask(self, seq_len: int, device: torch.device, dtype: torch.dtype) -> torch.Tensor | None:
|
| 1313 |
+
has_window = self.window_size[0] > 0
|
| 1314 |
+
if not self.causal and not has_window:
|
| 1315 |
+
return None
|
| 1316 |
+
mask = torch.zeros(seq_len, seq_len, device=device, dtype=dtype)
|
| 1317 |
+
if self.causal:
|
| 1318 |
+
mask = mask + torch.triu(torch.full((seq_len, seq_len), float("-inf"), device=device, dtype=dtype), diagonal=1)
|
| 1319 |
+
if has_window:
|
| 1320 |
+
row_idx = torch.arange(seq_len, device=device).unsqueeze(1)
|
| 1321 |
+
col_idx = torch.arange(seq_len, device=device).unsqueeze(0)
|
| 1322 |
+
mask = mask.masked_fill((row_idx - col_idx).abs() > self.window_size[0], float("-inf"))
|
| 1323 |
+
return mask
|
| 1324 |
+
|
| 1325 |
+
def forward(self, hidden_states, cu_seqlens, max_seqlen, rope_position_embeddings=None):
|
| 1326 |
+
total_len = hidden_states.shape[0]
|
| 1327 |
+
q = self.q_proj(hidden_states).view(total_len, self.num_heads, self.head_dim)
|
| 1328 |
+
k = self.k_proj(hidden_states).view(total_len, self.num_heads, self.head_dim)
|
| 1329 |
+
v = self.v_proj(hidden_states).view(total_len, self.num_heads, self.head_dim)
|
| 1330 |
+
if rope_position_embeddings is not None:
|
| 1331 |
+
cos, sin = rope_position_embeddings
|
| 1332 |
+
q, k = _at_apply_rotary_pos_emb(q, k, cos, sin)
|
| 1333 |
+
num_seqs = cu_seqlens.shape[0] - 1
|
| 1334 |
+
outputs = []
|
| 1335 |
+
for i in range(num_seqs):
|
| 1336 |
+
start, end = cu_seqlens[i].item(), cu_seqlens[i + 1].item()
|
| 1337 |
+
seq_len = end - start
|
| 1338 |
+
q_seq = q[start:end].transpose(0, 1).unsqueeze(0)
|
| 1339 |
+
k_seq = k[start:end].transpose(0, 1).unsqueeze(0)
|
| 1340 |
+
v_seq = v[start:end].transpose(0, 1).unsqueeze(0)
|
| 1341 |
+
attn_mask = self._build_attn_mask(seq_len, q_seq.device, q_seq.dtype)
|
| 1342 |
+
out = F.scaled_dot_product_attention(q_seq, k_seq, v_seq, attn_mask=attn_mask, scale=self.scaling)
|
| 1343 |
+
outputs.append(out.squeeze(0).transpose(0, 1))
|
| 1344 |
+
return self.out_proj(torch.cat(outputs, dim=0).reshape(total_len, self.embed_dim))
|
| 1345 |
+
|
| 1346 |
+
|
| 1347 |
+
class AudioTokenizerTransformerLayer(nn.Module):
|
| 1348 |
+
def __init__(self, config: MiMoAudioTokenizerConfig, causal: bool, attn_window_size: tuple[int, int] = (-1, -1)):
|
| 1349 |
+
super().__init__()
|
| 1350 |
+
self.embed_dim = config.d_model
|
| 1351 |
+
self.self_attn = AudioTokenizerAttention(
|
| 1352 |
+
embed_dim=self.embed_dim, num_heads=config.encoder_attention_heads,
|
| 1353 |
+
window_size=attn_window_size, causal=causal,
|
| 1354 |
+
)
|
| 1355 |
+
self.self_attn_layer_norm = _AT_LAYER_NORM[config.ln_type](self.embed_dim)
|
| 1356 |
+
self.activation_fn = ACT2FN[config.activation_function]
|
| 1357 |
+
self.fc1 = nn.Linear(self.embed_dim, config.encoder_ffn_dim)
|
| 1358 |
+
self.fc2 = nn.Linear(config.encoder_ffn_dim, self.embed_dim)
|
| 1359 |
+
self.final_layer_norm = _AT_LAYER_NORM[config.ln_type](self.embed_dim)
|
| 1360 |
+
|
| 1361 |
+
def forward(self, hidden_states, cu_seqlens, max_seqlen, rope_position_embeddings):
|
| 1362 |
+
residual = hidden_states
|
| 1363 |
+
hidden_states = self.self_attn_layer_norm(hidden_states)
|
| 1364 |
+
hidden_states = self.self_attn(hidden_states, cu_seqlens, max_seqlen, rope_position_embeddings=rope_position_embeddings)
|
| 1365 |
+
hidden_states = residual + hidden_states
|
| 1366 |
+
residual = hidden_states
|
| 1367 |
+
hidden_states = self.final_layer_norm(hidden_states)
|
| 1368 |
+
hidden_states = self.activation_fn(self.fc1(hidden_states))
|
| 1369 |
+
hidden_states = self.fc2(hidden_states)
|
| 1370 |
+
hidden_states = residual + hidden_states
|
| 1371 |
+
return hidden_states
|
| 1372 |
+
|
| 1373 |
+
|
| 1374 |
+
class AudioTokenizerEncoder(nn.Module):
|
| 1375 |
+
def __init__(self, config: MiMoAudioTokenizerConfig):
|
| 1376 |
+
super().__init__()
|
| 1377 |
+
self.config = config
|
| 1378 |
+
self.max_source_positions = (config.max_audio_seconds * config.sampling_rate // config.hop_length) // config.stride_size
|
| 1379 |
+
self.embed_scale = math.sqrt(config.d_model) if config.scale_embedding else 1.0
|
| 1380 |
+
self.skip_layer_idx = config.encoder_skip_layer_id
|
| 1381 |
+
|
| 1382 |
+
self.conv1 = nn.Conv1d(config.n_mels, config.d_model, kernel_size=config.kernel_size, padding=1)
|
| 1383 |
+
self.conv2 = nn.Conv1d(config.d_model, config.d_model, kernel_size=config.kernel_size, stride=config.stride_size, padding=1)
|
| 1384 |
+
|
| 1385 |
+
self.position_embedding = AudioTokenizerRotaryEmbedding(
|
| 1386 |
+
config.rope_theta, config.d_model // config.encoder_attention_heads,
|
| 1387 |
+
self.max_source_positions, config.rope_type,
|
| 1388 |
+
)
|
| 1389 |
+
|
| 1390 |
+
attn_window_sizes = []
|
| 1391 |
+
if config.hybrid_attention:
|
| 1392 |
+
for i in range(config.encoder_layers):
|
| 1393 |
+
if i % config.swa_per_block < config.swa_per_block - 1:
|
| 1394 |
+
attn_window_sizes.append(tuple(config.encoder_attn_window_size))
|
| 1395 |
+
else:
|
| 1396 |
+
attn_window_sizes.append((-1, -1))
|
| 1397 |
+
else:
|
| 1398 |
+
attn_window_sizes = [tuple(config.encoder_attn_window_size)] * config.encoder_layers
|
| 1399 |
+
|
| 1400 |
+
self.layers = nn.ModuleList([
|
| 1401 |
+
AudioTokenizerTransformerLayer(config=config, causal=config.encoder_causal, attn_window_size=attn_window_sizes[i])
|
| 1402 |
+
for i in range(config.encoder_layers)
|
| 1403 |
+
])
|
| 1404 |
+
|
| 1405 |
+
self.layer_norm = _AT_LAYER_NORM[config.ln_type](config.d_model)
|
| 1406 |
+
|
| 1407 |
+
if config.avg_pooler != 1:
|
| 1408 |
+
self.down_sample_layer = nn.Sequential(
|
| 1409 |
+
nn.Conv1d(config.d_model, config.d_model, config.avg_pooler, config.avg_pooler, bias=False),
|
| 1410 |
+
nn.GELU(),
|
| 1411 |
+
)
|
| 1412 |
+
self.down_sample_norm = _AT_LAYER_NORM[config.ln_type](config.d_model)
|
| 1413 |
+
else:
|
| 1414 |
+
self.down_sample_layer = None
|
| 1415 |
+
|
| 1416 |
+
if config.num_quantizers != 0:
|
| 1417 |
+
self.quantizer = ResidualVectorQuantizer(
|
| 1418 |
+
dimension=config.d_model, n_q=config.num_quantizers,
|
| 1419 |
+
bins=config.codebook_size,
|
| 1420 |
+
threshold_ema_dead_code=config.threshold_ema_dead_code,
|
| 1421 |
+
)
|
| 1422 |
+
else:
|
| 1423 |
+
self.quantizer = None
|
| 1424 |
+
|
| 1425 |
+
def get_output_length(self, mel_len):
|
| 1426 |
+
tgt_len = mel_len + 3 - self.config.kernel_size
|
| 1427 |
+
return (tgt_len + 2 - self.config.kernel_size) // self.config.stride_size + 1
|
| 1428 |
+
|
| 1429 |
+
def get_features(self, input_features, output_length):
|
| 1430 |
+
input_features = input_features.to(self.conv1.weight)
|
| 1431 |
+
inputs_embeds = F.gelu(self.conv1(input_features))
|
| 1432 |
+
inputs_embeds = F.gelu(self.conv2(inputs_embeds))
|
| 1433 |
+
inputs_embeds = inputs_embeds.permute(0, 2, 1)
|
| 1434 |
+
bsz, tgt_len, _ = inputs_embeds.size()
|
| 1435 |
+
|
| 1436 |
+
position_ids = _at_get_position_ids(output_length).long().to(input_features.device)
|
| 1437 |
+
rope_position_embeddings = self.position_embedding(input_features, position_ids)
|
| 1438 |
+
|
| 1439 |
+
attention_mask, unpacking_index = _at_get_sequence_mask(inputs_embeds, output_length)
|
| 1440 |
+
hidden_states = torch.masked_select(inputs_embeds, attention_mask).view(
|
| 1441 |
+
torch.sum(output_length), self.config.d_model
|
| 1442 |
+
)
|
| 1443 |
+
|
| 1444 |
+
cu_seqlens = F.pad(torch.cumsum(output_length, dim=0), (1, 0), "constant", 0).to(
|
| 1445 |
+
device=hidden_states.device, dtype=torch.int32
|
| 1446 |
+
)
|
| 1447 |
+
max_seqlen = torch.max(output_length).to(torch.int32).item()
|
| 1448 |
+
|
| 1449 |
+
skip_connect_hidden_states = 0.0
|
| 1450 |
+
for idx, encoder_layer in enumerate(self.layers):
|
| 1451 |
+
hidden_states = encoder_layer(hidden_states, cu_seqlens, max_seqlen, rope_position_embeddings=rope_position_embeddings)
|
| 1452 |
+
if self.skip_layer_idx is not None and idx == self.skip_layer_idx - 1:
|
| 1453 |
+
skip_connect_hidden_states = hidden_states.clone()
|
| 1454 |
+
|
| 1455 |
+
hidden_states += skip_connect_hidden_states
|
| 1456 |
+
hidden_states = self.layer_norm(hidden_states)
|
| 1457 |
+
|
| 1458 |
+
if self.down_sample_layer is not None:
|
| 1459 |
+
hidden_states = torch.index_select(hidden_states, 0, unpacking_index).view(bsz, tgt_len, self.config.d_model)
|
| 1460 |
+
if hidden_states.size(1) % self.config.avg_pooler:
|
| 1461 |
+
pad_len = self.config.avg_pooler - hidden_states.size(1) % self.config.avg_pooler
|
| 1462 |
+
hidden_states = F.pad(hidden_states, (0, 0, 0, pad_len), mode="constant", value=0.0)
|
| 1463 |
+
tgt_len += pad_len
|
| 1464 |
+
tgt_len = tgt_len // self.config.avg_pooler
|
| 1465 |
+
hidden_states = self.down_sample_layer(hidden_states.transpose(1, 2))
|
| 1466 |
+
output_length = output_length // self.config.avg_pooler + (output_length % self.config.avg_pooler != 0).int()
|
| 1467 |
+
hidden_states = hidden_states.transpose(1, 2)
|
| 1468 |
+
attention_mask, unpacking_index = _at_get_sequence_mask(hidden_states, output_length)
|
| 1469 |
+
hidden_states = torch.masked_select(hidden_states, attention_mask).view(
|
| 1470 |
+
torch.sum(output_length), self.config.d_model
|
| 1471 |
+
)
|
| 1472 |
+
hidden_states = self.down_sample_norm(hidden_states)
|
| 1473 |
+
|
| 1474 |
+
return hidden_states, output_length, attention_mask, unpacking_index, tgt_len, bsz
|
| 1475 |
+
|
| 1476 |
+
@torch.no_grad()
|
| 1477 |
+
def encode(self, input_features, input_lens=None, output_length=None, return_codes_only=False, n_q=None, use_quantizer=True):
|
| 1478 |
+
if output_length is None:
|
| 1479 |
+
output_length = self.get_output_length(input_lens)
|
| 1480 |
+
input_features = _at_unpack_hidden_states(input_features, input_lens)
|
| 1481 |
+
hidden_states, output_length, attention_mask, unpacking_index, tgt_len, bsz = self.get_features(
|
| 1482 |
+
input_features=input_features.transpose(1, 2), output_length=output_length,
|
| 1483 |
+
)
|
| 1484 |
+
dtype = hidden_states.dtype
|
| 1485 |
+
if use_quantizer and self.quantizer is not None:
|
| 1486 |
+
self.quantizer.float()
|
| 1487 |
+
codes = self.quantizer.encode(hidden_states.float(), n_q=n_q)
|
| 1488 |
+
if return_codes_only:
|
| 1489 |
+
return codes, output_length
|
| 1490 |
+
hidden_states = self.quantizer.decode(codes)
|
| 1491 |
+
hidden_states = hidden_states.to(dtype)
|
| 1492 |
+
else:
|
| 1493 |
+
codes = None
|
| 1494 |
+
hidden_states_packed = hidden_states.clone()
|
| 1495 |
+
hidden_states = torch.index_select(hidden_states, 0, unpacking_index).view(bsz, tgt_len, self.config.d_model)
|
| 1496 |
+
hidden_states = torch.where(attention_mask, hidden_states, 0)
|
| 1497 |
+
return hidden_states, hidden_states_packed, output_length, codes
|
| 1498 |
+
|
| 1499 |
+
|
| 1500 |
+
class MiMoAudioTokenizer(PreTrainedModel):
|
| 1501 |
+
config_class = MiMoAudioTokenizerConfig
|
| 1502 |
+
|
| 1503 |
+
def __init__(self, config: MiMoAudioTokenizerConfig):
|
| 1504 |
+
super().__init__(config)
|
| 1505 |
+
self.config = config
|
| 1506 |
+
self.sampling_rate = config.sampling_rate
|
| 1507 |
+
self.encoder = AudioTokenizerEncoder(config=config)
|
| 1508 |
+
self.downsample_rate = int(config.hop_length * 2 * config.avg_pooler)
|
| 1509 |
+
|
| 1510 |
+
def get_output_length(self, mel_len):
|
| 1511 |
+
return self.encoder.get_output_length(mel_len)
|
| 1512 |
+
|
| 1513 |
+
@torch.no_grad()
|
| 1514 |
+
def encode(self, mels, input_lens, use_quantizer=True):
|
| 1515 |
+
return self.encoder.encode(mels, input_lens=input_lens, use_quantizer=use_quantizer)
|
| 1516 |
+
|
| 1517 |
+
|
| 1518 |
+
def _at_group_by_length(features, lengths, max_length):
|
| 1519 |
+
split_points, current_sum = [], 0
|
| 1520 |
+
for i, seq_len in enumerate(lengths):
|
| 1521 |
+
if current_sum + seq_len > max_length and current_sum > 0:
|
| 1522 |
+
split_points.append(i)
|
| 1523 |
+
current_sum = seq_len.item()
|
| 1524 |
+
else:
|
| 1525 |
+
current_sum += seq_len.item()
|
| 1526 |
+
group_sizes, prev = [], 0
|
| 1527 |
+
for point in split_points:
|
| 1528 |
+
group_sizes.append(point - prev)
|
| 1529 |
+
prev = point
|
| 1530 |
+
if prev < len(lengths):
|
| 1531 |
+
group_sizes.append(len(lengths) - prev)
|
| 1532 |
+
len_groups = torch.split(lengths, group_sizes)
|
| 1533 |
+
feature_groups = torch.split(features, [g.sum().item() for g in len_groups])
|
| 1534 |
+
return feature_groups, len_groups
|
| 1535 |
+
|
| 1536 |
+
|
| 1537 |
+
@torch.no_grad()
|
| 1538 |
+
def tokenize_audio_batch(mels, audio_tokenizer_encoder, segment_size=6000, device=None):
|
| 1539 |
+
if not mels:
|
| 1540 |
+
return []
|
| 1541 |
+
if device is None:
|
| 1542 |
+
device = next(audio_tokenizer_encoder.parameters()).device
|
| 1543 |
+
input_len_seg_per_mel = []
|
| 1544 |
+
for m in mels:
|
| 1545 |
+
input_len = m.size(0)
|
| 1546 |
+
segs = [segment_size] * (input_len // segment_size)
|
| 1547 |
+
if input_len % segment_size > 0:
|
| 1548 |
+
segs.append(input_len % segment_size)
|
| 1549 |
+
input_len_seg_per_mel.append(segs)
|
| 1550 |
+
input_lens_flat = [s for segs in input_len_seg_per_mel for s in segs]
|
| 1551 |
+
input_features = torch.cat([m.to(device) for m in mels], dim=0)
|
| 1552 |
+
input_lens_t = torch.tensor(input_lens_flat, dtype=torch.long, device=device)
|
| 1553 |
+
feature_groups, len_groups = _at_group_by_length(input_features, input_lens_t, 256000)
|
| 1554 |
+
encoded_parts = []
|
| 1555 |
+
for features, lengths in zip(feature_groups, len_groups):
|
| 1556 |
+
codes, _ = audio_tokenizer_encoder.encode(input_features=features, input_lens=lengths, return_codes_only=True)
|
| 1557 |
+
encoded_parts.append(codes)
|
| 1558 |
+
codes = torch.cat(encoded_parts, dim=-1).transpose(0, 1).detach()
|
| 1559 |
+
code_lengths = []
|
| 1560 |
+
for segs in input_len_seg_per_mel:
|
| 1561 |
+
out_len = audio_tokenizer_encoder.get_output_length(torch.tensor(segs, dtype=torch.long, device=device))
|
| 1562 |
+
if getattr(audio_tokenizer_encoder, "down_sample_layer", None) is not None:
|
| 1563 |
+
avg = audio_tokenizer_encoder.config.avg_pooler
|
| 1564 |
+
out_len = out_len // avg + (out_len % avg != 0).long()
|
| 1565 |
+
code_lengths.append(out_len.sum().item())
|
| 1566 |
+
return list(torch.split(codes, code_lengths))
|
| 1567 |
+
|
| 1568 |
+
|
| 1569 |
+
# ---------------------------------------------------------------------------
|
| 1570 |
+
# LLM backbone
|
| 1571 |
+
# ---------------------------------------------------------------------------
|
| 1572 |
+
|
| 1573 |
+
|
| 1574 |
+
class MiMoV2Model(PreTrainedModel):
|
| 1575 |
+
config_class = MiMoV2Config
|
| 1576 |
+
attention_projection_layout = "split"
|
| 1577 |
+
|
| 1578 |
+
def __init__(self, config):
|
| 1579 |
+
super().__init__(config)
|
| 1580 |
+
self.attention_projection_layout = getattr(
|
| 1581 |
+
config, "attention_projection_layout", self.attention_projection_layout
|
| 1582 |
+
)
|
| 1583 |
+
self.vocab_size = config.vocab_size
|
| 1584 |
+
self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size)
|
| 1585 |
+
self.layers = nn.ModuleList(
|
| 1586 |
+
[
|
| 1587 |
+
MiMoV2DecoderLayer(
|
| 1588 |
+
config,
|
| 1589 |
+
layer_idx,
|
| 1590 |
+
attention_projection_layout=self.attention_projection_layout,
|
| 1591 |
+
)
|
| 1592 |
+
for layer_idx in range(config.num_hidden_layers)
|
| 1593 |
+
]
|
| 1594 |
+
)
|
| 1595 |
+
self.norm = MiMoV2RMSNorm(config.hidden_size, eps=config.layernorm_epsilon)
|
| 1596 |
+
self.rotary_emb = MiMoV2RotaryEmbedding(config=config, is_swa=False)
|
| 1597 |
+
self.swa_rotary_emb = MiMoV2RotaryEmbedding(config=config, is_swa=True)
|
| 1598 |
+
self.has_sliding_layers = any(pattern == 1 for pattern in config.hybrid_layer_pattern)
|
| 1599 |
+
self.config.layer_types = [
|
| 1600 |
+
"sliding_attention" if config.hybrid_layer_pattern[i] == 1 else "full_attention"
|
| 1601 |
+
for i in range(config.num_hidden_layers)
|
| 1602 |
+
]
|
| 1603 |
+
self.post_init()
|
| 1604 |
+
|
| 1605 |
+
def get_input_embeddings(self):
|
| 1606 |
+
return self.embed_tokens
|
| 1607 |
+
|
| 1608 |
+
def set_input_embeddings(self, value):
|
| 1609 |
+
self.embed_tokens = value
|
| 1610 |
+
|
| 1611 |
+
def forward(
|
| 1612 |
+
self,
|
| 1613 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 1614 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1615 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 1616 |
+
past_key_values: Optional[Cache] = None,
|
| 1617 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1618 |
+
use_cache: Optional[bool] = None,
|
| 1619 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 1620 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 1621 |
+
) -> BaseModelOutputWithPast:
|
| 1622 |
+
if (input_ids is None) ^ (inputs_embeds is not None):
|
| 1623 |
+
raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
|
| 1624 |
+
|
| 1625 |
+
use_cache = use_cache if use_cache is not None else self.config.use_cache
|
| 1626 |
+
|
| 1627 |
+
if inputs_embeds is None:
|
| 1628 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
| 1629 |
+
|
| 1630 |
+
if use_cache and past_key_values is None:
|
| 1631 |
+
past_key_values = DynamicCache(config=self.config)
|
| 1632 |
+
|
| 1633 |
+
if cache_position is None:
|
| 1634 |
+
past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
|
| 1635 |
+
cache_position = torch.arange(
|
| 1636 |
+
past_seen_tokens, past_seen_tokens + inputs_embeds.shape[1], device=inputs_embeds.device
|
| 1637 |
+
)
|
| 1638 |
+
|
| 1639 |
+
if position_ids is None:
|
| 1640 |
+
position_ids = cache_position.unsqueeze(0)
|
| 1641 |
+
|
| 1642 |
+
if not isinstance(causal_mask_mapping := attention_mask, dict):
|
| 1643 |
+
mask_kwargs = {
|
| 1644 |
+
"config": self.config,
|
| 1645 |
+
"input_embeds": inputs_embeds,
|
| 1646 |
+
"attention_mask": attention_mask,
|
| 1647 |
+
"cache_position": cache_position,
|
| 1648 |
+
"past_key_values": past_key_values,
|
| 1649 |
+
"position_ids": position_ids,
|
| 1650 |
+
}
|
| 1651 |
+
causal_mask_mapping = {
|
| 1652 |
+
"full_attention": create_causal_mask(**mask_kwargs),
|
| 1653 |
+
}
|
| 1654 |
+
if self.has_sliding_layers:
|
| 1655 |
+
if getattr(self.config, "sliding_window", None) is None:
|
| 1656 |
+
raise ValueError("MiMoV2 config `sliding_window` must be set when hybrid_layer_pattern uses SWA.")
|
| 1657 |
+
causal_mask_mapping["sliding_window_attention"] = create_sliding_window_causal_mask(**mask_kwargs)
|
| 1658 |
+
|
| 1659 |
+
hidden_states = inputs_embeds
|
| 1660 |
+
position_embeddings = self.rotary_emb(hidden_states, position_ids)
|
| 1661 |
+
swa_position_embeddings = self.swa_rotary_emb(hidden_states, position_ids)
|
| 1662 |
+
|
| 1663 |
+
for decoder_layer in self.layers[: self.config.num_hidden_layers]:
|
| 1664 |
+
hidden_states = decoder_layer(
|
| 1665 |
+
hidden_states,
|
| 1666 |
+
attention_mask=causal_mask_mapping[decoder_layer.attention_type],
|
| 1667 |
+
position_embeddings=position_embeddings
|
| 1668 |
+
if decoder_layer.attention_type == "full_attention"
|
| 1669 |
+
else swa_position_embeddings,
|
| 1670 |
+
position_ids=position_ids,
|
| 1671 |
+
past_key_values=past_key_values,
|
| 1672 |
+
use_cache=use_cache,
|
| 1673 |
+
cache_position=cache_position,
|
| 1674 |
+
**kwargs,
|
| 1675 |
+
)
|
| 1676 |
+
|
| 1677 |
+
hidden_states = self.norm(hidden_states)
|
| 1678 |
+
return BaseModelOutputWithPast(
|
| 1679 |
+
last_hidden_state=hidden_states,
|
| 1680 |
+
past_key_values=past_key_values if use_cache else None,
|
| 1681 |
+
)
|
| 1682 |
+
|
| 1683 |
+
|
| 1684 |
+
class MiMoV2ForCausalLM(PreTrainedModel, GenerationMixin):
|
| 1685 |
+
config_class = MiMoV2Config
|
| 1686 |
+
model_class = MiMoV2Model
|
| 1687 |
+
_tied_weights_keys = {"lm_head.weight": "model.embed_tokens.weight"}
|
| 1688 |
+
_tp_plan = {"lm_head": "colwise_rep"}
|
| 1689 |
+
_pp_plan = {"lm_head": (["hidden_states"], ["logits"])}
|
| 1690 |
+
_keys_to_ignore_on_load_unexpected = [
|
| 1691 |
+
r"model\.(swa_)?rotary_emb\.inv_freq",
|
| 1692 |
+
r"model\.layers\.\d+\.self_attn\.rotary_emb\.inv_freq",
|
| 1693 |
+
r"model\.layers\.\d+\.self_attn\.rotary_emb\.(cos_cached|sin_cached)",
|
| 1694 |
+
r"model\.mtp\..*",
|
| 1695 |
+
]
|
| 1696 |
+
_keys_to_ignore_on_load_missing = [
|
| 1697 |
+
r"audio_encoder\.input_local_transformer\.embed_tokens\.weight",
|
| 1698 |
+
]
|
| 1699 |
+
|
| 1700 |
+
def __init__(self, config):
|
| 1701 |
+
super().__init__(config)
|
| 1702 |
+
self.model = self.model_class(config)
|
| 1703 |
+
self.vocab_size = config.vocab_size
|
| 1704 |
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
| 1705 |
+
|
| 1706 |
+
if config.vision_config:
|
| 1707 |
+
self.visual = MiMoVisionTransformer(_as_namespace(config.vision_config))
|
| 1708 |
+
if config.audio_config:
|
| 1709 |
+
audio_cfg = _as_namespace(config.audio_config)
|
| 1710 |
+
self.speech_embeddings = _build_speech_embeddings(audio_cfg)
|
| 1711 |
+
self.audio_encoder = MiMoAudioEncoder(audio_cfg)
|
| 1712 |
+
|
| 1713 |
+
self.audio_tokenizer = None
|
| 1714 |
+
self.post_init()
|
| 1715 |
+
|
| 1716 |
+
def load_audio_tokenizer(self, path: str, device: torch.device | str | None = None, dtype: torch.dtype = torch.bfloat16):
|
| 1717 |
+
"""Load the audio tokenizer from a directory containing config.json and model.safetensors."""
|
| 1718 |
+
import json
|
| 1719 |
+
import os
|
| 1720 |
+
|
| 1721 |
+
from safetensors.torch import load_file
|
| 1722 |
+
|
| 1723 |
+
config_path = os.path.join(path, "config.json")
|
| 1724 |
+
with open(config_path) as f:
|
| 1725 |
+
config_dict = json.load(f)
|
| 1726 |
+
tokenizer_config = MiMoAudioTokenizerConfig(**config_dict)
|
| 1727 |
+
tokenizer_model = MiMoAudioTokenizer(tokenizer_config)
|
| 1728 |
+
|
| 1729 |
+
safetensors_path = os.path.join(path, "model.safetensors")
|
| 1730 |
+
bin_path = os.path.join(path, "pytorch_model.bin")
|
| 1731 |
+
if os.path.exists(safetensors_path):
|
| 1732 |
+
state_dict = load_file(safetensors_path, device="cpu")
|
| 1733 |
+
elif os.path.exists(bin_path):
|
| 1734 |
+
state_dict = torch.load(bin_path, map_location="cpu", weights_only=True)
|
| 1735 |
+
else:
|
| 1736 |
+
raise FileNotFoundError(f"No model weights found in {path}")
|
| 1737 |
+
tokenizer_model.load_state_dict(state_dict, strict=False)
|
| 1738 |
+
|
| 1739 |
+
if device is None:
|
| 1740 |
+
device = next(self.parameters()).device
|
| 1741 |
+
tokenizer_model = tokenizer_model.to(device=device, dtype=dtype)
|
| 1742 |
+
tokenizer_model.eval()
|
| 1743 |
+
tokenizer_model.requires_grad_(False)
|
| 1744 |
+
self.audio_tokenizer = tokenizer_model
|
| 1745 |
+
|
| 1746 |
+
def get_input_embeddings(self):
|
| 1747 |
+
return self.model.embed_tokens
|
| 1748 |
+
|
| 1749 |
+
def set_input_embeddings(self, value):
|
| 1750 |
+
self.model.embed_tokens = value
|
| 1751 |
+
|
| 1752 |
+
def get_output_embeddings(self):
|
| 1753 |
+
return self.lm_head
|
| 1754 |
+
|
| 1755 |
+
def set_output_embeddings(self, new_embeddings):
|
| 1756 |
+
self.lm_head = new_embeddings
|
| 1757 |
+
|
| 1758 |
+
def _get_multimodal_embeds(
|
| 1759 |
+
self,
|
| 1760 |
+
input_ids: torch.Tensor,
|
| 1761 |
+
inputs_embeds: torch.Tensor,
|
| 1762 |
+
pixel_values: Optional[torch.Tensor] = None,
|
| 1763 |
+
image_grid_thw: Optional[torch.Tensor] = None,
|
| 1764 |
+
image_embeds: Optional[torch.Tensor] = None,
|
| 1765 |
+
video_pixel_values: Optional[torch.Tensor] = None,
|
| 1766 |
+
video_grid_thw: Optional[torch.Tensor] = None,
|
| 1767 |
+
video_embeds: Optional[torch.Tensor] = None,
|
| 1768 |
+
audio_codes: Optional[torch.Tensor] = None,
|
| 1769 |
+
audio_embeds: Optional[torch.Tensor] = None,
|
| 1770 |
+
) -> torch.Tensor:
|
| 1771 |
+
has_image = image_embeds is not None or pixel_values is not None
|
| 1772 |
+
has_video = video_embeds is not None or video_pixel_values is not None
|
| 1773 |
+
has_audio = audio_embeds is not None or audio_codes is not None
|
| 1774 |
+
|
| 1775 |
+
if not (has_image or has_video or has_audio):
|
| 1776 |
+
return inputs_embeds
|
| 1777 |
+
|
| 1778 |
+
inputs_embeds = inputs_embeds.clone()
|
| 1779 |
+
|
| 1780 |
+
if has_image:
|
| 1781 |
+
cur_image_embeds = image_embeds if image_embeds is not None else self.visual(pixel_values=pixel_values, grid_thw=image_grid_thw)
|
| 1782 |
+
_replace_modal_embeddings_inplace(
|
| 1783 |
+
input_ids=input_ids, inputs_embeds=inputs_embeds,
|
| 1784 |
+
token_id=getattr(self.config, "image_token_id", None), modal_embeds=cur_image_embeds,
|
| 1785 |
+
)
|
| 1786 |
+
|
| 1787 |
+
if has_video:
|
| 1788 |
+
cur_video_embeds = video_embeds if video_embeds is not None else self.visual(pixel_values=video_pixel_values, grid_thw=video_grid_thw)
|
| 1789 |
+
_replace_modal_embeddings_inplace(
|
| 1790 |
+
input_ids=input_ids, inputs_embeds=inputs_embeds,
|
| 1791 |
+
token_id=getattr(self.config, "video_token_id", None), modal_embeds=cur_video_embeds,
|
| 1792 |
+
)
|
| 1793 |
+
|
| 1794 |
+
if has_audio:
|
| 1795 |
+
_replace_modal_embeddings_inplace(
|
| 1796 |
+
input_ids=input_ids, inputs_embeds=inputs_embeds,
|
| 1797 |
+
token_id=getattr(self.config, "audio_token_id", None),
|
| 1798 |
+
modal_embeds=self.audio_encoder(
|
| 1799 |
+
speech_embeddings=self.speech_embeddings, audio_codes=audio_codes, audio_embeds=audio_embeds,
|
| 1800 |
+
),
|
| 1801 |
+
)
|
| 1802 |
+
|
| 1803 |
+
return inputs_embeds
|
| 1804 |
+
|
| 1805 |
+
@can_return_tuple
|
| 1806 |
+
def forward(
|
| 1807 |
+
self,
|
| 1808 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 1809 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 1810 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 1811 |
+
past_key_values: Optional[Cache] = None,
|
| 1812 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1813 |
+
labels: Optional[torch.LongTensor] = None,
|
| 1814 |
+
use_cache: Optional[bool] = None,
|
| 1815 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 1816 |
+
logits_to_keep: Union[int, torch.Tensor] = 0,
|
| 1817 |
+
pixel_values: Optional[torch.Tensor] = None,
|
| 1818 |
+
image_grid_thw: Optional[torch.Tensor] = None,
|
| 1819 |
+
image_embeds: Optional[torch.Tensor] = None,
|
| 1820 |
+
video_pixel_values: Optional[torch.Tensor] = None,
|
| 1821 |
+
video_grid_thw: Optional[torch.Tensor] = None,
|
| 1822 |
+
video_embeds: Optional[torch.Tensor] = None,
|
| 1823 |
+
audio_codes: Optional[torch.Tensor] = None,
|
| 1824 |
+
audio_embeds: Optional[torch.Tensor] = None,
|
| 1825 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 1826 |
+
) -> CausalLMOutputWithPast:
|
| 1827 |
+
if inputs_embeds is None and input_ids is not None:
|
| 1828 |
+
inputs_embeds = self.model.get_input_embeddings()(input_ids)
|
| 1829 |
+
if any(x is not None for x in [pixel_values, image_embeds, video_pixel_values, video_embeds, audio_codes, audio_embeds]):
|
| 1830 |
+
inputs_embeds = self._get_multimodal_embeds(
|
| 1831 |
+
input_ids=input_ids, inputs_embeds=inputs_embeds,
|
| 1832 |
+
pixel_values=pixel_values, image_grid_thw=image_grid_thw, image_embeds=image_embeds,
|
| 1833 |
+
video_pixel_values=video_pixel_values, video_grid_thw=video_grid_thw, video_embeds=video_embeds,
|
| 1834 |
+
audio_codes=audio_codes, audio_embeds=audio_embeds,
|
| 1835 |
+
)
|
| 1836 |
+
input_ids = None
|
| 1837 |
+
|
| 1838 |
+
outputs: BaseModelOutputWithPast = self.model(
|
| 1839 |
+
input_ids=input_ids,
|
| 1840 |
+
attention_mask=attention_mask,
|
| 1841 |
+
position_ids=position_ids,
|
| 1842 |
+
past_key_values=past_key_values,
|
| 1843 |
+
inputs_embeds=inputs_embeds,
|
| 1844 |
+
use_cache=use_cache,
|
| 1845 |
+
cache_position=cache_position,
|
| 1846 |
+
**kwargs,
|
| 1847 |
+
)
|
| 1848 |
+
|
| 1849 |
+
hidden_states = outputs.last_hidden_state
|
| 1850 |
+
slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
|
| 1851 |
+
logits = self.lm_head(hidden_states[:, slice_indices, :])
|
| 1852 |
+
|
| 1853 |
+
loss = None
|
| 1854 |
+
if labels is not None:
|
| 1855 |
+
loss = self.loss_function(logits=logits, labels=labels, vocab_size=self.config.vocab_size, **kwargs)
|
| 1856 |
+
|
| 1857 |
+
return CausalLMOutputWithPast(
|
| 1858 |
+
loss=loss,
|
| 1859 |
+
logits=logits,
|
| 1860 |
+
past_key_values=outputs.past_key_values,
|
| 1861 |
+
hidden_states=outputs.hidden_states,
|
| 1862 |
+
attentions=outputs.attentions,
|
| 1863 |
+
)
|
| 1864 |
+
|
| 1865 |
+
|
| 1866 |
+
__all__ = [
|
| 1867 |
+
"MiMoAudioTokenizer",
|
| 1868 |
+
"MiMoAudioTokenizerConfig",
|
| 1869 |
+
"MiMoV2Attention",
|
| 1870 |
+
"MiMoV2DecoderLayer",
|
| 1871 |
+
"MiMoV2ForCausalLM",
|
| 1872 |
+
"MiMoV2MLP",
|
| 1873 |
+
"MiMoV2MoE",
|
| 1874 |
+
"MiMoV2MoEGate",
|
| 1875 |
+
"MiMoV2Model",
|
| 1876 |
+
"MiMoV2RMSNorm",
|
| 1877 |
+
"MiMoV2RotaryEmbedding",
|
| 1878 |
+
]
|
moe_L01.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d9d77a46b450101af9fcc5e37b995c7d20848ddd11fa32678bfc0a196c998d48
|
| 3 |
+
size 3422552560
|
moe_L02.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:74e042bc60c5d2c4389cf04c92b3043188242c4cecf5388e76744000524fb239
|
| 3 |
+
size 3422552560
|
moe_L03.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:92c9b9917d2a810011ce2d524d894294f679e427c6e61d562c280921ceb521e2
|
| 3 |
+
size 3422552560
|
moe_L04.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cc5c1f7ce02ba258c49fc345a419f8e9b0799b83e88793e070b801ed495e65f2
|
| 3 |
+
size 3422552560
|
moe_L05.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:04f84e210f932878ea95578c7b7b5ea751dea3cfbeacb9a0e62ae3b76368947a
|
| 3 |
+
size 3422552560
|
moe_L06.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:611aeb7870f3b3b872d592fc43de3653b32eef343f60ef9abc9a7b300fb0cf23
|
| 3 |
+
size 3422552560
|
moe_L07.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4015a5be96396a877d99c017aee2507971ad98ce3a4dc1545d83b7a83454d472
|
| 3 |
+
size 3422552560
|
moe_L08.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5be5f511c89e23389a5b159c9f0f03cf691ffda700ad920cecfc976fc1d8ff69
|
| 3 |
+
size 3422552560
|
moe_L09.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0a98bac9dcc14d144a660dd49c0c8abfe923014cb2cf054741f388b4135fe2fe
|
| 3 |
+
size 3422552560
|
moe_L10.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4740c74cf401bc0b03a2669e355836fa3d08d1a09bf81457f3f2d708d697e5b9
|
| 3 |
+
size 3422552560
|
moe_L11.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:69ccda253312e4b110d5a13fee2696db9cc6782eecd1cbe00e24f598d9b27f1d
|
| 3 |
+
size 3422552560
|
moe_L12.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a671a4d0fe3e1ed38399a631fa0f34aaabb094eb702c3ca2145c20e6a37f26e7
|
| 3 |
+
size 3422552560
|
moe_L13.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f7be65dbfacfbaeb6515c7bd10fd9db5c6abaca2264a6a5d90afaaad918dcc32
|
| 3 |
+
size 3422552560
|
moe_L14.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d1113d4747535a0e84e1fb7d3a8958af30cbd1d2d350856bdf584154795c5453
|
| 3 |
+
size 3422552560
|
moe_L15.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8007b2821f4dbc48ec7d3c012ba8a2506e35fad34b1453b8b23f3f4226e53bf2
|
| 3 |
+
size 3422552560
|
moe_L16.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ad0d03953561467dd99d4100d83f533fdb374e506ed863825eb195528f58d6cb
|
| 3 |
+
size 3422552560
|
moe_L17.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d3165b45e67336280e87c6fd10818c33d56253ea783885976ede6c2cd855639a
|
| 3 |
+
size 3422552560
|
moe_L18.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5297ed99d24cfce1b03e9c8ead054a963663d6e93d9a3701ea7c4596236ac055
|
| 3 |
+
size 3422552560
|
moe_L19.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b9f82e351b4939a5f68096897f0b8e82e509f83e81e89eaf328d4593f9a75027
|
| 3 |
+
size 3422552560
|
moe_L20.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:665c05a1db7ead0a28af22692c78fd17ed18a262b1cd6abac08b4844d74d83a8
|
| 3 |
+
size 3422552560
|
moe_L21.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6f65c50957b8674bf29346f3911a201180222d359f6bfbf267d13b1afc029854
|
| 3 |
+
size 3422552560
|
moe_L22.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:78a62398b488cd8b656b92b628c00916170cd2fce81c769efb8e744bc314cf26
|
| 3 |
+
size 3422552560
|
moe_L23.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c7fe46fee51ad3c235ab273662755a20ed48a22b3b4f9b918d2b9d10cdaab8d0
|
| 3 |
+
size 3422552560
|
moe_L24.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:16e41b3cfa89d78c8295dd4ea220dbcd64705d9b2d77728802fbb03ba4e89620
|
| 3 |
+
size 3422552560
|
moe_L25.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d585fffad189aff1578fffac61e82d479d795a3b4afc62d6f0a6974b776c1f0b
|
| 3 |
+
size 3422552560
|
moe_L26.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:16712ac61bc2d275a6bb2643df5e23e562bc8f11e8aba53b648af82356213bc6
|
| 3 |
+
size 3422552560
|
moe_L27.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1b5f753fbb652e7b4e83b9f543d9ba0bea843e239170aed8be2092578184e257
|
| 3 |
+
size 3422552560
|
moe_L28.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5fe035da6c22b757a755975408b8bb5aee3b96125ce624940f5c5e77f2fbbc07
|
| 3 |
+
size 3422552560
|
moe_L29.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2dd54ddf079a870cd5175bbc760385be4be495d8381c907fac8671b1e211bdff
|
| 3 |
+
size 3422552560
|
moe_L30.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5cf05e83b8ec552b1dba320a2fe6b272fc88a525abf0731c54f76c261ab9ee01
|
| 3 |
+
size 3422552560
|
moe_L31.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:651e5920261136e646935120426c6041367b09d1faa2ff67da61347e12a88cb1
|
| 3 |
+
size 3422552560
|
moe_L32.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:012a9c868051548dea46ef3836e486c963b2893e4edb9b89b9bba9703a8da6a9
|
| 3 |
+
size 3422552560
|
moe_L33.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9d2db6dba965c4ca0112e201b4bbb0709938eb2af96c73d8370151a1fa03a666
|
| 3 |
+
size 3422552560
|
moe_L34.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ee3db07b5a36650f252aa73920ac7e1b4cd8813dc9af14fbd14e5ce7a86a657e
|
| 3 |
+
size 3422552560
|
moe_L35.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:65f3b0c8c5d87ba34a977dfea0414c448df2fc24cf63984232c4bd3eea228fa3
|
| 3 |
+
size 3422552560
|
moe_L36.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2749586e631da71885e29f7467d7fdda3837c07e137c488c57b8ea2fbdbca4c8
|
| 3 |
+
size 3422552560
|
moe_L37.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:164c93078101e430841089172bccf604b3bc432abac6b2f4c241ae1c9051a2a2
|
| 3 |
+
size 3422552560
|
moe_L38.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fed71afbe58c389de8cb9a3e2973622f9d773af36dfb75e0a1ccc3de3f7e7a5d
|
| 3 |
+
size 3422552560
|
moe_L39.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cccef021a0c2785927ae16c50ab2ed406e833fb533f36cb736d84b8f9a7c3e33
|
| 3 |
+
size 3422552560
|