Skip to main content

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) * up with 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-launch or python -m cupydiff.cli).
  • Curriculum Shard Pipeline:
    • Compatible with binary token shards (.bin, uint16) and direct streaming from Hugging Face: vovaRL/slm388-corpus.

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.1.2

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

Source distribution (sdist)

Source distribution for cupydiff 0.1.2
File Size Uploaded Provenance
cupydiff-0.1.2.tar.gz 52.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for cupydiff 0.1.2
File Interpreter ABI Platform
cupydiff-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 109.2 kB

Release files / cupydiff-0.1.2.tar.gz

Download URL cupydiff-0.1.2.tar.gz
Size 52.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4d1abfb0de4efe856be0bf2a73a5167fef66940f309f4fce384be0062ce8539f
BLAKE2b-256 checksum
How to use checksums
d44bde6d98ea4c52e4f307e30f22279c621d9201c1a0e79589aa21ead6cb223b
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.1.2-py3-none-any.whl

Download URL cupydiff-0.1.2-py3-none-any.whl
Size 56.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0c541d79fb03b23eef6d8d286ba812a4c88dc9d1f91593bb836224a03d611520
BLAKE2b-256 checksum
How to use checksums
bbeceb6891ce560e6069fa8c65ee8f009986acc300d7fed6f0acbefffb4879f7
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.1.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.

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