Skip to main content

MMDiT-PyTorch

MMDiT-PyTorch is a lightweight and standalone PyTorch implementation of a single block from the Multimodal Diffusion Transformer (MMDiT), originally proposed in Scaling Rectified Flow Transformers for High-Resolution Image Synthesis.

MMDiT Architecture

This project focuses on simplicity and minimal dependencies to allow easy understanding and extensibility for research and experimentation.


🔍 Overview

MMDiT introduces a scalable and efficient Transformer-based architecture tailored for high-resolution image synthesis through rectified flows. This repository implements a single MMDiT block for educational and experimental purposes.

  • 📦 Single-block MMDiT in PyTorch
  • 🧠 Minimal and readable implementation
  • 🛠️ No training framework dependency

📦 Installation

Make sure you have Python 3.12+

Using pip

pip install mmdit-pytorch

From the source

git clone https://github.com/KennyStryker/mmdit-pytorch.git
cd mmdit-pytorch
poetry install

🚀 Usage

Make sure you have Python 3.12+ and Poetry installed.

import torch
from mmdit import MMDiTBlock

# Set embedding dimensions for each modality
dim_txt = 768         # Dimension of text embeddings
dim_img = 512         # Dimension of image embeddings
dim_timestep = 256    # Dimension of timestep embeddings (e.g., for conditioning)

device = 'cuda' if torch.cuda.is_available() else 'cpu'

# Initialize the multimodal transformer block
mmdit_block = MMDiTBlock(
    dim_txt=dim_txt,
    dim_img=dim_img,
    dim_timestep=dim_timestep,
    qk_rmsnorm=True  # Use RMSNorm on query/key in attention (optional setting)
).to(device)

# Generate random embeddings for demonstration
txt_emb = torch.randn(1, 512, dim_txt).to(device)
img_emb = torch.randn(1, 1024, dim_img).to(device)
time_emb = torch.randn(1, dim_timestep).to(device)

# Forward pass through the multimodal transformer block
txt_out, img_out = mmdit_block(txt_emb, img_emb, time_emb)

print(f"Text output shape: {txt_out.shape}")
print(f"Image output shape: {img_out.shape}")

Citations

@article{arXiv,
    title   = {Scaling Rectified Flow Transformers for High-Resolution Image Synthesis},
    author  = {Patrick Esser, Sumith Kulal, Andreas Blattmann, Rahim Entezari, Jonas Müller, Harry Saini, Yam Levi, Dominik Lorenz, Axel Sauer, Frederic Boesel, Dustin Podell, Tim Dockhorn, Zion English, Kyle Lacey, Alex Goodwin, Yannik Marek, Robin Rombach},
    url     = {https://arxiv.org/abs/2403.03206}
}

Metadata

Release files for mmdit-pytorch 0.2.7

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

Source distribution (sdist)

Source distribution for mmdit-pytorch 0.2.7
File Size Uploaded Provenance Actions
mmdit_pytorch-0.2.7.tar.gz 5.7 kB Without provenance Details for mmdit_pytorch-0.2.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mmdit-pytorch 0.2.7
File Interpreter ABI Platform Actions
mmdit_pytorch-0.2.7-py3-none-any.whl Python 3 none any Details for mmdit_pytorch-0.2.7-py3-none-any.whl

Total release size: 12.4 kB

Release files / mmdit_pytorch-0.2.7.tar.gz

Download URL mmdit_pytorch-0.2.7.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
72a2c0272946b4a0fe671bd52d5b8d6c40b0f2106bfeb868ff79cd1a8c441e24
BLAKE2b-256 checksum
How to use checksums
d8e8659e30565c23e492d9a85ab37066a8c70de15624e024ca674aaaa38178c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.0 CPython/3.12.9 Linux/5.15.167.4-microsoft-standard-WSL2

Release files / mmdit_pytorch-0.2.7-py3-none-any.whl

Download URL mmdit_pytorch-0.2.7-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bddd21c405947ecfbd2db5a110d61784c79b9e931019c354a7b12a42c7ae4900
BLAKE2b-256 checksum
How to use checksums
6dca32d856fcb7602f443f315b4869db59c15b83094df25a9e6c59bc0984cc7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.0 CPython/3.12.9 Linux/5.15.167.4-microsoft-standard-WSL2

Security for mmdit-pytorch 0.2.7

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.

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