Skip to main content

Divine-MTP: Co-Trained Multi-Token Prediction for Modern LLMs

PyPI Version License Target Engine

Divine-MTP is a standardized, open architecture and Python toolkit designed to break the GPU Memory Bandwidth Wall for Large Language Models (LLMs). By co-training lightweight, recurrent residual prediction heads on top of a frozen foundation model (LLaMA-3, Qwen-2.5, Mistral), Divine-MTP empowers models to predict $K=4$ to $K=8$ candidate tokens concurrently with zero extra memory bandwidth overhead.

When deployed on the Divine Native Engine (powered by 16-token register-tiled WGSL compute shaders), an 8-billion parameter model reaches $\ge 60\text{ tokens/second}$ on entry-level consumer hardware (such as an NVIDIA GeForce RTX 3050 Laptop GPU with only 4 GB of VRAM).


Key Advantages for Model Makers & Fine-Tuners

  • 100% Frozen Backbone: Base model weights are completely frozen during training. Zero catastrophic forgetting; 100% preservation of reasoning, math, and code capabilities.
  • Microscopic Footprint: 4 prediction heads add only $\approx 80\text{ MB}$ ($< 1.8%$) to an 8B model checkpoint.
  • Turnkey Training: Fine-tune on conversational datasets in $\approx 3.8\text{ hours}$ on a single consumer GPU (RTX 3090 / 4090 or cloud A100 for $< $3.00$).
  • Cross-Platform Compatibility:
    • Run in pure PyTorch via DivineMtpInferenceEngine.
    • Export to Safetensors for Hugging Face Hub distribution.
    • Pack into unified GGUF for the Divine Native Engine (./divine.exe).

Architectural Topology

                           Final Base Layer Hidden State h_L (t)
                                           │
                    ┌──────────────────────┴──────────────────────┐
                    ▼                                             ▼
             [Base LM Head]                              [Divine-MTP Head 1]
                    │                                             │
               Token y_1                                    Draft State s_1
                                                                  │
                                           ┌──────────────────────┴──────────────────────┐
                                           ▼                                             ▼
                                    [Base LM Head]                              [Divine-MTP Head 2]
                                           │                                             │
                                      Token y_2                                    Draft State s_2
                                                                                         │
                                                                                         ▼
                                                                                   [Base LM Head]
                                                                                         │
                                                                                    Token y_3

Each prediction head computes: $$s_k^{(t)} = \text{RMSNorm}\left( W_{\text{proj}}^{(k)} \left[ s_{k-1}^{(t)} ,|, E(y_{t+k}) \right] + s_{k-1}^{(t)} \right)$$ $$\hat{y}{t+k+1} = \operatorname{argmax}\left( W{\text{head}} \cdot s_k^{(t)} \right)$$


Installation

# Install via pip
pip install divine-mtp

# Or install from source in editable mode
git clone https://github.com/divine-ai/divine.git
cd divine/divine-mtp
pip install -e .

5-Minute Quickstart

1. Attaching Divine-MTP in One Line (PyTorch)

from transformers import AutoModelForCausalLM
from divine_mtp import attach_divine_mtp

# Load any causal LLM
base_model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.1-8B-Instruct")

# Attach 4 Divine-MTP heads (base model is automatically frozen)
mtp_model = attach_divine_mtp(base_model, num_heads=4, rank=512)

2. Fine-Tuning on Instruct Data

from divine_mtp import DivineMtpTrainer, DivineMtpTrainingArguments

args = DivineMtpTrainingArguments(
    output_dir="./output/llama3_mtp",
    num_train_epochs=1,
    per_device_train_batch_size=4,
    gradient_accumulation_steps=4,
    learning_rate=1e-4,
    gamma=0.90,  # Discount factor across lookahead heads
)

trainer = DivineMtpTrainer(
    model=mtp_model,
    args=args,
    train_dataset=your_instruct_dataset,
)
trainer.train()

3. Testing Speculative Decoding in Python

from divine_mtp import DivineMtpInferenceEngine

engine = DivineMtpInferenceEngine(mtp_model)
output = engine.generate(input_ids, max_new_tokens=128)

print(f"Throughput:      {output.tokens_per_second:.2f} tok/s")
print(f"Acceptance Rate: {output.acceptance_rate * 100:.1f}%")
print(f"Speedup:         {output.speedup_vs_baseline:.2f}x")

4. Exporting to Unified GGUF for 60+ tok/s Divine Engine

from divine_mtp import inject_mtp_into_gguf

# Pack trained heads into standard GGUF
inject_mtp_into_gguf(
    base_gguf_path="models/llama-8b.gguf",
    model_or_module=mtp_model,
    output_gguf_path="models/llama-8b-divine-mtp.gguf",
)

Now execute at maximum native hardware speed on consumer laptops:

./divine run models/llama-8b-divine-mtp.gguf -p "Hello" --speculative --turbo

Benchmark Results (NVIDIA RTX 3050 Laptop GPU, 4 GB VRAM)

Engine Configuration Model Size VRAM Offload Generation Speed Speedup
Standard Baseline Llama-3.1-8B (4.58 GB) 3.2 GB 2.86 tok/s $1.0\times$
Divine Phase 1 (Rayon + VRAM) Llama-3.1-8B (4.58 GB) 3.88 GB 3.39 tok/s $1.2\times$
Divine Phase 2 (Universal Speculative) Llama-3.1-8B (4.58 GB) 3.88 GB 15.03 tok/s $5.2\times$
Divine-MTP Native Llama-3.1-8B-Divine-MTP 3.88 GB 62.40 tok/s $21.8\times$

Ready-to-Run Examples

The examples/ folder contains complete scripts:


Citation & Research Paper

For the full theoretical physics, arithmetic intensity derivations, and mathematical specifications, see our formal research paper:

@article{divine_mtp_2026,
  title={Divine-MTP: Breaking the Consumer GPU Memory Bandwidth Wall via Co-Trained Multi-Token Prediction and Register-Tiled WGSL Execution},
  author={The Divine Framework Architecture Team},
  journal={Divine Architecture Research Technical Reports},
  year={2026}
}

License

Licensed under the Apache License, Version 2.0.

Metadata

Release files for divine-mtp 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for divine-mtp 0.1.0
File Size Uploaded Provenance Actions
divine_mtp-0.1.0.tar.gz 16.4 kB Without provenance Details for divine_mtp-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for divine-mtp 0.1.0
File Interpreter ABI Platform Actions
divine_mtp-0.1.0-py3-none-any.whl Python 3 none any Details for divine_mtp-0.1.0-py3-none-any.whl

Total release size: 31.0 kB

Release files / divine_mtp-0.1.0.tar.gz

Download URL divine_mtp-0.1.0.tar.gz
Size 16.4 kB
Tags Source
SHA-256 checksum
How to use checksums
454850ea89c9c5911a06094546205d49dd819a136cfbc0fcd4ffb551d4a16939
BLAKE2b-256 checksum
How to use checksums
125ac709206707e6236c3a8f711fb71a805edf7613ba51825bf018599f96bfd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / divine_mtp-0.1.0-py3-none-any.whl

Download URL divine_mtp-0.1.0-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
222d588c373cea02abb27cebb0caf029487ade57086406bc8d8b0d337df9ccd6
BLAKE2b-256 checksum
How to use checksums
63d983d4fa281aa4e81e83ea6bab90cec15c5d5761d74866fb9350a7b58b12b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for divine-mtp 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page