Skip to main content

A diffusion-based language model implementation

Project description

DiffusionLM: Large Language Models with Diffusion

PyPI version License: MIT

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/PIP-DifffusionLM.git
cd PIP-DifffusionLM
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

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/PIP-DifffusionLM}
}

Contact

PIP-DifffusionLM

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

diffusionlm-0.1.8.tar.gz (21.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

diffusionlm-0.1.8.0-py3-none-any.whl (26.5 kB view details)

Uploaded Python 3

diffusionlm-0.1.8-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

Details for the file diffusionlm-0.1.8.tar.gz.

File metadata

  • Download URL: diffusionlm-0.1.8.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for diffusionlm-0.1.8.tar.gz
Algorithm Hash digest
SHA256 6e71cd0c028146d3a5e08d39656de94286e56892a2b84b295558434ddd8bf95a
MD5 8eda2072cc99f4786f749a8eebc60720
BLAKE2b-256 5fe296cb0bbcd40bef708813a96a658639a9241193b9328f705a4acd357305f3

See more details on using hashes here.

File details

Details for the file diffusionlm-0.1.8.0-py3-none-any.whl.

File metadata

  • Download URL: diffusionlm-0.1.8.0-py3-none-any.whl
  • Upload date:
  • Size: 26.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for diffusionlm-0.1.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 290a829e08d7eb1087330a767864b5e9ebfa89e630dbf6aa72fb3d89cd0d2893
MD5 063388e65b0c771be2b6561f55534225
BLAKE2b-256 b687512a907bddb20acc2a1a5eaf359b406d2bd4b21e99c24b44dbf3dfbae77c

See more details on using hashes here.

File details

Details for the file diffusionlm-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: diffusionlm-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 26.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for diffusionlm-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 129768fe0f6f63a045fe45e399c44e90fadbdb57adbec3d74c11946c14991b2b
MD5 b551a92160ccb23b33feea472ac55eab
BLAKE2b-256 217ecf72361ea7152a246d7c298cd95b7dc3af1616904146a0ba0485fee528ed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page