Fix: swap input_amplitude and target_amplitude in JukeboxLoss.forward#8821
Fix: swap input_amplitude and target_amplitude in JukeboxLoss.forward#8821Zeesejo wants to merge 2 commits intoProject-MONAI:devfrom
Conversation
Fixes Project-MONAI#8820 - input_amplitude was incorrectly computed from `target` and target_amplitude from `input`. Corrected to match semantic meaning and standard forward(input, target) convention. Signed-off-by: Zeeshan Modi <92383127+Zeesejo@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughFixes two small, independent edits: (1) in monai/losses/spectral_loss.py, Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Fixes a semantic bug in JukeboxLoss.forward() where input_amplitude and target_amplitude were computed from the wrong tensors, aligning the implementation with the standard PyTorch forward(input, target) convention.
Changes:
- Compute
input_amplitudefrominput(instead oftarget). - Compute
target_amplitudefromtarget(instead ofinput).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def forward(self, input: torch.Tensor, target: torch.Tensor) -> torch.Tensor: | ||
| input_amplitude = self._get_fft_amplitude(target) | ||
| target_amplitude = self._get_fft_amplitude(input) | ||
| input_amplitude = self._get_fft_amplitude(input) | ||
| target_amplitude = self._get_fft_amplitude(target) | ||
|
|
There was a problem hiding this comment.
The existing unit tests for JukeboxLoss validate numeric output/shape, but they won’t fail if input/target amplitudes are swapped because MSE is symmetric. To prevent regressions of this specific semantics fix, consider adding a test that patches/spies on _get_fft_amplitude (e.g., via unittest.mock) and asserts it is called first with input and then with target inside forward().
| def forward(self, input: torch.Tensor, target: torch.Tensor) -> torch.Tensor: | ||
| input_amplitude = self._get_fft_amplitude(target) | ||
| target_amplitude = self._get_fft_amplitude(input) | ||
| input_amplitude = self._get_fft_amplitude(input) | ||
| target_amplitude = self._get_fft_amplitude(target) |
There was a problem hiding this comment.
PR description indicates "In-line docstrings updated", but this diff only swaps the input_amplitude/target_amplitude assignments and doesn’t modify any docstrings/comments. Either update the PR checklist/description to match the actual change set or include the intended docstring update in this PR.
Fixes Project-MONAI#8822 - The forward() docstring examples used `print(1-SSIMLoss()(x,y))`, but SSIMLoss already computes 1-ssim internally. The `1-` prefix made examples return ssim (not loss), misleading users into training with inverted loss. Signed-off-by: Zeeshan Modi <92383127+Zeesejo@users.noreply.github.com>
|
Update: This PR now also includes a second commit ( The |
Fixes #8820
Description
In
JukeboxLoss.forward(), the variable namesinput_amplitudeandtarget_amplitudewere swapped:input_amplitudewas computed fromtarget(should be frominput)target_amplitudewas computed frominput(should be fromtarget)This fix corrects the assignments to match semantic meaning and the standard
forward(input, target)PyTorch convention.Types of changes
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests --disttests.make htmlcommand in thedocs/folder.