A conditional Denoising Diffusion Probabilistic Model (DDPM) that emulates
neutral-hydrogen (HI) 2D maps from the CAMELS Latin-Hypercube (LH)
simulation suite, conditioned on the full 6 CAMELS LH parameters
(Ωm, σ8, ASN1, AAGN1, ASN2, AAGN2). Sampling supports both full DDPM and
accelerated DDIM.
This is the best-validation checkpoint from the training run under
ddpm_hi_lh6/outputs_conditional_6param_20260413_132226/.
Files in this repo
Top level
File
Purpose
model.pt
PyTorch checkpoint (state-dict for ConditionalDiffusionModel)
args.json / args.txt
Training hyper-parameters and U-Net configuration
config.json
Architecture summary (for Hub discoverability)
inference_example.py
Runnable example: downloads weights and generates a sample
src/ — per-model Python
File
Purpose
train_conditional.py
Training entry point (label_dim=6, mixed-precision)
evaluate_conditional.py
Held-out evaluation: samples + metrics
eval_model.py
Lightweight evaluation helper used by the figure scripts
posterior_inference.py
Full posterior-inference pipeline (likelihood / sampling)
figure9_posterior.py
Paper figure 9 (posterior triangle for the 6-param model)
plot_r2_cosmology_lhs.py
Latin-hypercube R² map (μ, σ vs cosmology)
unet_conditional.py
ConditionalUNet module
diffusion_conditional.py
GaussianDiffusion (DDPM + DDIM) and the wrapping ConditionalDiffusionModel
dataset_conditional.py
CAMELS LH dataset loader + label normalisation
scripts/shell/ — SLURM launchers
File
Purpose
train_conditional_lh6.sh
Submit a training job (label_dim=6)
evaluate_conditional_lh6.sh
Submit evaluation against the held-out test split
plot_r2_cosmology_lhs.sh
Generate the R² cosmology figure
cross_model/ — posterior + comparison scripts that use BOTH models
Confidence-contour helper used by the figure scripts
scripts/compare_ddpm_training_curves.py
Parses SLURM logs for combined train/val loss plots
cross_model/README.md
How to point these scripts at locally-downloaded weights/data
These cross-model scripts default to the original cluster paths (e.g.
<CAMELS_LH_DATA_DIR>/params_6). After downloading
this repo, supply --bundle-2param, --bundle-6param, --data-2param,
--data-6param to override.
Architecture
Conditional U-Net + Gaussian diffusion process. Hyper-parameters (taken from
args.json):
Field
Value
label_dim
6
base_channels
64
channel_multipliers
[1, 2, 4, 8]
attention_levels
[2, 3]
dropout
0.1
timesteps
1500 (linear β schedule: 1e-4 → 0.02)
EMA decay
0.9999
Mixed precision
Yes (use_amp = true during training)
Sampler
DDIM, 50 steps (DDPM also supported)
Image size
256 × 256, single channel
Image range
[-1, 1] (training data is rescaled by x * 2 - 1)
Labels are z-scored using the training-split mean / std. The
inference_example.py shows how to recover this normalisation from the
CAMELS LH params_6 dataset, or you can pass already-normalised conditioning
values directly.
Quick start
python
1from huggingface_hub import hf_hub_download
2import sys, torch, json
3from pathlib import Path
45# 1) Download all needed files6repo ="collins909/DDPM-6param"7ckpt_path = hf_hub_download(repo,"model.pt")8args_path = hf_hub_download(repo,"args.json")9for name in("unet_conditional.py","diffusion_conditional.py","__init__.py"):10 hf_hub_download(repo,f"src/{name}")11sys.path.insert(0,str(Path(ckpt_path).parent /"src"))1213from unet_conditional import ConditionalUNet
14from diffusion_conditional import GaussianDiffusion, ConditionalDiffusionModel
1516# 2) Rebuild the model from args.json17args = json.loads(Path(args_path).read_text())18unet = ConditionalUNet(19 in_channels=1, out_channels=1,20 label_dim=args["label_dim"],21 base_channels=args["base_channels"],22 channel_multipliers=tuple(args["channel_multipliers"]),23 attention_levels=tuple(args["attention_levels"]),24 dropout=args["dropout"],25)26diffusion = GaussianDiffusion(27 timesteps=args["timesteps"],28 beta_start=args["beta_start"],29 beta_end=args["beta_end"],30 schedule_type=args["schedule_type"],31)32model = ConditionalDiffusionModel(unet, diffusion)3334# 3) Load the checkpoint and sample35ckpt = torch.load(ckpt_path, map_location="cpu", weights_only=False)36model.load_state_dict(ckpt["model_state_dict"])37model.eval()3839# 6-parameter conditioning vector (order: Ωm, σ8, ASN1, AAGN1, ASN2, AAGN2),40# z-scored with training-split stats. See inference_example.py for the helper.41labels = torch.zeros((1,6))42sample = model.sample(labels, channels=1, height=256, width=256,43 device="cpu", use_ddim=True, ddim_steps=50)44# sample is in [-1, 1]; rescale to physical HI units as needed.
For an end-to-end runnable example (including label normalisation, GPU usage,
and image saving), see inference_example.py in this repo.
Training data
Trained on CAMELS LH HI maps with full 6-parameter conditioning. The
data layout consumed by src/dataset_conditional.py is:
Images are rescaled to [-1, 1]; labels are z-scored using train-split
statistics. Point your training/eval scripts at the local directory that contains those
files (e.g. via --data_dir <CAMELS_LH_DATA_DIR>/params_6).
Intended use & limitations
Intended for research on diffusion emulators for cosmological fields,
posterior inference, and sensitivity studies across cosmology /
astrophysics nuisance parameters.
The companion 2-parameter model (collins909/DDPM-2param) is
available for the simpler 2-label setup.
Outputs are 256 × 256 single-channel maps in the model's normalised range.
Apply the inverse of any data-pipeline preprocessing before physical
interpretation.
Citation
If you use this checkpoint, please cite the CAMELS project and the upstream
DDPM HI emulation work. (Citation block to be filled in once the
accompanying paper is published.)