Skip to main content
WiDiT banner

pypi badge testing badge coverage badge docs badge black badge

WiDiT is a SwinIR-style DiT backbone that unifies 2D images and 3D volumes with N-D windowed attention, optional Swin shifts, and AdaLN-Zero conditioning.

  • Single model class: widit.models.WiDiT

  • Also includes a configurable widit.models.Unet for 2D/3D U-Net baselines

  • Optional timestep conditioning (pass timestep=None if unused)

  • Shared blocks for 2D/3D via N-D window partitioning

  • Presets for quick experiments in both 2D and 3D

Installation

Install using pip:

pip install widit

Or

pip install git+https://github.com/rbturnbull/widit.git

WiDiT depends on torch.

Quick Start (2D)

import torch
from widit.models import WiDiT

# Example: 2D RGB input & conditioning (e.g., low-res guidance)
N, C, H, W = 2, 3, 128, 96
x      = torch.randn(N, C, H, W)
cond   = torch.randn_like(x)
t      = torch.randint(0, 1000, (N,), dtype=torch.long)  # optional

model = WiDiT(
    spatial_dim=2,
    patch_size=2,             # must divide H and W
    in_channels=C,
    hidden_size=256,          # must be divisible by num_heads and even
    depth=6,
    num_heads=8,
    window_size=8,            # can be int or (wh, ww)
    mlp_ratio=4.0,
    learn_sigma=True,         # output channels = 2*C if True
    use_conditioning=True,    # expect a conditioning image
)

# NEW CALL SIGNATURE:
# forward(input, timestep=None, *, conditioned=None)
y = model(x, t, conditioned=cond)     # (N, 2*C, H, W) if learn_sigma=True

Quick Start (3D)

import torch
from widit.models import WiDiT

# Example: 3D single-channel volumes
N, C, D, H, W = 1, 1, 64, 64, 48
x    = torch.randn(N, C, D, H, W)
cond = torch.randn_like(x)

model = WiDiT(
    spatial_dim=3,
    patch_size=2,             # must divide D/H/W
    in_channels=C,
    hidden_size=256,
    depth=4,
    num_heads=8,
    window_size=(4, 4, 4),    # can be int or (wd, wh, ww)
    mlp_ratio=4.0,
    learn_sigma=False,        # output channels = C if False
    use_conditioning=True,
)

y = model(x, timestep=None, conditioned=cond)  # (N, C, D, H, W)

Unconditioned Image Path (no second image)

import torch
from widit.models import WiDiT

N, C, H, W = 2, 3, 128, 96
x = torch.randn(N, C, H, W)
t = torch.randint(0, 1000, (N,))

model = WiDiT(
    spatial_dim=2,
    in_channels=C,
    hidden_size=256,
    depth=4,
    num_heads=8,
    patch_size=2,
    window_size=8,
    learn_sigma=True,
    use_conditioning=False,       # <-- no conditioning image expected
)

# Do NOT pass `conditioned` when use_conditioning=False
y = model(x, t)  # (N, 2*C, H, W)

Presets

Presets provide ready-made configurations for common model sizes (2D & 3D), all using patch_size=2 and Swin-style window attention:

from widit.models import PRESETS
import torch

# 2D: B, M, L, XL
model_2d = PRESETS["WiDiT2D-L"](in_channels=3, learn_sigma=True)

# 3D: B, M, L, XL
model_3d = PRESETS["WiDiT3D-M"](in_channels=1, learn_sigma=False)

# Example inputs
x2d = torch.randn(1, 3, 64, 48)
c2d = torch.randn_like(x2d)
t2d = torch.randint(0, 1000, (1,))

x3d = torch.randn(1, 1, 32, 32, 24)
c3d = torch.randn_like(x3d)
t3d = torch.randint(0, 1000, (1,))

# Run
y2d = model_2d(x2d, t2d, conditioned=c2d)
y3d = model_3d(x3d, timestep=None, conditioned=c3d)

Loading Models

Use load_model to load a saved WiDiT or Unet checkpoint. It infers the correct class from the stored config:

from widit import load_model

model = load_model("path/to/checkpoint.pt")

Credits

Robert Turnbull - Melbourne Data Analytics Platform (MDAP), The University of Melbourne

Metadata

Release files for WiDiT 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 WiDiT 0.1.2
File Size Uploaded
widit-0.1.2.tar.gz 19.4 kB Details

Built distribution (wheel)

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

Total release size: 39.9 kB

Release files / widit-0.1.2.tar.gz

Download URL widit-0.1.2.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2ff0af722c4764a2a6c604767f4fdfd211689c4c5e97b55d6b569555767207b8
BLAKE2b-256 checksum
How to use checksums
c9d86739f4d5a10a1c94ee058fdb1d759f05b9e5d188682e25b5f494ba3e623b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.13.1 Darwin/25.6.0

Release files / widit-0.1.2-py3-none-any.whl

Download URL widit-0.1.2-py3-none-any.whl
Size 20.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
734d2c9a1e5038ee45deca0bd13eba01ed0aa1b62d44ec6a19ca45912786880f
BLAKE2b-256 checksum
How to use checksums
14cad44dcb7a742776fd919848e2aad7a8db6cab91367cd1b2d08ff2fe77a7d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.13.1 Darwin/25.6.0

Release history Release notifications | RSS feed

0.1.15

2 release files

This release

0.1.2 This release

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