Coder Social home page Coder Social logo

kd_loss implementation issue about ld HOT 9 OPEN

ZaberKo avatar ZaberKo commented on August 28, 2024
kd_loss implementation issue

from ld.

Comments (9)

HikariTJU avatar HikariTJU commented on August 28, 2024

I remeber that .mean(1) is equal to reduction='batch_mean‘ ?

from ld.

ZaberKo avatar ZaberKo commented on August 28, 2024

I remeber that .mean(1) is equal to reduction='batch_mean‘ ?

Here is the source code of F.kl_div:
https://github.com/pytorch/pytorch/blob/defa0d3a2d230e5d731d5c443c1b9beda2e7fd93/torch/nn/functional.py#L2949-L2958

And the problem here is that the kd_loss is subsequently averaged by @weighted_loss wrapper.

from ld.

HikariTJU avatar HikariTJU commented on August 28, 2024

So batch_mean equals .mean(0)?

from ld.

ZaberKo avatar ZaberKo commented on August 28, 2024

So batch_mean equals .mean(0)?

No. "batchmean" means .sum()/batch_size, i.e., .sum(1).mean()

from ld.

HikariTJU avatar HikariTJU commented on August 28, 2024

OK, I get your point, you mean mathmatically .sum(1) is the correct implementation and .mean(1)=.sum(1)/16
That's true, but how is it related to batchmean?

from ld.

ZaberKo avatar ZaberKo commented on August 28, 2024

OK, I get your point, you mean mathmatically .sum(1) is the correct implementation and .mean(1)=.sum(1)/16 That's true, but how is it related to batchmean?

BTW, I also found that loss_ld used weighted sum and was not divided by avg_factor (i.e. sum of weights). Is this a typo or intended behavior for not using normalization?

from ld.

ZaberKo avatar ZaberKo commented on August 28, 2024

FYI: I record the factor ratio avg_factor/(self.reg_max+1) during the training. Maybe it will help this discussion.

image

from ld.

HikariTJU avatar HikariTJU commented on August 28, 2024

It's a intended behavior because experiment shows not dividing is better. Don't know the theory behind this though

from ld.

ZaberKo avatar ZaberKo commented on August 28, 2024

It's a intended behavior because experiment shows not dividing is better. Don't know the theory behind this though

I see, thanks for the reply.

from ld.

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.