Skip to main content

DiffusionLM: Large Language Models with Diffusion

PyPI version License: MIT Sponsor

DiffusionLM is a novel approach to language modeling that combines transformer architectures with diffusion processes for high-quality text generation. This package provides a flexible and efficient implementation of diffusion-based language models.

Features

  • Advanced Architecture

    • Transformer-based backbone with diffusion capabilities
    • Configurable model sizes (small, medium, large)
    • Time step conditioning
    • Attention mechanisms optimized for text
  • Multiple Generation Strategies

    • Auto-regressive generation
    • Parallel generation
    • Confidence-based masking
    • Semi-autoregressive generation
    • Top-p (nucleus) sampling
    • Beam search
  • Training Features

    • Distributed training support
    • Mixed precision training
    • Gradient checkpointing
    • Early stopping
    • Model checkpointing
    • Learning rate scheduling
  • Utilities

    • Real-time token generation streaming
    • Model saving and loading
    • HuggingFace Hub integration
    • Comprehensive logging
    • Error handling

Installation

pip install diffusionLM

For development installation:

git clone https://github.com/codewithdark-git/DiffusionLM.git
cd DiffusionLM
pip install -e .

Quick Start

from diffusionLM.utils import prepare_dataset
from diffusionLM.model import DiffusionConfig, DiffusionLLM
from transformers import AutoTokenizer

# Load tokenizer and prepare dataset
tokenizer = AutoTokenizer.from_pretrained("gpt2")
train_dataset, val_dataset, _ = prepare_dataset(
    dataset_name="wikitext/wikitext-103-v1",
    tokenizer_name="gpt2"
)

# Initialize model
config = DiffusionConfig(
        vocab_size=len(tokenizer),
        max_position_embeddings=256,
        num_timesteps=50,
        pad_token_id=tokenizer.pad_token_id,
        mask_token_id=tokenizer.mask_token_id,
        # **config_kwargs
    )

model = DiffusionLLM(config)

Training

Basic Training

from diffusionLM import trainer

train_model = trainer(
        model=model,
        train_dataset=train_dataset,
        val_dataset=val_dataset,
        batch_size=batch_size,
        num_epochs=num_epochs,
        learning_rate=learning_rate,
        num_timesteps=num_timesteps,
        save_path=save_dir,
        device=device,
    )

Model Registry

from diffusionLM import registerANDpush

registerANDpush(
    model=trained_model,
    tokenizer=tokenizer,
    model_type="diffusionLM",
    repo_id="your-username/model-name"
)

Error Handling

The package includes comprehensive error handling:

from diffusionLM import DiffusionLMError, handle_errors

@handle_errors()
def your_function():
    # Your code here
    pass

Sponsorship

If you find DiffusionLM useful for your project or research, please consider supporting its development through GitHub Sponsors. Your sponsorship helps maintain the project and develop new features.

Sponsor

Why Sponsor?

  • Support ongoing development and maintenance
  • Priority bug fixes and feature requests
  • Recognition in our documentation
  • Help make DiffusionLM better for everyone

How to Sponsor

Click the "Sponsor" button at the top of the repository or visit our GitHub Sponsors page.

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Requirements

  • Python ≥ 3.8
  • PyTorch ≥ 1.9.0
  • Transformers ≥ 4.21.0
  • For full requirements, see requirements.txt

License

This project is licensed under the MIT License - see the LICENSE file for details.

Citation

@article{diffusionllm2025,
  title={DiffusionLM: Large Language Models with Diffusion},
  author={Dark Coder},
  journal={GitHub Repository},
  year={2025},
  publisher={GitHub},
  url={https://github.com/codewithdark-git/DiffusionLM}
}

Contact

Release files for diffusionLM 0.1.9

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

Source distribution (sdist)

Source distribution for diffusionLM 0.1.9
File Size Uploaded
diffusionlm-0.1.9.tar.gz 22.0 kB Details

Built distribution (wheel)

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

Total release size: 48.5 kB

Release files / diffusionlm-0.1.9.tar.gz

Download URL diffusionlm-0.1.9.tar.gz
Size 22.0 kB
Tags Source
SHA-256 checksum
How to use checksums
82eb0626c4d39ea8fec8eff58f5a19ae48d951a005802a2df2be099bf7aa58fe
BLAKE2b-256 checksum
How to use checksums
e31de617e865d0bd28950e15d78aaa11dc8437946c787d8ab995ad256d03a251
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release files / diffusionlm-0.1.9-py3-none-any.whl

Download URL diffusionlm-0.1.9-py3-none-any.whl
Size 26.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6861a12a63c2c40f76fbd5a83ebfbe47d2861ad679f57796a460c654337e8b9d
BLAKE2b-256 checksum
How to use checksums
b9f29e5146bded09235aaa684c61d95dd1b5265742c23abee05547c9dfaac89b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.1.9 This release

2 release files

0.1.8

3 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

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