-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix hardcoded input dim in DiffusionModelEncoder #8514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
WalkthroughThe initialization of the output layer in the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant DiffusionModelEncoder
participant nn.Sequential
User->>DiffusionModelEncoder: forward(input)
DiffusionModelEncoder->>DiffusionModelEncoder: Flatten features (h)
alt self.out not initialized
DiffusionModelEncoder->>nn.Sequential: Create with input size = h.shape[1]
DiffusionModelEncoder->>DiffusionModelEncoder: Assign to self.out
end
DiffusionModelEncoder->>nn.Sequential: Pass h through self.out
nn.Sequential-->>DiffusionModelEncoder: Output tensor
DiffusionModelEncoder-->>User: Return output
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
monai/networks/nets/diffusion_model_unet.py (1)
2053-2056
: Consider device placement and thread safety for lazy initialization.The lazy initialization logic is correct, but consider these improvements:
- Device placement: The dynamically created module should be moved to the same device as the input tensor.
- Thread safety: In multi-threaded environments, this could create race conditions.
Apply this diff to ensure proper device placement:
- if self.out is None: - self.out = nn.Sequential( - nn.Linear(h.shape[1], 512), nn.ReLU(), nn.Dropout(0.1), nn.Linear(512, self.out_channels) - ) + if self.out is None: + self.out = nn.Sequential( + nn.Linear(h.shape[1], 512), nn.ReLU(), nn.Dropout(0.1), nn.Linear(512, self.out_channels) + ).to(h.device)For thread safety, consider using a lock or moving the initialization to a separate method called during model setup.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
monai/networks/nets/diffusion_model_unet.py
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
- GitHub Check: min-dep-pytorch (2.6.0)
- GitHub Check: min-dep-py3 (3.12)
- GitHub Check: min-dep-pytorch (2.5.1)
- GitHub Check: min-dep-py3 (3.11)
- GitHub Check: min-dep-pytorch (2.4.1)
- GitHub Check: min-dep-os (ubuntu-latest)
- GitHub Check: min-dep-py3 (3.10)
- GitHub Check: min-dep-py3 (3.9)
- GitHub Check: min-dep-os (windows-latest)
- GitHub Check: min-dep-os (macOS-latest)
- GitHub Check: quick-py3 (macOS-latest)
- GitHub Check: build-docs
- GitHub Check: flake8-py3 (mypy)
- GitHub Check: quick-py3 (ubuntu-latest)
- GitHub Check: quick-py3 (windows-latest)
- GitHub Check: packaging
- GitHub Check: flake8-py3 (codeformat)
- GitHub Check: flake8-py3 (pytype)
🔇 Additional comments (1)
monai/networks/nets/diffusion_model_unet.py (1)
2008-2008
: LGTM: Proper lazy initialization setup.Setting
self.out = None
correctly defers the output layer creation until runtime, enabling dynamic input dimension adaptation.
Signed-off-by: IamTingTing <[email protected]>
3e45145
to
595ca84
Compare
Fixes #8496
Description
A few sentences describing the changes proposed in this pull request.
Types of changes
./runtests.sh -f -u --net --coverage
../runtests.sh --quick --unittests --disttests
.make html
command in thedocs/
folder.Summary by CodeRabbit