DiffusionUNet3D cannot run under torch.autocast (amp_mode is not exposed)
Maintainers usually reply within 2 days
Nobody has claimed this yet.
- #1937 by @pjaysaval — closed without merging
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Domain
- machine-learning
Research direction
Start with physicsnemo/experimental/models/diffusion_unets/diffusion_unet_3d.py, focusing on DiffusionUNet3D and UNetBlock3D, then compare their constructors and layer setup with SongUNet and physicsnemo.nn UNetBlock. Check the amp_mode validation in physicsnemo/nn/module/fully_connected_layers.py and its utility module. Done means the 3D model exposes and propagates amp_mode, and the reported torch.autocast example no longer raises.
Written by the indexing model from the issue text.
Description
Version
2.1.1 (also reproduces on current main)
On which installation method(s) does this occur?
Pip
Describe the issue
The experimental 3D diffusion U-Net (physicsnemo.experimental.models.diffusion_unets.DiffusionUNet3D) cannot be trained under torch.autocast. Its internal physicsnemo.nn layers (Linear, PositionalEmbedding, FourierEmbedding) validate their amp_mode flag in forward and raise when autocast is active, but neither DiffusionUNet3D nor UNetBlock3D exposes the flag, so it is always False and mixed-precision training always fails.
The 2D counterparts (SongUNet, physicsnemo.nn UNetBlock) expose amp_mode as a constructor argument and thread it through their layers; the 3D model is missing that plumbing.
Minimum reproducible example
import torch
from physicsnemo.experimental.models.diffusion_unets import DiffusionUNet3D
model = DiffusionUNet3D(
x_channels=1, num_levels=2, model_channels=16, channel_mult=[1, 2],
num_blocks=1,
).cuda()
x = torch.randn(2, 1, 16, 16, 16, device="cuda")
t = torch.rand(2, device="cuda")
with torch.autocast("cuda", dtype=torch.bfloat16):
model(x, t) # raises
Relevant log output
File ".../physicsnemo/experimental/models/diffusion_unets/diffusion_unet_3d.py", line 515, in forward
emb = silu(self.map_layer0(emb))
File ".../physicsnemo/nn/module/fully_connected_layers.py", line 521, in forward
_validate_amp(self.amp_mode)
File ".../physicsnemo/nn/module/utils/utils.py", line 209, in _validate_amp
raise RuntimeError(
RuntimeError: amp_mode=False but torch autocast is enabled on: cuda. Disable autocast for this region or set amp_mode=True if mixed precision is intended.
Environment details
nvidia-physicsnemo 2.1.1, torch 2.11.0+cu128 / 2.13.0, Python 3.12
Observed on A100 (Linux, CUDA 12.8) and on CPU with torch.autocast("cpu", dtype=torch.bfloat16).
- Dominant language
- Python
- Stars
- 3.4k
- Forks
- 824
- Avg merge
- 4d 5h
- Merged PRs (30d)
- 82
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NVIDIA/physicsnemo
-
Wasserstein CDF distance uses the first width for every binPossibly taken @sylvesterkaczmarek claimed this 25 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
NVIDIA/physicsnemo#2042 ·
Maintainers usually reply within 2 days
-
🐛[BUG]: Darcy2D Jacobi kernel divides grad(k)·grad(u) by 2dx instead of 4dx², so the data doesn't solve the Darcy equationPossibly taken @coreyjadams claimed this 23 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
NVIDIA/physicsnemo#2036 · 2 comments · 1 assignee ·
Maintainers usually reply within 2 days
-
🐛[BUG]: MHD_PDE equation "B_grad_u" uses v * Bx.diff(y) instead of By * u.diff(y)Possibly taken @aaguadob claimed this 30 days ago. Open? - Needs Triage bug
Difficulty 1/5 Under an hour Newbie friendliness 92/100
NVIDIA/physicsnemo#2021 ·
Maintainers usually reply within 2 days
-
🐛[BUG]: Diffusion(time=True) in darcy_physics_informed/utils.py silently drops the time-derivative termPossibly taken @aaguadob claimed this 30 days ago. Open? - Needs Triage bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
NVIDIA/physicsnemo#2020 ·
Maintainers usually reply within 2 days
-
Difficulty 5/5 Over a week Newbie friendliness 15/100
NVIDIA/physicsnemo#2177 ·
Maintainers usually reply within 2 days
All issues in NVIDIA/physicsnemo
Similar issues
-
ready-for-agent tooling
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
KRoperUK/smeg-plus-patches#249 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
monzta1/ToneCommand#293 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
oracle/graalvm-reachability-metadata#11318 ·
Maintainers usually reply within 1 day
-
area: parser bug difficulty: easy
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
hayagrivai-labs/phantom#150 ·
Maintainers usually reply within 1 day
-
difficulty: easy good first issue help wanted mentor available testing
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
hayagrivai-labs/sciproof#179 ·
Maintainers usually reply within 1 day