cupydiff
High-Performance Discrete Diffusion Language Models in Triton + CuPy
Strictly NO PyTorch dependency. Pure functional architecture. Optimized for 8x NVIDIA RTX PRO 6000 96GB (Blackwell).
Highlights
- Strictly No PyTorch: Built entirely on Triton kernels and CuPy array operations with pure NumPy fallback for CPU testing.
- Pure Functional Design: Stateless mathematical functions, explicit weight dictionaries, and deterministic analytical forward and backward passes.
- Triton GPU Kernels:
- Fused RMSNorm & AdaLN: High-bandwidth elementwise normalization and adaptive modulation.
- Fused RoPE: Analytical rotary position embedding rotation.
- Fused SwiGLU:
silu(gate) * upwith analytical backward gradients. - Bidirectional FlashAttention: Non-causal scaled dot-product attention executing in $O(L)$ SRAM instead of $O(L^2)$ global memory.
- Cut Cross-Entropy (CCE): Chunked vocabulary projection that avoids materializing $(N, 49152)$ float32 logit tensors, preventing out-of-memory errors on massive context lengths.
- Hybrid Muon + AdamW Optimizer:
- Muon: Quintic Newton-Schulz iteration (polar orthogonalization) for internal 2D weight matrices with Nesterov momentum.
- AdamW: First and second moment buffers with decoupled weight decay for 1D vectors, biases, and token embeddings.
- Cosine Learning Rate Schedule: Warmup + cosine decay.
- Multi-GPU Scalability (8x RTX PRO 6000 96GB Blackwell):
- Native CuPy NCCL communicator with in-place gradient all-reduce.
- Multi-process launcher (
cupydiff-launchorpython -m cupydiff.cli).
- Curriculum Shard Pipeline:
- Compatible with binary token shards (
.bin, uint16) and direct streaming from Hugging Face:vovaRL/slm388-corpus.
- Compatible with binary token shards (
Installation
From Source / Local Development
git clone https://github.com/vovaRL/cupydiff.git
cd cupydiff
pip install -e .
With CUDA / Triton Acceleration (GPU)
pip install cupydiff[cuda]
(Installs cupy-cuda12x and triton)
Testing
cupydiff includes a complete standalone test suite that runs on CPU (using NumPy reference kernels) when no GPU is present, and automatically verifies Triton + CuPy GPU kernels when CUDA is available:
python tests/run_all.py
or with pytest:
pytest -v tests
Usage
1. Profiling & Benchmark Mode
Measure exact kernel latencies and throughput (tokens/sec):
# Single GPU
cupydiff --mode bench --bench_steps 20 --batch_size 64 --seq_len 2048
# 8x RTX PRO 6000 96GB
cupydiff --mode bench --nproc_per_node 8 --batch_size 512 --seq_len 2048
2. Pretraining on vovaRL/slm388-corpus
Trains the MDLM model using the curriculum binary shard loader:
cupydiff --mode train \
--hf_dataset vovaRL/slm388-corpus \
--data_dir /data/slm388-corpus \
--batch_size 512 \
--seq_len 2048 \
--nproc_per_node 8 \
--total_steps 85000 \
--repo_id vovaRL/DiffLM-388M \
--checkpoint_interval 2500
Hugging Face Jobs (8x RTX PRO 6000 96GB Blackwell)
To run distributed training on Hugging Face Jobs with 8x RTX PRO 6000:
hf jobs run \
--flavor 8x-rtx-pro-6000 \
--image nvidia/cuda:12.4.1-devel-ubuntu22.04 \
--env HF_TOKEN="hf_your_token_here" \
--command "pip install cupydiff[cuda] && cupydiff --mode train --hf_dataset vovaRL/slm388-corpus --batch_size 512 --seq_len 2048 --nproc_per_node 8"
Building and Pushing to PyPI
pip install build twine
python -m build
twine check dist/*
twine upload dist/*
Architecture Specification
| Hyperparameter | Value | Description |
|---|---|---|
| Model Dimension ($d$) | 512 | Hidden dimension |
| Diffusion Blocks | 3 | Block specializations ($t \in [0, 1]$) |
| Layers per Block | 6 | 18 total transformer layers |
| Attention Heads | 8 | Multi-head attention |
| Head Dimension | 64 | Query/Key/Value dimension ($8 \times 64 = 512$) |
| RoPE Theta ($\theta$) | 50,000.0 | Rotary frequency base |
| SwiGLU Hidden Dim | 1408 | MLP intermediate expansion |
| Vocabulary Size | 49,152 | Token vocabulary |
| Mask Token ID | 49,151 | [MASK] token for diffusion corruption |
| CCE Chunk Size | 8,192 | Cut Cross-Entropy projection chunk |
| Optimizer | Hybrid Muon + AdamW | Fused quintic Newton-Schulz for 2D weights, AdamW for 1D/heads |
License
Apache License 2.0.
Metadata
Release files for cupydiff 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| cupydiff-0.2.2.tar.gz | 56.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cupydiff-0.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 117.1 kB
Release files / cupydiff-0.2.2.tar.gz
| Download URL | cupydiff-0.2.2.tar.gz |
|---|---|
| Size | 56.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
24f9de7f0ffe146799591f825d4cc05bb004a469911bd364f3da0971707428b4
|
|
BLAKE2b-256 checksum How to use checksums |
8e3f8127cdeab40dcf58c2ddca101bcfae6178ea83ff7211865c68eab1f63687
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Release files / cupydiff-0.2.2-py3-none-any.whl
| Download URL | cupydiff-0.2.2-py3-none-any.whl |
|---|---|
| Size | 60.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e0c62089ab08e1537b5d11f1fcb2fdd91be9bede2811e3b621af370662de0eb6
|
|
BLAKE2b-256 checksum How to use checksums |
c366e851fe74b8b67784d38cd188cadfcd229d40e17dd9ea6baf20cae9d6ca15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Security for cupydiff 0.2.2
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.