Skip to content

Fix Grad behavior on empty outputs#272

Merged
ValerianRey merged 2 commits intomainfrom
fix-grad-empty-outputs
Mar 25, 2025
Merged

Fix Grad behavior on empty outputs#272
ValerianRey merged 2 commits intomainfrom
fix-grad-empty-outputs

Conversation

@ValerianRey
Copy link
Copy Markdown
Contributor

  • Make Grad._differentiate return a tuple of zero tensors when its outputs parameter is of length 0

When outputs is an empty list, we are implicitly summing no gradients. The identity element w.r.t. the summation of tensors of the same shape as the inputs is tensors of zeros of the same shape as the inputs, not tensors of nan values like we had. This is an internal fix since there is currently no way to call Grad with empty outputs with the current public interface of torchjd.

@ValerianRey ValerianRey added package: autojac cc: fix Conventional commit type for bug fixes of the actual library (changes to src). labels Mar 25, 2025
@ValerianRey ValerianRey self-assigned this Mar 25, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 25, 2025

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/torchjd/autojac/_transform/grad.py 0.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/torchjd/autojac/_transform/grad.py 94.73% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@PierreQuinton PierreQuinton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coverage will be added in later PR, LGTM.

@ValerianRey ValerianRey merged commit e951575 into main Mar 25, 2025
13 of 14 checks passed
@ValerianRey ValerianRey deleted the fix-grad-empty-outputs branch March 25, 2025 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cc: fix Conventional commit type for bug fixes of the actual library (changes to src). package: autojac

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants