Git Product home page Git Product logo

Comments (4)

emadeldeen24 avatar emadeldeen24 commented on May 28, 2024

Hi,
thanks for reporting this. This issue is more related to the CA-TCC work, where we use the SupConLoss.

To summarize what I understood:
you mean that the process of subtracting the maximum value from each row in the anchor_Dot_Contrast tensor can lead to some extremely negative values in the logits tensor, especially when there's a large disparity between the maximum value and other values in a particular row.
As a consequence, the exponential operation (torch.exp(logits)) and (torch.log(exp_logits.sum(1, keepdim=True))), can result in numerical instability, leading to values of NaN for the loss.

I think you are right, and this can be a valid point. We can address it in the implementation in several ways. For example, we can do clamping to the values of logits before performing the exponential operation. This can be to a predefined range.
Another way is to add a small constant before taking the logarithm to prevent the logarithm of a value close to zero.

It would be very beneficial if you can post the whole error message so that I can check and debug it properly.

from ts-tcc.

kkj9333 avatar kkj9333 commented on May 28, 2024

Yes, that's what I mean. During the training process, the loss becomes Nan, resulting in all weights becoming Nan, which will not lead to python errors.
image
But I can provide information on debugging SupConLoss:

  • When entering 'forward':
    image
  • Before subtracting the maximum value:
    image
  • After subtracting the maximum value:
    image
  • exp_logits = torch.exp(logits) * logits_mask After exponential operation, it will become zero.
    image
  • When calculating log_prob, some calculation results become Nan due to -torch. log Nan appeared in the final calculation of the loss:
    image

My current solution is to add 'eps=1e-15' when calculating the row sum of 'exp_logits' to avoid zero. But will this lead to situations where losses cannot converge?

from ts-tcc.

kkj9333 avatar kkj9333 commented on May 28, 2024

If the eps I set is too small, this error message will still appear:
image

from ts-tcc.

kkj9333 avatar kkj9333 commented on May 28, 2024

Thank you for your help! Perhaps I can use some methods to alleviate this problem myself.

from ts-tcc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.