Text Generation
Diffusers
English
diffusion
flow-matching
rectified-flow
reasoning
qwen2.5
block-diffusion
non-autoregressive
Instructions to use tahamajs/BlockDiffuse with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use tahamajs/BlockDiffuse with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("tahamajs/BlockDiffuse", dtype=torch.bfloat16, device_map="cuda") prompt = "Hi, what can you help me with?" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -3,7 +3,6 @@ license: apache-2.0
|
|
| 3 |
tags:
|
| 4 |
- diffusion
|
| 5 |
- flow-matching
|
| 6 |
-
- rectified-flow
|
| 7 |
- text-generation
|
| 8 |
- reasoning
|
| 9 |
- qwen2.5
|
|
@@ -13,47 +12,71 @@ language:
|
|
| 13 |
- en
|
| 14 |
---
|
| 15 |
|
| 16 |
-
# BlockDiffuse: Parallel
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
By
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
| Mode |
|
| 34 |
| :--- | :--- | :--- | :--- | :--- |
|
| 35 |
-
| **Single-Block Parallel** | 100 tokens | 8 ODE steps
|
| 36 |
-
| **Multi-Block
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
## Quickstart & Inference
|
| 39 |
|
| 40 |
-
|
| 41 |
|
| 42 |
```bash
|
|
|
|
| 43 |
git clone https://github.com/Hooshaai/BlockDiffuse.git
|
| 44 |
cd BlockDiffuse
|
| 45 |
|
|
|
|
| 46 |
python inference.py \
|
| 47 |
--model Qwen/Qwen2.5-0.5B-Instruct \
|
| 48 |
-
--checkpoint ./blockdiffuse_final.pt \
|
| 49 |
-
--prompt "<|im_start|>system\nYou are a helpful assistant that solves problems step by step.<|im_end|>\n<|im_start|>user\
|
|
|
|
| 50 |
--steps 8 \
|
| 51 |
--solver dpm_solver \
|
| 52 |
-
--use_tfe
|
| 53 |
-
--tfe_seeds 3
|
| 54 |
```
|
| 55 |
|
| 56 |
-
## Citation
|
| 57 |
|
| 58 |
```bibtex
|
| 59 |
@software{blockdiffuse2026,
|
|
|
|
| 3 |
tags:
|
| 4 |
- diffusion
|
| 5 |
- flow-matching
|
|
|
|
| 6 |
- text-generation
|
| 7 |
- reasoning
|
| 8 |
- qwen2.5
|
|
|
|
| 12 |
- en
|
| 13 |
---
|
| 14 |
|
| 15 |
+
# 🚀 BlockDiffuse: Fully Parallel Latent Space Reasoning Generation
|
| 16 |
|
| 17 |
+
<div align="center">
|
| 18 |
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/text-generation.png" alt="Text Generation" width="400"/>
|
| 19 |
+
</div>
|
| 20 |
+
<br/>
|
| 21 |
|
| 22 |
+
> **TL;DR:** BlockDiffuse is a novel generative framework that bypasses the autoregressive token-by-token bottleneck of LLMs. By combining a **Diffusion Transformer (DiT)** with **Rectified Flow Matching** and a frozen Qwen2.5-0.5B-Instruct, it generates **100-token blocks in parallel** in continuous latent space, achieving over **150 tokens/sec** on a laptop GPU!
|
| 23 |
|
| 24 |
+
---
|
| 25 |
+
|
| 26 |
+
## 📖 The Problem: The Autoregressive Bottleneck
|
| 27 |
+
|
| 28 |
+
Traditional Large Language Models (LLMs) generate text autoregressively—one token at a time. While highly effective, this creates a severe latency bottleneck, especially for complex reasoning tasks (like math or coding) that require long "chain-of-thought" sequences before arriving at an answer. Because the model must perform a full forward pass for *every single token*, latency scales linearly with the sequence length.
|
| 29 |
+
|
| 30 |
+
## 💡 The Solution: BlockDiffuse
|
| 31 |
+
|
| 32 |
+
What if we could generate an entire paragraph of thoughts at once?
|
| 33 |
+
|
| 34 |
+
**BlockDiffuse** shifts text generation from discrete token classification to **continuous continuous latent space trajectory modeling**.
|
| 35 |
+
We map sequences of 100 discrete tokens into a continuous embedding space using the deep layers of a pre-trained LLM. Then, a DiT learns to denoise pure Gaussian noise into these 100-token latent representations simultaneously.
|
| 36 |
|
| 37 |
+
### 🏗️ Architecture Deep Dive
|
| 38 |
+
1. **Base LLM:** `Qwen/Qwen2.5-0.5B-Instruct` (Frozen). We use the first 12 layers for processing the prompt and the final language modeling head for decoding latents back to text.
|
| 39 |
+
2. **Diffusion Transformer (DiT):** An 8-layer, 14-head ($d_\text{model}=896$) transformer initialized via transfer learning from Qwen's intermediate layers.
|
| 40 |
+
3. **Deep Projection Head:** A 3-layer MLP residual adapter that perfectly bridges the gap between the diffusion output space and the discrete token space.
|
| 41 |
+
4. **Flow Matching:** Instead of standard DDPM, we use **Rectified Flow Matching** with an ODE solver (DPM-Solver) allowing for ultra-fast generation in just 8 steps.
|
| 42 |
+
5. **Loss Objectives:** A sophisticated multi-objective setup combining Velocity MSE ($\mathcal{L}_\text{FM}$), Teacher KL Distillation, Discrete Token Cross-Entropy ($\mathcal{L}_\text{CE}$), and Contrastive InfoNCE ($\mathcal{L}_\text{NN}$).
|
| 43 |
|
| 44 |
+
---
|
| 45 |
+
|
| 46 |
+
## ⚡ Benchmark Results (RTX 4070 Laptop 8GB)
|
| 47 |
+
|
| 48 |
+
BlockDiffuse achieves remarkable throughput by solving the ODE block-by-block instead of token-by-token.
|
| 49 |
|
| 50 |
+
| Mode | Generation Size | Diffusion Steps | Latency | Throughput |
|
| 51 |
| :--- | :--- | :--- | :--- | :--- |
|
| 52 |
+
| **Single-Block Parallel** | 100 tokens | 8 ODE steps | **1.73 seconds** | **57.78 tokens/sec** |
|
| 53 |
+
| **Multi-Block Reasoning** | 200 tokens (2 blocks) | 8 ODE steps / block | **1.27 seconds** | **156.35 tokens/sec** |
|
| 54 |
+
|
| 55 |
+
*(Using DPM-Solver with Training-Free Ensemble (TFE) k=3 seeds)*
|
| 56 |
+
|
| 57 |
+
---
|
| 58 |
|
| 59 |
+
## 💻 Quickstart & Inference
|
| 60 |
|
| 61 |
+
Want to run this yourself? Clone the official repository and use our inference script!
|
| 62 |
|
| 63 |
```bash
|
| 64 |
+
# 1. Clone the repository
|
| 65 |
git clone https://github.com/Hooshaai/BlockDiffuse.git
|
| 66 |
cd BlockDiffuse
|
| 67 |
|
| 68 |
+
# 2. Run parallel multi-block reasoning
|
| 69 |
python inference.py \
|
| 70 |
--model Qwen/Qwen2.5-0.5B-Instruct \
|
| 71 |
+
--checkpoint ./checkpoints_improved/blockdiffuse_final.pt \
|
| 72 |
+
--prompt "<|im_start|>system\nYou are a helpful assistant that solves problems step by step.<|im_end|>\n<|im_start|>user\nJanet has 3 bags of 10 apples. She gives 5 apples to her friend and eats 2. How many apples does she have left?<|im_end|>\n<|im_start|>assistant\n" \
|
| 73 |
+
--max_blocks 2 \
|
| 74 |
--steps 8 \
|
| 75 |
--solver dpm_solver \
|
| 76 |
+
--use_tfe
|
|
|
|
| 77 |
```
|
| 78 |
|
| 79 |
+
## 📝 Citation
|
| 80 |
|
| 81 |
```bibtex
|
| 82 |
@software{blockdiffuse2026,
|