Instructions to use Baekpica/MiMo-V2.6-Flash-RL-GGUF with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use Baekpica/MiMo-V2.6-Flash-RL-GGUF with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf Baekpica/MiMo-V2.6-Flash-RL-GGUF:Q8_0 # Run inference directly in the terminal: llama cli -hf Baekpica/MiMo-V2.6-Flash-RL-GGUF:Q8_0
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf Baekpica/MiMo-V2.6-Flash-RL-GGUF:Q8_0 # Run inference directly in the terminal: llama cli -hf Baekpica/MiMo-V2.6-Flash-RL-GGUF:Q8_0
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf Baekpica/MiMo-V2.6-Flash-RL-GGUF:Q8_0 # Run inference directly in the terminal: ./llama-cli -hf Baekpica/MiMo-V2.6-Flash-RL-GGUF:Q8_0
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf Baekpica/MiMo-V2.6-Flash-RL-GGUF:Q8_0 # Run inference directly in the terminal: ./build/bin/llama-cli -hf Baekpica/MiMo-V2.6-Flash-RL-GGUF:Q8_0
Use Docker
docker model run hf.co/Baekpica/MiMo-V2.6-Flash-RL-GGUF:Q8_0
- LM Studio
- Jan
- vLLM
How to use Baekpica/MiMo-V2.6-Flash-RL-GGUF with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Baekpica/MiMo-V2.6-Flash-RL-GGUF" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Baekpica/MiMo-V2.6-Flash-RL-GGUF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Baekpica/MiMo-V2.6-Flash-RL-GGUF:Q8_0
- Ollama
How to use Baekpica/MiMo-V2.6-Flash-RL-GGUF with Ollama:
ollama run hf.co/Baekpica/MiMo-V2.6-Flash-RL-GGUF:Q8_0
- Unsloth Desktop
- Pi
How to use Baekpica/MiMo-V2.6-Flash-RL-GGUF with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf Baekpica/MiMo-V2.6-Flash-RL-GGUF:Q8_0
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "Baekpica/MiMo-V2.6-Flash-RL-GGUF:Q8_0" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Docker Model Runner
How to use Baekpica/MiMo-V2.6-Flash-RL-GGUF with Docker Model Runner:
docker model run hf.co/Baekpica/MiMo-V2.6-Flash-RL-GGUF:Q8_0
- Lemonade
How to use Baekpica/MiMo-V2.6-Flash-RL-GGUF with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull Baekpica/MiMo-V2.6-Flash-RL-GGUF:Q8_0
Run and chat with the model
lemonade run user.MiMo-V2.6-Flash-RL-GGUF-Q8_0
List all available models
lemonade list
- Hermes Agent
How to use Baekpica/MiMo-V2.6-Flash-RL-GGUF with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf Baekpica/MiMo-V2.6-Flash-RL-GGUF:Q8_0
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default Baekpica/MiMo-V2.6-Flash-RL-GGUF:Q8_0
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use Baekpica/MiMo-V2.6-Flash-RL-GGUF with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf Baekpica/MiMo-V2.6-Flash-RL-GGUF:Q8_0
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "Baekpica/MiMo-V2.6-Flash-RL-GGUF:Q8_0" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
Add BF16 multimodal projector and audited Q8 DFlash auxiliary package
Browse files- .gitattributes +2 -0
- MiMo-V2.6-Flash-RL-DFlash-Q8_0.gguf +3 -0
- README.md +15 -1
- SHA256SUMS +2 -0
- artifact-manifest.json +10 -0
- dflash-audit.json +419 -0
- dflash/config.json +57 -0
- dflash/dflash.py +379 -0
- dflash/mask_embedding.pt +3 -0
- dflash/runtime-contract.json +38 -0
- mmproj-MiMo-V2.6-Flash-RL-BF16.gguf +3 -0
- toolchain-pins.json +5 -0
- vision-parity-fp32.json +13 -0
- vision-parity.json +12 -0
.gitattributes
CHANGED
|
@@ -37,3 +37,5 @@ MiMo-V2.6-Flash-RL-MXFP4-BF16-00001-of-00004.gguf filter=lfs diff=lfs merge=lfs
|
|
| 37 |
MiMo-V2.6-Flash-RL-MXFP4-BF16-00002-of-00004.gguf filter=lfs diff=lfs merge=lfs -text
|
| 38 |
MiMo-V2.6-Flash-RL-MXFP4-BF16-00003-of-00004.gguf filter=lfs diff=lfs merge=lfs -text
|
| 39 |
MiMo-V2.6-Flash-RL-MXFP4-BF16-00004-of-00004.gguf filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 37 |
MiMo-V2.6-Flash-RL-MXFP4-BF16-00002-of-00004.gguf filter=lfs diff=lfs merge=lfs -text
|
| 38 |
MiMo-V2.6-Flash-RL-MXFP4-BF16-00003-of-00004.gguf filter=lfs diff=lfs merge=lfs -text
|
| 39 |
MiMo-V2.6-Flash-RL-MXFP4-BF16-00004-of-00004.gguf filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
MiMo-V2.6-Flash-RL-DFlash-Q8_0.gguf filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
mmproj-MiMo-V2.6-Flash-RL-BF16.gguf filter=lfs diff=lfs merge=lfs -text
|
MiMo-V2.6-Flash-RL-DFlash-Q8_0.gguf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:06a56d466017739918f2e1c9b771f08ac5cb92d7ea2173bbb5537a82284a7d8c
|
| 3 |
+
size 1565911104
|
README.md
CHANGED
|
@@ -29,7 +29,21 @@ The four `MXFP4-BF16` shards preserve the original routed experts through an exa
|
|
| 29 |
| `MiMo-V2.6-Flash-RL-MXFP4-BF16-00004-of-00004.gguf` | 41,422,766,592 |
|
| 30 |
| **Total** | **174,908,254,624** |
|
| 31 |
|
| 32 |
-
Keep all shards together and open the first shard. The language artifact includes the checkpoint's three embedded MTP blocks; this is not evidence of validated speculative decoding. Multimodal encoders and the separate DFlash model are separate components and are not supplied by these four shards alone.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
## Validation status
|
| 35 |
|
|
|
|
| 29 |
| `MiMo-V2.6-Flash-RL-MXFP4-BF16-00004-of-00004.gguf` | 41,422,766,592 |
|
| 30 |
| **Total** | **174,908,254,624** |
|
| 31 |
|
| 32 |
+
Keep all shards together and open the first shard. The language artifact includes the checkpoint's three embedded MTP blocks; this is not evidence of validated speculative decoding. Multimodal encoders and the separate DFlash model are separate components and are not supplied by these four shards alone. They are included as the auxiliary files listed below.
|
| 33 |
+
|
| 34 |
+
## Auxiliary artifacts
|
| 35 |
+
|
| 36 |
+
| File | Role | Validation |
|
| 37 |
+
|---|---|---|
|
| 38 |
+
| `mmproj-MiMo-V2.6-Flash-RL-BF16.gguf` | BF16 image/audio input encoders and projector, about 2.75 GB | One-image native/GGUF numerical comparison; full runtime media validation pending |
|
| 39 |
+
| `MiMo-V2.6-Flash-RL-DFlash-Q8_0.gguf` | Five-layer Q8_0 draft, about 1.56 GB | 63-tensor mapping/shape audit, exact F32 and sampled Q8 error checks; runtime acceptance untested |
|
| 40 |
+
| `dflash/` | Original config, learned mask embedding, upstream example, and explicit runtime contract | Source files retained byte for byte |
|
| 41 |
+
|
| 42 |
+
The DFlash GGUF explicitly preserves 64 rotary dimensions per 128-dimensional head
|
| 43 |
+
and attention value scale 0.612. Its config, sinks, target-layer mapping, and learned
|
| 44 |
+
mask embedding must be consumed by a compatible runtime. The bundled upstream
|
| 45 |
+
Python example does not implement every MiMo-specific draft setting; the runtime
|
| 46 |
+
contract records the production reference. No stock-runtime compatibility is claimed.
|
| 47 |
|
| 48 |
## Validation status
|
| 49 |
|
SHA256SUMS
CHANGED
|
@@ -2,3 +2,5 @@
|
|
| 2 |
caf0e120484239878cbf389914e17f2dd9cb733dd0f9c87c35437b9e649ec551 MiMo-V2.6-Flash-RL-MXFP4-BF16-00002-of-00004.gguf
|
| 3 |
c92a8d8ba4eea32c8ff8ca7ba403bc4df90b3fec1b6bf5630d8672aeb2837d16 MiMo-V2.6-Flash-RL-MXFP4-BF16-00003-of-00004.gguf
|
| 4 |
5c91e1e8489000fe5e281616b4b13c7710eaddf7ea82a6808458b26eb575c783 MiMo-V2.6-Flash-RL-MXFP4-BF16-00004-of-00004.gguf
|
|
|
|
|
|
|
|
|
| 2 |
caf0e120484239878cbf389914e17f2dd9cb733dd0f9c87c35437b9e649ec551 MiMo-V2.6-Flash-RL-MXFP4-BF16-00002-of-00004.gguf
|
| 3 |
c92a8d8ba4eea32c8ff8ca7ba403bc4df90b3fec1b6bf5630d8672aeb2837d16 MiMo-V2.6-Flash-RL-MXFP4-BF16-00003-of-00004.gguf
|
| 4 |
5c91e1e8489000fe5e281616b4b13c7710eaddf7ea82a6808458b26eb575c783 MiMo-V2.6-Flash-RL-MXFP4-BF16-00004-of-00004.gguf
|
| 5 |
+
333af1e9f86c4c4be2305c655a9a4fe7684a68e127d513832b8ea27cd89408d6 mmproj-MiMo-V2.6-Flash-RL-BF16.gguf
|
| 6 |
+
06a56d466017739918f2e1c9b771f08ac5cb92d7ea2173bbb5537a82284a7d8c MiMo-V2.6-Flash-RL-DFlash-Q8_0.gguf
|
artifact-manifest.json
CHANGED
|
@@ -22,6 +22,16 @@
|
|
| 22 |
"file": "MiMo-V2.6-Flash-RL-MXFP4-BF16-00004-of-00004.gguf",
|
| 23 |
"bytes": 41422766592,
|
| 24 |
"sha256": "5c91e1e8489000fe5e281616b4b13c7710eaddf7ea82a6808458b26eb575c783"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
}
|
| 26 |
]
|
| 27 |
}
|
|
|
|
| 22 |
"file": "MiMo-V2.6-Flash-RL-MXFP4-BF16-00004-of-00004.gguf",
|
| 23 |
"bytes": 41422766592,
|
| 24 |
"sha256": "5c91e1e8489000fe5e281616b4b13c7710eaddf7ea82a6808458b26eb575c783"
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"file": "mmproj-MiMo-V2.6-Flash-RL-BF16.gguf",
|
| 28 |
+
"bytes": 2748509792,
|
| 29 |
+
"sha256": "333af1e9f86c4c4be2305c655a9a4fe7684a68e127d513832b8ea27cd89408d6"
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"file": "MiMo-V2.6-Flash-RL-DFlash-Q8_0.gguf",
|
| 33 |
+
"bytes": 1565911104,
|
| 34 |
+
"sha256": "06a56d466017739918f2e1c9b771f08ac5cb92d7ea2173bbb5537a82284a7d8c"
|
| 35 |
}
|
| 36 |
]
|
| 37 |
}
|
dflash-audit.json
ADDED
|
@@ -0,0 +1,419 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"passed": true,
|
| 3 |
+
"tensor_count": 63,
|
| 4 |
+
"source_to_gguf_mapping": "exact set and shape match",
|
| 5 |
+
"f32_check": "all elements equal",
|
| 6 |
+
"q8_check": "three deterministic rows per matrix, relative L2 below 0.03",
|
| 7 |
+
"metadata": {
|
| 8 |
+
"dflash.block_count": 5,
|
| 9 |
+
"dflash.context_length": 1048576,
|
| 10 |
+
"dflash.embedding_length": 4096,
|
| 11 |
+
"dflash.feed_forward_length": 16384,
|
| 12 |
+
"dflash.attention.head_count": 64,
|
| 13 |
+
"dflash.attention.head_count_kv": 8,
|
| 14 |
+
"dflash.attention.causal": false,
|
| 15 |
+
"dflash.rope.freq_base": 10000.0,
|
| 16 |
+
"dflash.attention.layer_norm_rms_epsilon": 9.999999974752427e-07,
|
| 17 |
+
"dflash.attention.key_length": 128,
|
| 18 |
+
"dflash.attention.value_length": 128,
|
| 19 |
+
"dflash.block_size": 8,
|
| 20 |
+
"dflash.target_layers": [
|
| 21 |
+
1,
|
| 22 |
+
12,
|
| 23 |
+
24,
|
| 24 |
+
36,
|
| 25 |
+
48
|
| 26 |
+
],
|
| 27 |
+
"dflash.attention.sliding_window": 1024,
|
| 28 |
+
"dflash.attention.sliding_window_pattern": [
|
| 29 |
+
true,
|
| 30 |
+
true,
|
| 31 |
+
true,
|
| 32 |
+
true,
|
| 33 |
+
true
|
| 34 |
+
],
|
| 35 |
+
"dflash.rope.dimension_count": 64,
|
| 36 |
+
"dflash.attention.value_scale": 0.6119999885559082
|
| 37 |
+
},
|
| 38 |
+
"rows": [
|
| 39 |
+
{
|
| 40 |
+
"source": "fc.weight",
|
| 41 |
+
"gguf": "fc.weight",
|
| 42 |
+
"type": "Q8_0",
|
| 43 |
+
"sampled_relative_l2": 0.005588418338447809
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"source": "hidden_norm.weight",
|
| 47 |
+
"gguf": "enc.output_norm.weight",
|
| 48 |
+
"type": "F32",
|
| 49 |
+
"sampled_relative_l2": 0.0
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"source": "layers.0.input_layernorm.weight",
|
| 53 |
+
"gguf": "blk.0.attn_norm.weight",
|
| 54 |
+
"type": "F32",
|
| 55 |
+
"sampled_relative_l2": 0.0
|
| 56 |
+
},
|
| 57 |
+
{
|
| 58 |
+
"source": "layers.0.mlp.down_proj.weight",
|
| 59 |
+
"gguf": "blk.0.ffn_down.weight",
|
| 60 |
+
"type": "Q8_0",
|
| 61 |
+
"sampled_relative_l2": 0.005761090200394392
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"source": "layers.0.mlp.gate_proj.weight",
|
| 65 |
+
"gguf": "blk.0.ffn_gate.weight",
|
| 66 |
+
"type": "Q8_0",
|
| 67 |
+
"sampled_relative_l2": 0.005506220273673534
|
| 68 |
+
},
|
| 69 |
+
{
|
| 70 |
+
"source": "layers.0.mlp.up_proj.weight",
|
| 71 |
+
"gguf": "blk.0.ffn_up.weight",
|
| 72 |
+
"type": "Q8_0",
|
| 73 |
+
"sampled_relative_l2": 0.005492477677762508
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"source": "layers.0.post_attention_layernorm.weight",
|
| 77 |
+
"gguf": "blk.0.ffn_norm.weight",
|
| 78 |
+
"type": "F32",
|
| 79 |
+
"sampled_relative_l2": 0.0
|
| 80 |
+
},
|
| 81 |
+
{
|
| 82 |
+
"source": "layers.0.self_attn.attention_sink_bias",
|
| 83 |
+
"gguf": "blk.0.attn_sinks.weight",
|
| 84 |
+
"type": "F32",
|
| 85 |
+
"sampled_relative_l2": 0.0
|
| 86 |
+
},
|
| 87 |
+
{
|
| 88 |
+
"source": "layers.0.self_attn.k_norm.weight",
|
| 89 |
+
"gguf": "blk.0.attn_k_norm.weight",
|
| 90 |
+
"type": "F32",
|
| 91 |
+
"sampled_relative_l2": 0.0
|
| 92 |
+
},
|
| 93 |
+
{
|
| 94 |
+
"source": "layers.0.self_attn.k_proj.weight",
|
| 95 |
+
"gguf": "blk.0.attn_k.weight",
|
| 96 |
+
"type": "Q8_0",
|
| 97 |
+
"sampled_relative_l2": 0.005711852107197046
|
| 98 |
+
},
|
| 99 |
+
{
|
| 100 |
+
"source": "layers.0.self_attn.o_proj.weight",
|
| 101 |
+
"gguf": "blk.0.attn_output.weight",
|
| 102 |
+
"type": "Q8_0",
|
| 103 |
+
"sampled_relative_l2": 0.00542857451364398
|
| 104 |
+
},
|
| 105 |
+
{
|
| 106 |
+
"source": "layers.0.self_attn.q_norm.weight",
|
| 107 |
+
"gguf": "blk.0.attn_q_norm.weight",
|
| 108 |
+
"type": "F32",
|
| 109 |
+
"sampled_relative_l2": 0.0
|
| 110 |
+
},
|
| 111 |
+
{
|
| 112 |
+
"source": "layers.0.self_attn.q_proj.weight",
|
| 113 |
+
"gguf": "blk.0.attn_q.weight",
|
| 114 |
+
"type": "Q8_0",
|
| 115 |
+
"sampled_relative_l2": 0.00566287524998188
|
| 116 |
+
},
|
| 117 |
+
{
|
| 118 |
+
"source": "layers.0.self_attn.v_proj.weight",
|
| 119 |
+
"gguf": "blk.0.attn_v.weight",
|
| 120 |
+
"type": "Q8_0",
|
| 121 |
+
"sampled_relative_l2": 0.005591947585344315
|
| 122 |
+
},
|
| 123 |
+
{
|
| 124 |
+
"source": "layers.1.input_layernorm.weight",
|
| 125 |
+
"gguf": "blk.1.attn_norm.weight",
|
| 126 |
+
"type": "F32",
|
| 127 |
+
"sampled_relative_l2": 0.0
|
| 128 |
+
},
|
| 129 |
+
{
|
| 130 |
+
"source": "layers.1.mlp.down_proj.weight",
|
| 131 |
+
"gguf": "blk.1.ffn_down.weight",
|
| 132 |
+
"type": "Q8_0",
|
| 133 |
+
"sampled_relative_l2": 0.005702429451048374
|
| 134 |
+
},
|
| 135 |
+
{
|
| 136 |
+
"source": "layers.1.mlp.gate_proj.weight",
|
| 137 |
+
"gguf": "blk.1.ffn_gate.weight",
|
| 138 |
+
"type": "Q8_0",
|
| 139 |
+
"sampled_relative_l2": 0.0054396879859268665
|
| 140 |
+
},
|
| 141 |
+
{
|
| 142 |
+
"source": "layers.1.mlp.up_proj.weight",
|
| 143 |
+
"gguf": "blk.1.ffn_up.weight",
|
| 144 |
+
"type": "Q8_0",
|
| 145 |
+
"sampled_relative_l2": 0.005450685042887926
|
| 146 |
+
},
|
| 147 |
+
{
|
| 148 |
+
"source": "layers.1.post_attention_layernorm.weight",
|
| 149 |
+
"gguf": "blk.1.ffn_norm.weight",
|
| 150 |
+
"type": "F32",
|
| 151 |
+
"sampled_relative_l2": 0.0
|
| 152 |
+
},
|
| 153 |
+
{
|
| 154 |
+
"source": "layers.1.self_attn.attention_sink_bias",
|
| 155 |
+
"gguf": "blk.1.attn_sinks.weight",
|
| 156 |
+
"type": "F32",
|
| 157 |
+
"sampled_relative_l2": 0.0
|
| 158 |
+
},
|
| 159 |
+
{
|
| 160 |
+
"source": "layers.1.self_attn.k_norm.weight",
|
| 161 |
+
"gguf": "blk.1.attn_k_norm.weight",
|
| 162 |
+
"type": "F32",
|
| 163 |
+
"sampled_relative_l2": 0.0
|
| 164 |
+
},
|
| 165 |
+
{
|
| 166 |
+
"source": "layers.1.self_attn.k_proj.weight",
|
| 167 |
+
"gguf": "blk.1.attn_k.weight",
|
| 168 |
+
"type": "Q8_0",
|
| 169 |
+
"sampled_relative_l2": 0.005590083077549934
|
| 170 |
+
},
|
| 171 |
+
{
|
| 172 |
+
"source": "layers.1.self_attn.o_proj.weight",
|
| 173 |
+
"gguf": "blk.1.attn_output.weight",
|
| 174 |
+
"type": "Q8_0",
|
| 175 |
+
"sampled_relative_l2": 0.005548989400267601
|
| 176 |
+
},
|
| 177 |
+
{
|
| 178 |
+
"source": "layers.1.self_attn.q_norm.weight",
|
| 179 |
+
"gguf": "blk.1.attn_q_norm.weight",
|
| 180 |
+
"type": "F32",
|
| 181 |
+
"sampled_relative_l2": 0.0
|
| 182 |
+
},
|
| 183 |
+
{
|
| 184 |
+
"source": "layers.1.self_attn.q_proj.weight",
|
| 185 |
+
"gguf": "blk.1.attn_q.weight",
|
| 186 |
+
"type": "Q8_0",
|
| 187 |
+
"sampled_relative_l2": 0.00569014111533761
|
| 188 |
+
},
|
| 189 |
+
{
|
| 190 |
+
"source": "layers.1.self_attn.v_proj.weight",
|
| 191 |
+
"gguf": "blk.1.attn_v.weight",
|
| 192 |
+
"type": "Q8_0",
|
| 193 |
+
"sampled_relative_l2": 0.005482448264956474
|
| 194 |
+
},
|
| 195 |
+
{
|
| 196 |
+
"source": "layers.2.input_layernorm.weight",
|
| 197 |
+
"gguf": "blk.2.attn_norm.weight",
|
| 198 |
+
"type": "F32",
|
| 199 |
+
"sampled_relative_l2": 0.0
|
| 200 |
+
},
|
| 201 |
+
{
|
| 202 |
+
"source": "layers.2.mlp.down_proj.weight",
|
| 203 |
+
"gguf": "blk.2.ffn_down.weight",
|
| 204 |
+
"type": "Q8_0",
|
| 205 |
+
"sampled_relative_l2": 0.005693534389138222
|
| 206 |
+
},
|
| 207 |
+
{
|
| 208 |
+
"source": "layers.2.mlp.gate_proj.weight",
|
| 209 |
+
"gguf": "blk.2.ffn_gate.weight",
|
| 210 |
+
"type": "Q8_0",
|
| 211 |
+
"sampled_relative_l2": 0.005409534554928541
|
| 212 |
+
},
|
| 213 |
+
{
|
| 214 |
+
"source": "layers.2.mlp.up_proj.weight",
|
| 215 |
+
"gguf": "blk.2.ffn_up.weight",
|
| 216 |
+
"type": "Q8_0",
|
| 217 |
+
"sampled_relative_l2": 0.005460306536406279
|
| 218 |
+
},
|
| 219 |
+
{
|
| 220 |
+
"source": "layers.2.post_attention_layernorm.weight",
|
| 221 |
+
"gguf": "blk.2.ffn_norm.weight",
|
| 222 |
+
"type": "F32",
|
| 223 |
+
"sampled_relative_l2": 0.0
|
| 224 |
+
},
|
| 225 |
+
{
|
| 226 |
+
"source": "layers.2.self_attn.attention_sink_bias",
|
| 227 |
+
"gguf": "blk.2.attn_sinks.weight",
|
| 228 |
+
"type": "F32",
|
| 229 |
+
"sampled_relative_l2": 0.0
|
| 230 |
+
},
|
| 231 |
+
{
|
| 232 |
+
"source": "layers.2.self_attn.k_norm.weight",
|
| 233 |
+
"gguf": "blk.2.attn_k_norm.weight",
|
| 234 |
+
"type": "F32",
|
| 235 |
+
"sampled_relative_l2": 0.0
|
| 236 |
+
},
|
| 237 |
+
{
|
| 238 |
+
"source": "layers.2.self_attn.k_proj.weight",
|
| 239 |
+
"gguf": "blk.2.attn_k.weight",
|
| 240 |
+
"type": "Q8_0",
|
| 241 |
+
"sampled_relative_l2": 0.00555426487699151
|
| 242 |
+
},
|
| 243 |
+
{
|
| 244 |
+
"source": "layers.2.self_attn.o_proj.weight",
|
| 245 |
+
"gguf": "blk.2.attn_output.weight",
|
| 246 |
+
"type": "Q8_0",
|
| 247 |
+
"sampled_relative_l2": 0.005506662651896477
|
| 248 |
+
},
|
| 249 |
+
{
|
| 250 |
+
"source": "layers.2.self_attn.q_norm.weight",
|
| 251 |
+
"gguf": "blk.2.attn_q_norm.weight",
|
| 252 |
+
"type": "F32",
|
| 253 |
+
"sampled_relative_l2": 0.0
|
| 254 |
+
},
|
| 255 |
+
{
|
| 256 |
+
"source": "layers.2.self_attn.q_proj.weight",
|
| 257 |
+
"gguf": "blk.2.attn_q.weight",
|
| 258 |
+
"type": "Q8_0",
|
| 259 |
+
"sampled_relative_l2": 0.0055401320569217205
|
| 260 |
+
},
|
| 261 |
+
{
|
| 262 |
+
"source": "layers.2.self_attn.v_proj.weight",
|
| 263 |
+
"gguf": "blk.2.attn_v.weight",
|
| 264 |
+
"type": "Q8_0",
|
| 265 |
+
"sampled_relative_l2": 0.005393540486693382
|
| 266 |
+
},
|
| 267 |
+
{
|
| 268 |
+
"source": "layers.3.input_layernorm.weight",
|
| 269 |
+
"gguf": "blk.3.attn_norm.weight",
|
| 270 |
+
"type": "F32",
|
| 271 |
+
"sampled_relative_l2": 0.0
|
| 272 |
+
},
|
| 273 |
+
{
|
| 274 |
+
"source": "layers.3.mlp.down_proj.weight",
|
| 275 |
+
"gguf": "blk.3.ffn_down.weight",
|
| 276 |
+
"type": "Q8_0",
|
| 277 |
+
"sampled_relative_l2": 0.005636085756123066
|
| 278 |
+
},
|
| 279 |
+
{
|
| 280 |
+
"source": "layers.3.mlp.gate_proj.weight",
|
| 281 |
+
"gguf": "blk.3.ffn_gate.weight",
|
| 282 |
+
"type": "Q8_0",
|
| 283 |
+
"sampled_relative_l2": 0.005447070114314556
|
| 284 |
+
},
|
| 285 |
+
{
|
| 286 |
+
"source": "layers.3.mlp.up_proj.weight",
|
| 287 |
+
"gguf": "blk.3.ffn_up.weight",
|
| 288 |
+
"type": "Q8_0",
|
| 289 |
+
"sampled_relative_l2": 0.005448319483548403
|
| 290 |
+
},
|
| 291 |
+
{
|
| 292 |
+
"source": "layers.3.post_attention_layernorm.weight",
|
| 293 |
+
"gguf": "blk.3.ffn_norm.weight",
|
| 294 |
+
"type": "F32",
|
| 295 |
+
"sampled_relative_l2": 0.0
|
| 296 |
+
},
|
| 297 |
+
{
|
| 298 |
+
"source": "layers.3.self_attn.attention_sink_bias",
|
| 299 |
+
"gguf": "blk.3.attn_sinks.weight",
|
| 300 |
+
"type": "F32",
|
| 301 |
+
"sampled_relative_l2": 0.0
|
| 302 |
+
},
|
| 303 |
+
{
|
| 304 |
+
"source": "layers.3.self_attn.k_norm.weight",
|
| 305 |
+
"gguf": "blk.3.attn_k_norm.weight",
|
| 306 |
+
"type": "F32",
|
| 307 |
+
"sampled_relative_l2": 0.0
|
| 308 |
+
},
|
| 309 |
+
{
|
| 310 |
+
"source": "layers.3.self_attn.k_proj.weight",
|
| 311 |
+
"gguf": "blk.3.attn_k.weight",
|
| 312 |
+
"type": "Q8_0",
|
| 313 |
+
"sampled_relative_l2": 0.005607506725937128
|
| 314 |
+
},
|
| 315 |
+
{
|
| 316 |
+
"source": "layers.3.self_attn.o_proj.weight",
|
| 317 |
+
"gguf": "blk.3.attn_output.weight",
|
| 318 |
+
"type": "Q8_0",
|
| 319 |
+
"sampled_relative_l2": 0.005487577058374882
|
| 320 |
+
},
|
| 321 |
+
{
|
| 322 |
+
"source": "layers.3.self_attn.q_norm.weight",
|
| 323 |
+
"gguf": "blk.3.attn_q_norm.weight",
|
| 324 |
+
"type": "F32",
|
| 325 |
+
"sampled_relative_l2": 0.0
|
| 326 |
+
},
|
| 327 |
+
{
|
| 328 |
+
"source": "layers.3.self_attn.q_proj.weight",
|
| 329 |
+
"gguf": "blk.3.attn_q.weight",
|
| 330 |
+
"type": "Q8_0",
|
| 331 |
+
"sampled_relative_l2": 0.005722770467400551
|
| 332 |
+
},
|
| 333 |
+
{
|
| 334 |
+
"source": "layers.3.self_attn.v_proj.weight",
|
| 335 |
+
"gguf": "blk.3.attn_v.weight",
|
| 336 |
+
"type": "Q8_0",
|
| 337 |
+
"sampled_relative_l2": 0.005510271061211824
|
| 338 |
+
},
|
| 339 |
+
{
|
| 340 |
+
"source": "layers.4.input_layernorm.weight",
|
| 341 |
+
"gguf": "blk.4.attn_norm.weight",
|
| 342 |
+
"type": "F32",
|
| 343 |
+
"sampled_relative_l2": 0.0
|
| 344 |
+
},
|
| 345 |
+
{
|
| 346 |
+
"source": "layers.4.mlp.down_proj.weight",
|
| 347 |
+
"gguf": "blk.4.ffn_down.weight",
|
| 348 |
+
"type": "Q8_0",
|
| 349 |
+
"sampled_relative_l2": 0.005580178461968899
|
| 350 |
+
},
|
| 351 |
+
{
|
| 352 |
+
"source": "layers.4.mlp.gate_proj.weight",
|
| 353 |
+
"gguf": "blk.4.ffn_gate.weight",
|
| 354 |
+
"type": "Q8_0",
|
| 355 |
+
"sampled_relative_l2": 0.005537654273211956
|
| 356 |
+
},
|
| 357 |
+
{
|
| 358 |
+
"source": "layers.4.mlp.up_proj.weight",
|
| 359 |
+
"gguf": "blk.4.ffn_up.weight",
|
| 360 |
+
"type": "Q8_0",
|
| 361 |
+
"sampled_relative_l2": 0.005511666182428598
|
| 362 |
+
},
|
| 363 |
+
{
|
| 364 |
+
"source": "layers.4.post_attention_layernorm.weight",
|
| 365 |
+
"gguf": "blk.4.ffn_norm.weight",
|
| 366 |
+
"type": "F32",
|
| 367 |
+
"sampled_relative_l2": 0.0
|
| 368 |
+
},
|
| 369 |
+
{
|
| 370 |
+
"source": "layers.4.self_attn.attention_sink_bias",
|
| 371 |
+
"gguf": "blk.4.attn_sinks.weight",
|
| 372 |
+
"type": "F32",
|
| 373 |
+
"sampled_relative_l2": 0.0
|
| 374 |
+
},
|
| 375 |
+
{
|
| 376 |
+
"source": "layers.4.self_attn.k_norm.weight",
|
| 377 |
+
"gguf": "blk.4.attn_k_norm.weight",
|
| 378 |
+
"type": "F32",
|
| 379 |
+
"sampled_relative_l2": 0.0
|
| 380 |
+
},
|
| 381 |
+
{
|
| 382 |
+
"source": "layers.4.self_attn.k_proj.weight",
|
| 383 |
+
"gguf": "blk.4.attn_k.weight",
|
| 384 |
+
"type": "Q8_0",
|
| 385 |
+
"sampled_relative_l2": 0.005514967255294323
|
| 386 |
+
},
|
| 387 |
+
{
|
| 388 |
+
"source": "layers.4.self_attn.o_proj.weight",
|
| 389 |
+
"gguf": "blk.4.attn_output.weight",
|
| 390 |
+
"type": "Q8_0",
|
| 391 |
+
"sampled_relative_l2": 0.005578942131251097
|
| 392 |
+
},
|
| 393 |
+
{
|
| 394 |
+
"source": "layers.4.self_attn.q_norm.weight",
|
| 395 |
+
"gguf": "blk.4.attn_q_norm.weight",
|
| 396 |
+
"type": "F32",
|
| 397 |
+
"sampled_relative_l2": 0.0
|
| 398 |
+
},
|
| 399 |
+
{
|
| 400 |
+
"source": "layers.4.self_attn.q_proj.weight",
|
| 401 |
+
"gguf": "blk.4.attn_q.weight",
|
| 402 |
+
"type": "Q8_0",
|
| 403 |
+
"sampled_relative_l2": 0.005511818453669548
|
| 404 |
+
},
|
| 405 |
+
{
|
| 406 |
+
"source": "layers.4.self_attn.v_proj.weight",
|
| 407 |
+
"gguf": "blk.4.attn_v.weight",
|
| 408 |
+
"type": "Q8_0",
|
| 409 |
+
"sampled_relative_l2": 0.005557454191148281
|
| 410 |
+
},
|
| 411 |
+
{
|
| 412 |
+
"source": "norm.weight",
|
| 413 |
+
"gguf": "output_norm.weight",
|
| 414 |
+
"type": "F32",
|
| 415 |
+
"sampled_relative_l2": 0.0
|
| 416 |
+
}
|
| 417 |
+
],
|
| 418 |
+
"scope": "Conversion integrity; speculative decoding and acceptance rate not tested."
|
| 419 |
+
}
|
dflash/config.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"DFlashDraftModel"
|
| 4 |
+
],
|
| 5 |
+
"model_type": "qwen3",
|
| 6 |
+
"auto_map": {
|
| 7 |
+
"AutoModel": "dflash.DFlashDraftModel"
|
| 8 |
+
},
|
| 9 |
+
"hidden_size": 4096,
|
| 10 |
+
"intermediate_size": 16384,
|
| 11 |
+
"num_hidden_layers": 5,
|
| 12 |
+
"num_attention_heads": 64,
|
| 13 |
+
"num_key_value_heads": 8,
|
| 14 |
+
"head_dim": 128,
|
| 15 |
+
"v_head_dim": 128,
|
| 16 |
+
"partial_rotary_factor": 0.5,
|
| 17 |
+
"block_size": 8,
|
| 18 |
+
"dflash_config": {
|
| 19 |
+
"target_layer_ids": [
|
| 20 |
+
0,
|
| 21 |
+
11,
|
| 22 |
+
23,
|
| 23 |
+
35,
|
| 24 |
+
47
|
| 25 |
+
],
|
| 26 |
+
"mask_token_id": 151675,
|
| 27 |
+
"num_anchors": 4096,
|
| 28 |
+
"block_size": 8,
|
| 29 |
+
"loss_decay_gamma": 7.0,
|
| 30 |
+
"attention_value_scale": 0.612,
|
| 31 |
+
"attention_sink_bias": true
|
| 32 |
+
},
|
| 33 |
+
"layer_types": [
|
| 34 |
+
"sliding_attention",
|
| 35 |
+
"sliding_attention",
|
| 36 |
+
"sliding_attention",
|
| 37 |
+
"sliding_attention",
|
| 38 |
+
"sliding_attention"
|
| 39 |
+
],
|
| 40 |
+
"sliding_window": 1024,
|
| 41 |
+
"use_sliding_window": true,
|
| 42 |
+
"is_causal": false,
|
| 43 |
+
"num_target_layers": 48,
|
| 44 |
+
"target_hidden_size": 4096,
|
| 45 |
+
"vocab_size": 152576,
|
| 46 |
+
"max_position_embeddings": 1048576,
|
| 47 |
+
"rope_theta": 10000.0,
|
| 48 |
+
"rms_norm_eps": 1e-06,
|
| 49 |
+
"torch_dtype": "bfloat16",
|
| 50 |
+
"hidden_act": "silu",
|
| 51 |
+
"attention_bias": false,
|
| 52 |
+
"attention_dropout": 0.0,
|
| 53 |
+
"add_swa_attention_sink_bias": true,
|
| 54 |
+
"tie_word_embeddings": false,
|
| 55 |
+
"use_cache": true,
|
| 56 |
+
|
| 57 |
+
}
|
dflash/dflash.py
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Callable, Optional
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
from torch import nn
|
| 5 |
+
from transformers import DynamicCache
|
| 6 |
+
from transformers.cache_utils import Cache
|
| 7 |
+
from transformers.modeling_outputs import CausalLMOutputWithPast
|
| 8 |
+
from transformers.models.qwen3.modeling_qwen3 import (
|
| 9 |
+
ALL_ATTENTION_FUNCTIONS,
|
| 10 |
+
FlashAttentionKwargs,
|
| 11 |
+
GradientCheckpointingLayer,
|
| 12 |
+
Qwen3Config,
|
| 13 |
+
Qwen3MLP,
|
| 14 |
+
Qwen3PreTrainedModel,
|
| 15 |
+
Qwen3RMSNorm,
|
| 16 |
+
Qwen3RotaryEmbedding,
|
| 17 |
+
eager_attention_forward,
|
| 18 |
+
rotate_half,
|
| 19 |
+
)
|
| 20 |
+
from typing_extensions import Tuple, Unpack
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def sample(logits: torch.Tensor, temperature: float = 0.0) -> torch.Tensor:
|
| 24 |
+
if temperature < 1e-5:
|
| 25 |
+
return torch.argmax(logits, dim=-1)
|
| 26 |
+
bsz, seq_len, vocab_size = logits.shape
|
| 27 |
+
logits = logits.view(-1, vocab_size)
|
| 28 |
+
logits = logits / temperature
|
| 29 |
+
probs = torch.softmax(logits, dim=-1)
|
| 30 |
+
return torch.multinomial(probs, num_samples=1).view(bsz, seq_len)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
|
| 34 |
+
cos = cos.unsqueeze(unsqueeze_dim)
|
| 35 |
+
sin = sin.unsqueeze(unsqueeze_dim)
|
| 36 |
+
q_len = q.size(-2)
|
| 37 |
+
q_embed = (q * cos[..., -q_len:, :]) + (rotate_half(q) * sin[..., -q_len:, :])
|
| 38 |
+
k_embed = (k * cos) + (rotate_half(k) * sin)
|
| 39 |
+
return q_embed, k_embed
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class Qwen3DFlashAttention(nn.Module):
|
| 43 |
+
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
| 44 |
+
|
| 45 |
+
def __init__(self, config: Qwen3Config, layer_idx: int):
|
| 46 |
+
super().__init__()
|
| 47 |
+
self.config = config
|
| 48 |
+
self.layer_idx = layer_idx
|
| 49 |
+
self.head_dim = getattr(
|
| 50 |
+
config, "head_dim", config.hidden_size // config.num_attention_heads
|
| 51 |
+
)
|
| 52 |
+
self.num_key_value_groups = (
|
| 53 |
+
config.num_attention_heads // config.num_key_value_heads
|
| 54 |
+
)
|
| 55 |
+
self.scaling = self.head_dim**-0.5
|
| 56 |
+
self.attention_dropout = config.attention_dropout
|
| 57 |
+
self.is_causal = False
|
| 58 |
+
self.q_proj = nn.Linear(
|
| 59 |
+
config.hidden_size,
|
| 60 |
+
config.num_attention_heads * self.head_dim,
|
| 61 |
+
bias=config.attention_bias,
|
| 62 |
+
)
|
| 63 |
+
self.k_proj = nn.Linear(
|
| 64 |
+
config.hidden_size,
|
| 65 |
+
config.num_key_value_heads * self.head_dim,
|
| 66 |
+
bias=config.attention_bias,
|
| 67 |
+
)
|
| 68 |
+
self.v_proj = nn.Linear(
|
| 69 |
+
config.hidden_size,
|
| 70 |
+
config.num_key_value_heads * self.head_dim,
|
| 71 |
+
bias=config.attention_bias,
|
| 72 |
+
)
|
| 73 |
+
self.o_proj = nn.Linear(
|
| 74 |
+
config.num_attention_heads * self.head_dim,
|
| 75 |
+
config.hidden_size,
|
| 76 |
+
bias=config.attention_bias,
|
| 77 |
+
)
|
| 78 |
+
self.q_norm = Qwen3RMSNorm(self.head_dim, eps=config.rms_norm_eps)
|
| 79 |
+
self.k_norm = Qwen3RMSNorm(self.head_dim, eps=config.rms_norm_eps)
|
| 80 |
+
self.sliding_window = (
|
| 81 |
+
config.sliding_window
|
| 82 |
+
if config.layer_types[layer_idx] == "sliding_attention"
|
| 83 |
+
else None
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
def forward(
|
| 87 |
+
self,
|
| 88 |
+
hidden_states: torch.Tensor,
|
| 89 |
+
target_hidden: torch.Tensor,
|
| 90 |
+
position_embeddings: tuple[torch.Tensor, torch.Tensor],
|
| 91 |
+
attention_mask: Optional[torch.Tensor],
|
| 92 |
+
past_key_values: Optional[Cache] = None,
|
| 93 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 94 |
+
**kwargs: Unpack[FlashAttentionKwargs],
|
| 95 |
+
) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
|
| 96 |
+
bsz, q_len = hidden_states.shape[:-1]
|
| 97 |
+
ctx_len = target_hidden.shape[1]
|
| 98 |
+
q = self.q_proj(hidden_states)
|
| 99 |
+
q = q.view(bsz, q_len, -1, self.head_dim)
|
| 100 |
+
q = self.q_norm(q).transpose(1, 2)
|
| 101 |
+
k_ctx = self.k_proj(target_hidden)
|
| 102 |
+
k_noise = self.k_proj(hidden_states)
|
| 103 |
+
v_ctx = self.v_proj(target_hidden)
|
| 104 |
+
v_noise = self.v_proj(hidden_states)
|
| 105 |
+
k = torch.cat([k_ctx, k_noise], dim=1).view(
|
| 106 |
+
bsz, ctx_len + q_len, -1, self.head_dim
|
| 107 |
+
)
|
| 108 |
+
v = torch.cat([v_ctx, v_noise], dim=1).view(
|
| 109 |
+
bsz, ctx_len + q_len, -1, self.head_dim
|
| 110 |
+
)
|
| 111 |
+
k = self.k_norm(k).transpose(1, 2)
|
| 112 |
+
v = v.transpose(1, 2)
|
| 113 |
+
cos, sin = position_embeddings
|
| 114 |
+
q, k = apply_rotary_pos_emb(q, k, cos, sin)
|
| 115 |
+
if past_key_values is not None:
|
| 116 |
+
cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
|
| 117 |
+
k, v = past_key_values.update(k, v, self.layer_idx, cache_kwargs)
|
| 118 |
+
attn_fn: Callable = eager_attention_forward
|
| 119 |
+
if self.config._attn_implementation != "eager":
|
| 120 |
+
attn_fn = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation]
|
| 121 |
+
attn_output, attn_weights = attn_fn(
|
| 122 |
+
self,
|
| 123 |
+
q,
|
| 124 |
+
k,
|
| 125 |
+
v,
|
| 126 |
+
attention_mask,
|
| 127 |
+
dropout=0.0 if not self.training else self.attention_dropout,
|
| 128 |
+
scaling=self.scaling,
|
| 129 |
+
sliding_window=self.sliding_window,
|
| 130 |
+
**kwargs,
|
| 131 |
+
)
|
| 132 |
+
attn_output = attn_output.reshape(bsz, q_len, -1)
|
| 133 |
+
attn_output = self.o_proj(attn_output)
|
| 134 |
+
return attn_output, attn_weights
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
class Qwen3DFlashDecoderLayer(GradientCheckpointingLayer):
|
| 138 |
+
def __init__(self, config: Qwen3Config, layer_idx: int):
|
| 139 |
+
super().__init__()
|
| 140 |
+
self.hidden_size = config.hidden_size
|
| 141 |
+
self.self_attn = Qwen3DFlashAttention(config=config, layer_idx=layer_idx)
|
| 142 |
+
self.mlp = Qwen3MLP(config)
|
| 143 |
+
self.input_layernorm = Qwen3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 144 |
+
self.post_attention_layernorm = Qwen3RMSNorm(
|
| 145 |
+
config.hidden_size, eps=config.rms_norm_eps
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
def forward(
|
| 149 |
+
self,
|
| 150 |
+
target_hidden: Optional[torch.Tensor] = None,
|
| 151 |
+
hidden_states: Optional[torch.Tensor] = None,
|
| 152 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 153 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 154 |
+
past_key_value: Optional[Cache] = None,
|
| 155 |
+
output_attentions: Optional[bool] = False,
|
| 156 |
+
use_cache: Optional[bool] = False,
|
| 157 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 158 |
+
position_embeddings: Optional[
|
| 159 |
+
Tuple[torch.Tensor, torch.Tensor]
|
| 160 |
+
] = None, # necessary, but kept here for BC
|
| 161 |
+
**kwargs: Unpack[FlashAttentionKwargs],
|
| 162 |
+
) -> Tuple[
|
| 163 |
+
torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]
|
| 164 |
+
]:
|
| 165 |
+
residual = hidden_states
|
| 166 |
+
hidden_states = self.input_layernorm(hidden_states)
|
| 167 |
+
hidden_states = self.self_attn(
|
| 168 |
+
hidden_states=hidden_states,
|
| 169 |
+
target_hidden=target_hidden,
|
| 170 |
+
attention_mask=attention_mask,
|
| 171 |
+
position_ids=position_ids,
|
| 172 |
+
past_key_values=past_key_value,
|
| 173 |
+
output_attentions=output_attentions,
|
| 174 |
+
use_cache=use_cache,
|
| 175 |
+
cache_position=cache_position,
|
| 176 |
+
position_embeddings=position_embeddings,
|
| 177 |
+
**kwargs,
|
| 178 |
+
)[0]
|
| 179 |
+
hidden_states = residual + hidden_states
|
| 180 |
+
residual = hidden_states
|
| 181 |
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
| 182 |
+
hidden_states = self.mlp(hidden_states)
|
| 183 |
+
hidden_states = residual + hidden_states
|
| 184 |
+
return hidden_states
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def build_target_layer_ids(num_target_layers: int, num_draft_layers: int):
|
| 188 |
+
if num_draft_layers == 1:
|
| 189 |
+
return [(num_target_layers // 2)]
|
| 190 |
+
start = 1
|
| 191 |
+
end = num_target_layers - 3
|
| 192 |
+
span = end - start
|
| 193 |
+
target_layer_ids = [
|
| 194 |
+
int(round(start + (i * span) / (num_draft_layers - 1)))
|
| 195 |
+
for i in range(num_draft_layers)
|
| 196 |
+
]
|
| 197 |
+
return target_layer_ids
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def extract_context_feature(
|
| 201 |
+
hidden_states: list[torch.Tensor],
|
| 202 |
+
layer_ids: Optional[list[int]],
|
| 203 |
+
) -> torch.Tensor:
|
| 204 |
+
offset = 1
|
| 205 |
+
selected_states = []
|
| 206 |
+
for layer_id in layer_ids:
|
| 207 |
+
selected_states.append(hidden_states[layer_id + offset])
|
| 208 |
+
target_hidden = torch.cat(selected_states, dim=-1)
|
| 209 |
+
return target_hidden
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
class DFlashDraftModel(Qwen3PreTrainedModel):
|
| 213 |
+
config_class = Qwen3Config
|
| 214 |
+
_no_split_modules = ["Qwen3DFlashDecoderLayer"]
|
| 215 |
+
|
| 216 |
+
def __init__(self, config) -> None:
|
| 217 |
+
super().__init__(config)
|
| 218 |
+
self.config = config
|
| 219 |
+
self.layers = nn.ModuleList(
|
| 220 |
+
[
|
| 221 |
+
Qwen3DFlashDecoderLayer(config, layer_idx)
|
| 222 |
+
for layer_idx in range(config.num_hidden_layers)
|
| 223 |
+
]
|
| 224 |
+
)
|
| 225 |
+
dflash_config = getattr(config, "dflash_config", {}) or {}
|
| 226 |
+
self.target_layer_ids = dflash_config.get(
|
| 227 |
+
"target_layer_ids",
|
| 228 |
+
build_target_layer_ids(config.num_target_layers, config.num_hidden_layers),
|
| 229 |
+
)
|
| 230 |
+
self.norm = Qwen3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 231 |
+
self.rotary_emb = Qwen3RotaryEmbedding(config)
|
| 232 |
+
self.fc = nn.Linear(
|
| 233 |
+
len(self.target_layer_ids) * config.hidden_size,
|
| 234 |
+
config.hidden_size,
|
| 235 |
+
bias=False,
|
| 236 |
+
)
|
| 237 |
+
self.hidden_norm = Qwen3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 238 |
+
self.block_size = config.block_size
|
| 239 |
+
self.mask_token_id = dflash_config.get("mask_token_id", None)
|
| 240 |
+
self.post_init()
|
| 241 |
+
|
| 242 |
+
def forward(
|
| 243 |
+
self,
|
| 244 |
+
position_ids: torch.LongTensor,
|
| 245 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 246 |
+
noise_embedding: Optional[torch.Tensor] = None,
|
| 247 |
+
target_hidden: Optional[torch.Tensor] = None,
|
| 248 |
+
past_key_values: Optional[Cache] = None,
|
| 249 |
+
use_cache: bool = False,
|
| 250 |
+
**kwargs,
|
| 251 |
+
) -> CausalLMOutputWithPast:
|
| 252 |
+
hidden_states = noise_embedding
|
| 253 |
+
target_hidden = self.hidden_norm(self.fc(target_hidden))
|
| 254 |
+
position_embeddings = self.rotary_emb(hidden_states, position_ids)
|
| 255 |
+
for layer in self.layers:
|
| 256 |
+
hidden_states = layer(
|
| 257 |
+
hidden_states=hidden_states,
|
| 258 |
+
target_hidden=target_hidden,
|
| 259 |
+
attention_mask=attention_mask,
|
| 260 |
+
position_ids=position_ids,
|
| 261 |
+
past_key_value=past_key_values,
|
| 262 |
+
use_cache=use_cache,
|
| 263 |
+
position_embeddings=position_embeddings,
|
| 264 |
+
**kwargs,
|
| 265 |
+
)
|
| 266 |
+
return self.norm(hidden_states)
|
| 267 |
+
|
| 268 |
+
@torch.inference_mode()
|
| 269 |
+
def spec_generate(
|
| 270 |
+
self,
|
| 271 |
+
target: nn.Module,
|
| 272 |
+
input_ids: torch.LongTensor,
|
| 273 |
+
max_new_tokens: int,
|
| 274 |
+
stop_token_ids: list[int],
|
| 275 |
+
temperature: float,
|
| 276 |
+
):
|
| 277 |
+
self.eval()
|
| 278 |
+
num_input_tokens = input_ids.shape[1]
|
| 279 |
+
max_length = num_input_tokens + max_new_tokens
|
| 280 |
+
|
| 281 |
+
block_size = self.block_size
|
| 282 |
+
output_ids = torch.full(
|
| 283 |
+
(1, max_length + block_size),
|
| 284 |
+
self.mask_token_id,
|
| 285 |
+
dtype=torch.long,
|
| 286 |
+
device=target.device,
|
| 287 |
+
)
|
| 288 |
+
position_ids = torch.arange(
|
| 289 |
+
output_ids.shape[1], device=target.device
|
| 290 |
+
).unsqueeze(0)
|
| 291 |
+
|
| 292 |
+
past_key_values_target = DynamicCache()
|
| 293 |
+
past_key_values_draft = DynamicCache()
|
| 294 |
+
|
| 295 |
+
# Prefill stage
|
| 296 |
+
output = target(
|
| 297 |
+
input_ids,
|
| 298 |
+
position_ids=position_ids[:, :num_input_tokens],
|
| 299 |
+
past_key_values=past_key_values_target,
|
| 300 |
+
use_cache=True,
|
| 301 |
+
logits_to_keep=1,
|
| 302 |
+
output_hidden_states=True,
|
| 303 |
+
)
|
| 304 |
+
|
| 305 |
+
output_ids[:, :num_input_tokens] = input_ids
|
| 306 |
+
output_ids[:, num_input_tokens : num_input_tokens + 1] = sample(
|
| 307 |
+
output.logits, temperature
|
| 308 |
+
)
|
| 309 |
+
target_hidden = extract_context_feature(
|
| 310 |
+
output.hidden_states, self.target_layer_ids
|
| 311 |
+
)
|
| 312 |
+
|
| 313 |
+
# Decode stage
|
| 314 |
+
acceptance_lengths = []
|
| 315 |
+
start = input_ids.shape[1]
|
| 316 |
+
while start < max_length:
|
| 317 |
+
block_output_ids = output_ids[:, start : start + block_size].clone()
|
| 318 |
+
block_position_ids = position_ids[:, start : start + block_size]
|
| 319 |
+
noise_embedding = target.model.embed_tokens(block_output_ids)
|
| 320 |
+
draft_logits = target.lm_head(
|
| 321 |
+
self(
|
| 322 |
+
target_hidden=target_hidden,
|
| 323 |
+
noise_embedding=noise_embedding,
|
| 324 |
+
position_ids=position_ids[
|
| 325 |
+
:, past_key_values_draft.get_seq_length() : start + block_size
|
| 326 |
+
],
|
| 327 |
+
past_key_values=past_key_values_draft,
|
| 328 |
+
use_cache=True,
|
| 329 |
+
is_causal=False,
|
| 330 |
+
)[:, -block_size + 1 :, :]
|
| 331 |
+
)
|
| 332 |
+
past_key_values_draft.crop(start)
|
| 333 |
+
block_output_ids[:, 1:] = sample(draft_logits)
|
| 334 |
+
|
| 335 |
+
output = target(
|
| 336 |
+
block_output_ids,
|
| 337 |
+
position_ids=block_position_ids,
|
| 338 |
+
past_key_values=past_key_values_target,
|
| 339 |
+
use_cache=True,
|
| 340 |
+
output_hidden_states=True,
|
| 341 |
+
)
|
| 342 |
+
|
| 343 |
+
posterior = sample(output.logits, temperature)
|
| 344 |
+
acceptance_length = (
|
| 345 |
+
(block_output_ids[:, 1:] == posterior[:, :-1])
|
| 346 |
+
.cumprod(dim=1)
|
| 347 |
+
.sum(dim=1)[0]
|
| 348 |
+
.item()
|
| 349 |
+
)
|
| 350 |
+
output_ids[:, start : start + acceptance_length + 1] = block_output_ids[
|
| 351 |
+
:, : acceptance_length + 1
|
| 352 |
+
]
|
| 353 |
+
output_ids[:, start + acceptance_length + 1] = posterior[
|
| 354 |
+
:, acceptance_length
|
| 355 |
+
]
|
| 356 |
+
start += acceptance_length + 1
|
| 357 |
+
past_key_values_target.crop(start)
|
| 358 |
+
target_hidden = extract_context_feature(
|
| 359 |
+
output.hidden_states, self.target_layer_ids
|
| 360 |
+
)[:, : acceptance_length + 1, :]
|
| 361 |
+
acceptance_lengths.append(acceptance_length + 1)
|
| 362 |
+
if stop_token_ids is not None and any(
|
| 363 |
+
stop_token_id in output_ids[:, num_input_tokens:]
|
| 364 |
+
for stop_token_id in stop_token_ids
|
| 365 |
+
):
|
| 366 |
+
break
|
| 367 |
+
output_ids = output_ids[:, :max_length]
|
| 368 |
+
output_ids = output_ids[:, output_ids[0] != self.mask_token_id]
|
| 369 |
+
if stop_token_ids is not None:
|
| 370 |
+
stop_token_ids = torch.tensor(stop_token_ids, device=output_ids.device)
|
| 371 |
+
stop_token_indices = torch.isin(
|
| 372 |
+
output_ids[0][num_input_tokens:], stop_token_ids
|
| 373 |
+
).nonzero(as_tuple=True)[0]
|
| 374 |
+
if stop_token_indices.numel() > 0:
|
| 375 |
+
output_ids = output_ids[
|
| 376 |
+
:, : num_input_tokens + stop_token_indices[0] + 1
|
| 377 |
+
]
|
| 378 |
+
|
| 379 |
+
return output_ids
|
dflash/mask_embedding.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b35b379fe0497ffdc0d6407f502622237d9346e0d03f457ec574be60f6c2cee0
|
| 3 |
+
size 9882
|
dflash/runtime-contract.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"source_revision": "3b38d063180c3e4aed9691fdc735f3d10b266ee4",
|
| 3 |
+
"gguf": "MiMo-V2.6-Flash-RL-DFlash-Q8_0.gguf",
|
| 4 |
+
"embedded_mtp_is_separate": true,
|
| 5 |
+
"block_count": 5,
|
| 6 |
+
"block_size": 8,
|
| 7 |
+
"mask_token_id": 151675,
|
| 8 |
+
"mask_embedding_file": "mask_embedding.pt",
|
| 9 |
+
"source_target_layer_ids": [
|
| 10 |
+
0,
|
| 11 |
+
11,
|
| 12 |
+
23,
|
| 13 |
+
35,
|
| 14 |
+
47
|
| 15 |
+
],
|
| 16 |
+
"gguf_hidden_state_indices": [
|
| 17 |
+
1,
|
| 18 |
+
12,
|
| 19 |
+
24,
|
| 20 |
+
36,
|
| 21 |
+
48
|
| 22 |
+
],
|
| 23 |
+
"partial_rotary_factor": 0.5,
|
| 24 |
+
"rotary_dimensions": 64,
|
| 25 |
+
"head_dimensions": 128,
|
| 26 |
+
"attention_value_scale": 0.612,
|
| 27 |
+
"attention_sinks": true,
|
| 28 |
+
"is_causal": false,
|
| 29 |
+
"sliding_window": 1024,
|
| 30 |
+
"config_note": "Original config retained byte for byte, including its trailing comma; normalized JSON used only in conversion staging.",
|
| 31 |
+
"runtime_status": "Deferred; no validated acceptance rate or ds4 support claimed.",
|
| 32 |
+
"source_python_note": "Bundled HF example does not implement all MiMo-specific draft behavior; use production SGLang draft implementation and the checkpoint config as integration references.",
|
| 33 |
+
"files": {
|
| 34 |
+
"config.json": "29f18def0d74535771b2364b28107f4914ebb88872abb93189012f7573e10e4b",
|
| 35 |
+
"mask_embedding.pt": "b35b379fe0497ffdc0d6407f502622237d9346e0d03f457ec574be60f6c2cee0",
|
| 36 |
+
"dflash.py": "da5ab1738b954800950405131f1d1d97c3345f37e32676d511d3a25dfddd9d75"
|
| 37 |
+
}
|
| 38 |
+
}
|
mmproj-MiMo-V2.6-Flash-RL-BF16.gguf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:333af1e9f86c4c4be2305c655a9a4fe7684a68e127d513832b8ea27cd89408d6
|
| 3 |
+
size 2748509792
|
toolchain-pins.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"llama.cpp": "58367713a6935c0810103378144008df32e3d5db",
|
| 3 |
+
"ds4-dfm-rs": "d9fa8b65d3cdb505e6fa9060cb9a327bc3b0d432",
|
| 4 |
+
"source": "3b38d063180c3e4aed9691fdc735f3d10b266ee4"
|
| 5 |
+
}
|
vision-parity-fp32.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"native_compute_dtype": "float32",
|
| 3 |
+
"shape": [
|
| 4 |
+
88,
|
| 5 |
+
4096
|
| 6 |
+
],
|
| 7 |
+
"cosine": 0.999983453167901,
|
| 8 |
+
"relative_l2": 0.005762081450217797,
|
| 9 |
+
"max_abs": 0.029657483100891113,
|
| 10 |
+
"native_rms": 0.0693792951089455,
|
| 11 |
+
"gguf_rms": 0.06940096774910624,
|
| 12 |
+
"scope": "One real still image; identical production-normalized pixels; BF16 PyTorch versus converted GGUF. Video and audio require separate checks."
|
| 13 |
+
}
|
vision-parity.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"shape": [
|
| 3 |
+
88,
|
| 4 |
+
4096
|
| 5 |
+
],
|
| 6 |
+
"cosine": 0.9974313942728767,
|
| 7 |
+
"relative_l2": 0.07171386073721285,
|
| 8 |
+
"max_abs": 0.45852723717689514,
|
| 9 |
+
"native_rms": 0.06933624871181736,
|
| 10 |
+
"gguf_rms": 0.06940096774910624,
|
| 11 |
+
"scope": "One real still image; identical production-normalized pixels; BF16 PyTorch versus converted GGUF. Video and audio require separate checks."
|
| 12 |
+
}
|