Views
No views yet
stabilityai/stable-diffusion-2-1-base
(UNet + CLIP text encoder trained) with a lightweight Hierarchical Conditioner Network (HCN):
a typed compositional conditioner that takes the three demographic attributes (sex, race, age)
and emits four demographic tokens that the UNet reads next to the clinical-findings text tokens.compdiff-fundusModel versions. This is the second release of the chest model (September 2026), the checkpoint used in the current version of the paper. It conditions on all three attributes through the HCN, with age encoded continuously inside the conditioner. The first release (July 2026; sex × race through the HCN, age written into the prompt) remains available unchanged under thev1revision:snapshot_download(..., revision="v1"). The two releases have different conditioner code and a different pipeline interface, so do not mix files across revisions.
[ t_age, t_sex, t_race, t_cls ] → concatenated to the 77 CLIP text tokens → UNet cross-attentionmodel_index.json # diffusers StableDiffusionPipeline index
unet/ text_encoder/ vae/ # fine-tuned SD-2.1 UNet + text encoder (fp32); vae is the frozen base
tokenizer/ scheduler/ feature_extractor/
hcn/ # conditioner: config.json + model.safetensors (6.3M params)
compdiff2.py # self-contained conditioner class (CompDiff2Conditioner)
compdiff_pipeline.py # turnkey CompDiffPipeline (demographic-conditioned generation)
training_config.yaml # full training configuration of the released runpip install "diffusers>=0.35" transformers accelerate huggingface_hub safetensors pillowpip install torch may pull a build
newer than your driver supports (e.g. a cu130 wheel on a CUDA 12.4 driver fails with
"NVIDIA driver too old" / cuda available: False). Pick the wheel for your CUDA version
from pytorch.org. Tested combo (A100, driver
550.x / CUDA 12.4):pip install torch==2.6.0 --index-url https://download.pytorch.org/whl/cu124compdiff_pipeline.py reproduces the generation loop used for the paper's
evaluation cohorts (classifier-free guidance 7.5, DDPM sampling, 75 steps, 512×512). This is
the recommended entry point:1import torch
2from huggingface_hub import snapshot_download
3
4path = snapshot_download("mahmoudibra98/compdiff-chest-xray")
5import sys; sys.path.insert(0, path)
6from compdiff_pipeline import CompDiffPipeline
7
8pipe = CompDiffPipeline.from_pretrained(path, device="cuda", dtype=torch.float16)
9img = pipe.generate("Cardiomegaly with small bilateral pleural effusions",
10 sex="female", race="White", age=67)[0]
11img.save("out.png")prompt; do not write age, sex or race into it (the pipeline warns if it sees
demographic words). age is a number of years, not a bin. Each of prompt, sex, race,
age may also be a list of length num_images to generate a mixed batch, and seed= makes
a call reproducible.sex : 0 = male, 1 = female
race: 0 = White, 1 = Black/African American, 2 = Asian, 3 = Hispanic/Latinosex/race accept an integer index (always safe) or a string (mapped with the convention above)."<AGE> year old <RACE> <SEX>. <IMPRESSION>"; CompDiff strips
the demographic clause before the text encoder and routes the three attributes through the
HCN instead. The text encoder therefore only ever saw the impression / findings text, for
example:"Cardiomegaly with small bilateral pleural effusions."
"No acute cardiopulmonary process."
"Right mid lung rounded opacity may represent a new mass or infection. Recommend CT for further evaluation.""Normal chest radiograph", the same fallback used in training.1from compdiff2 import CompDiff2Conditioner # after sys.path.insert(0, path)
2hcn = CompDiff2Conditioner.from_pretrained(f"{path}/hcn", device="cuda")
3ctx, mu, logsigma, aux, _ = hcn(sex_idx=torch.tensor([1]).cuda(),
4 race_idx=torch.tensor([0]).cuda(),
5 age_continuous=torch.tensor([67.0]).cuda())
6ctx.shape # torch.Size([1, 4, 1024]) -> concatenate to the CLIP hidden states (dim=1)compdiff_pipeline.py.diffusers gives the fine-tuned SD-2.1 backbone
without demographic conditioning (the conditioner is not part of the diffusers pipeline):1import torch
2from diffusers import StableDiffusionPipeline
3
4pipe = StableDiffusionPipeline.from_pretrained(path, dtype=torch.float16, safety_checker=None).to("cuda")
5image = pipe("a chest radiograph", num_inference_steps=75, guidance_scale=7.5).images[0]CompDiffPipeline for real use.| Metric | Value |
|---|---|
| FID (Inception) | 58.7 |
| FID (RadImageNet features) | 5.78 |
| Sex accuracy (XRV classifier) | 0.999 |
| Race accuracy (XRV classifier) | 0.955 |
| Age RMSE, years (XRV regressor) | 8.44 |
| Mean disease AUROC (XRV DenseNet-121) | 0.823 |
1@article{ibrahim2026compdiff,
2 title = {CompDiff: Hierarchical Compositional Diffusion for Fair and Zero-Shot Intersectional Medical Image Generation},
3 author = {Ibrahim, Mahmoud and Elen, Bart and Sun, Chang and Ertaylan, Gokhan and Dumontier, Michel},
4 journal = {arXiv preprint arXiv:2603.16551},
5 year = {2026},
6 url = {https://arxiv.org/abs/2603.16551}
7}