Skip to content
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

docs: fix mismatch between forward method and docstring of NTXentLoss #1789

Merged
merged 1 commit into from
Jan 29, 2025

Conversation

adosar
Copy link
Contributor

@adosar adosar commented Jan 28, 2025

Under the Examples section of NTXentLoss, the calculation of loss:

>>> # initialize loss function without memory bank
>>> loss_fn = NTXentLoss(memory_bank_size=0)
>>>
>>> # generate two random transforms of images
>>> t0 = transforms(images)
>>> t1 = transforms(images)
>>>
>>> # feed through SimCLR or MoCo model
>>> batch = torch.cat((t0, t1), dim=0)
>>> output = model(batch)
>>>
>>> # calculate loss
>>> loss = loss_fn(output)   # Correct: loss_fn(out0, out1)

doesn't match the function signature of forward, which requires two input tensors:

def forward(self, out0: Tensor, out1: Tensor) -> Tensor:

Suggested change:

>>> # initialize loss function without memory bank
>>> loss_fn = NTXentLoss(memory_bank_size=0)
>>>
>>> # generate two random transforms of images
>>> t0 = transforms(images)
>>> t1 = transforms(images)
>>>
>>> # feed through SimCLR or MoCo model
>>> out0, out1 = model(t0), model(t1)
>>>
>>> # calculate loss
>>> loss = loss_fn(out0, out1)

Copy link
Contributor

@guarin guarin left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

@guarin guarin enabled auto-merge (squash) January 29, 2025 10:57
Copy link

codecov bot commented Jan 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.24%. Comparing base (a1d755d) to head (2a1ed02).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1789   +/-   ##
=======================================
  Coverage   85.24%   85.24%           
=======================================
  Files         163      163           
  Lines        6833     6833           
=======================================
  Hits         5825     5825           
  Misses       1008     1008           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@guarin guarin merged commit 7f84a56 into lightly-ai:master Jan 29, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants