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
|
@@ -1,88 +1,130 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
tags:
|
| 4 |
-
- diffusion
|
| 5 |
-
- flow-matching
|
| 6 |
-
-
|
| 7 |
-
-
|
| 8 |
-
-
|
| 9 |
-
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
```
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
tags:
|
| 4 |
+
- diffusion
|
| 5 |
+
- flow-matching
|
| 6 |
+
- rectified-flow
|
| 7 |
+
- text-generation
|
| 8 |
+
- reasoning
|
| 9 |
+
- qwen2.5
|
| 10 |
+
- block-diffusion
|
| 11 |
+
- non-autoregressive
|
| 12 |
+
pipeline_tag: text-generation
|
| 13 |
+
language:
|
| 14 |
+
- en
|
| 15 |
+
library_name: diffusers
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# π BlockDiffuse: Fully Parallel Latent Space Reasoning Generation
|
| 19 |
+
|
| 20 |
+
[](https://opensource.org/licenses/Apache-2.0)
|
| 21 |
+
[](https://github.com/Hooshaai/BlockDiffuse)
|
| 22 |
+
[](https://huggingface.co/spaces/tahamajs/BlockDiffuse-Blog)
|
| 23 |
+
[](https://huggingface.co/datasets/tahamajs/BlockDiffuse-Data)
|
| 24 |
+
|
| 25 |
+
> **TL;DR:** BlockDiffuse is a non-autoregressive / block-autoregressive generative framework that generates **100 tokens simultaneously** in continuous latent space using **Rectified Flow Matching** and a **Diffusion Transformer (DiT)** conditioned on intermediate layers of modern LLMs (`Qwen/Qwen2.5-0.5B-Instruct`).
|
| 26 |
+
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
## β‘ Key Highlights & Benchmark Results
|
| 30 |
+
|
| 31 |
+
All benchmarks measured on a single consumer **NVIDIA GeForce RTX 4070 Laptop GPU (8GB VRAM)**:
|
| 32 |
+
|
| 33 |
+
| Generation Mode | Target Size | ODE Steps / Block | Numerical Solver | Latency (ms) | Throughput (tokens/sec) | VRAM Footprint |
|
| 34 |
+
| :--- | :--- | :--- | :--- | :--- | :--- | :--- |
|
| 35 |
+
| **Single-Block Parallel** | **100 tokens** | 8 ODE steps | DPM-Solver + TFE | **1,730.60 ms** | **57.78 tok/s** | 3,674 MB |
|
| 36 |
+
| **Multi-Block Autoregressive** | **200 tokens** | 8 ODE steps / block | DPM-Solver + TFE | **1,279.20 ms** | **156.35 tok/s** | 3,789 MB |
|
| 37 |
+
|
| 38 |
+
---
|
| 39 |
+
|
| 40 |
+
## ποΈ Architecture Overview
|
| 41 |
+
|
| 42 |
+
```
|
| 43 |
+
Prompt Prefix βββΊ Frozen Qwen2.5 (Layers 1..12) βββΊ Continuous Context c [L_p x 896]
|
| 44 |
+
β
|
| 45 |
+
Initial Gaussian Noise z_0 [100 x 896] ~ N(0, I) ββββββββββ€
|
| 46 |
+
βΌ
|
| 47 |
+
BlockDiffuse DiT (8 Layers, 14 Heads)
|
| 48 |
+
- AdaLN-Zero Timestep Conditioning
|
| 49 |
+
- Continuous RoPE Positional Encoding
|
| 50 |
+
- Rectified Flow (v-prediction)
|
| 51 |
+
β
|
| 52 |
+
βΌ
|
| 53 |
+
Predicted Latents z_1 [100 x 896]
|
| 54 |
+
β
|
| 55 |
+
βΌ
|
| 56 |
+
Deep Proj Head (3-Layer SwiGLU MLP)
|
| 57 |
+
β
|
| 58 |
+
βΌ
|
| 59 |
+
Pre-Head RMSNorm + Frozen LM Head
|
| 60 |
+
β
|
| 61 |
+
βΌ
|
| 62 |
+
Discrete Next 100 Tokens in Parallel
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
### 1. Base LLM Backbone
|
| 66 |
+
- **Model**: `Qwen/Qwen2.5-0.5B-Instruct`
|
| 67 |
+
- **Representation Layer**: Layer 12 (mid-layer context extraction, $d_{\text{model}} = 896$).
|
| 68 |
+
- **Head**: Frozen LM head with vocab size $151{,}936$.
|
| 69 |
+
|
| 70 |
+
### 2. Diffusion Transformer (DiT)
|
| 71 |
+
- **Depth**: 8 Transformer Blocks.
|
| 72 |
+
- **Attention**: 14 heads (head dimension 64, matches $d_{\text{model}} = 896$).
|
| 73 |
+
- **Initialization**: Direct parameter transfer from layers 6β11 of Qwen2.5-0.5B.
|
| 74 |
+
- **Modulation**: AdaLN-Zero modulates scale and shift parameters based on timestep $t \in [0, 1]$.
|
| 75 |
+
|
| 76 |
+
### 3. Flow Matching & Multi-Objective Training
|
| 77 |
+
Rectified Flow straight-line trajectory:
|
| 78 |
+
$$z_t = (1 - t) z_0 + t z_1, \quad v_t = \frac{dz_t}{dt} = z_1 - z_0$$
|
| 79 |
+
|
| 80 |
+
Trained under composite multi-loss:
|
| 81 |
+
$$\mathcal{L}_{\text{total}} = \lambda_{\text{FM}} \mathcal{L}_{\text{FM}} + \lambda_{\text{disp}} \mathcal{L}_{\text{disp}} + \lambda_{\text{KL}} \mathcal{L}_{\text{KL}} + \lambda_{\text{CE}} \mathcal{L}_{\text{CE}} + \lambda_{\text{NN}} \mathcal{L}_{\text{NN}}$$
|
| 82 |
+
|
| 83 |
+
---
|
| 84 |
+
|
| 85 |
+
## π» Quickstart: Inference
|
| 86 |
+
|
| 87 |
+
### 1. Clone & Setup
|
| 88 |
+
```bash
|
| 89 |
+
git clone https://github.com/Hooshaai/BlockDiffuse.git
|
| 90 |
+
cd BlockDiffuse
|
| 91 |
+
pip install -r requirements.txt
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
### 2. Download Checkpoint from Hugging Face
|
| 95 |
+
```python
|
| 96 |
+
from huggingface_hub import hf_hub_download
|
| 97 |
+
|
| 98 |
+
ckpt_path = hf_hub_download(
|
| 99 |
+
repo_id="tahamajs/BlockDiffuse",
|
| 100 |
+
filename="blockdiffuse_final.pt"
|
| 101 |
+
)
|
| 102 |
+
print("Checkpoint downloaded to:", ckpt_path)
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
### 3. Run Parallel Multi-Block Generation
|
| 106 |
+
```bash
|
| 107 |
+
python inference.py \
|
| 108 |
+
--model Qwen/Qwen2.5-0.5B-Instruct \
|
| 109 |
+
--checkpoint ./checkpoints_improved/blockdiffuse_final.pt \
|
| 110 |
+
--prompt "<|im_start|>system\nYou are a helpful assistant that solves problems step by step.<|im_end|>\n<|im_start|>user\nA bookstore has 140 books on Monday. On Tuesday, they sell 45 books. On Wednesday, they receive 80 books. How many remain?<|im_end|>\n<|im_start|>assistant\n" \
|
| 111 |
+
--max_blocks 2 \
|
| 112 |
+
--steps 8 \
|
| 113 |
+
--solver dpm_solver \
|
| 114 |
+
--use_tfe \
|
| 115 |
+
--tfe_seeds 3
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
---
|
| 119 |
+
|
| 120 |
+
## π Citation
|
| 121 |
+
|
| 122 |
+
```bibtex
|
| 123 |
+
@article{blockdiffuse2026,
|
| 124 |
+
title={BlockDiffuse: Fully Parallel Latent Space Reasoning Generation with Diffusion Transformers},
|
| 125 |
+
author={Hooshaai Research},
|
| 126 |
+
journal={GitHub / HuggingFace Technical Report},
|
| 127 |
+
year={2026},
|
| 128 |
+
url={https://github.com/Hooshaai/BlockDiffuse}
|
| 129 |
+
}
|
| 130 |
+
```
|