Views
No views yet
stabilityai/stable-diffusion-2-1-base
(UNet + CLIP text encoder trained) augmented with a lightweight Hierarchical Conditioner Network (HCN)
that injects demographic attributes (sex, race, age) into the generation.model_index.json # diffusers StableDiffusionPipeline index
unet/ text_encoder/ vae/ # fine-tuned SD-2.1 components (vae is the frozen base)
tokenizer/ scheduler/ feature_extractor/
hcn/ # HCN module: config.json + pytorch_model.bin
hcn_v7.py # self-contained HCN class (HierarchicalConditionerV8)
compdiff_pipeline.py # turnkey CompDiffPipeline (demographic-conditioned generation)
training_config.yaml # full training configurationpip 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 exact generation used in the paper —
it appends the HCN demographic token to the text embeddings and runs classifier-free
guided DDPM sampling. This is the recommended entry point:1import torch
2from huggingface_hub import snapshot_download
3
4path = snapshot_download("mahmoudibra98/compdiff-fundus")
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("glaucoma, severe vision loss, abnormal cup-disc ratio, myopia",
10 sex="female", race=0, age=67)[0]
11img.save("out.png")age= and it is prepended as
"<age> years old. ..."). Put only clinical findings in prompt — not sex/race.sex : 0 = male, 1 = female
race: 0 = White, 1 = Black/African American, 2 = Asian (this model uses 3 race classes)race="White", "Black", "Asian"), but note
that unlike the chest model there is no Hispanic/Latino class here — index 3 is out of
range. Pass integer indices if in doubt."<age> years old. <clinical findings>"<clinical findings> in prompt; compdiff_pipeline.py prepends the age
string for you when you pass age=. Omit age= to drop the age clause entirely. Do not
put sex/race in the prompt — they are conditioned by the HCN.prompt as
", ".join(...) of the following slots, in this order:| Slot | Values |
|---|---|
| Glaucoma status | glaucoma / non-glaucoma |
| Vision loss (mean-deviation severity) | normal vision, or <severity> vision loss (e.g. mild vision loss, moderate vision loss, severe vision loss) |
| Cup-to-disc ratio (optional) | normal cup-disc ratio / borderline cup-disc ratio / abnormal cup-disc ratio |
| Refraction (optional) | hyperopia / emmetropia / myopia |
non-glaucoma, normal vision, normal cup-disc ratio, emmetropia
glaucoma, severe vision loss, abnormal cup-disc ratio, myopiadiffusers gives the fine-tuned SD-2.1 backbone
without demographic conditioning (the HCN 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 retinal fundus image", num_inference_steps=75, guidance_scale=7.5).images[0]compdiff_pipeline.py or generate_synthetic_dataset.py
in the CompDiff repository.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}