GithubHelp home page GithubHelp logo

Comments (3)

LaurentMazare avatar LaurentMazare commented on July 18, 2024

I don't think there are much guarantees on the values being exactly equal on both sides. Especially when using bfloat16, there are only 8 bits for the mantissa so if the error is of the order of a percent that would be somewhat expected.
Things that could be worth checking:

  • How much is the error when using f32 on both sides?
  • What happens without biases, the error being in the same column might indicate that this is the culprit and it may be caused by pytorch fusing the add and mul part whereas candle doesn't do it for now.
  • Are the f32 to bf16 conversions in line between both sides? (using a safetensors rather than npy would allow storing the bf16 tensors)

from candle.

EricLBuehler avatar EricLBuehler commented on July 18, 2024

Thank you for giving me those tips, I think I figured out what the problem is:

How much is the error when using f32 on both sides?

About the same, there is no change to the output.

What happens without biases, the error being in the same column might indicate that this is the culprit and it may be caused by pytorch fusing the add and mul part whereas candle doesn't do it for now.

It turns out that I only do a matmul and then add the bias separately, the 2 tensors are the same in the output! So when we folow the xW^T + B strictly (as Candle does) in Pytorch, the output is the same.

Would it be possible to add this fusion of add and mul to Candle too, as it would fix this? Alternatively, is there something which I can do to fix this? Thank you so much!

from candle.

EricLBuehler avatar EricLBuehler commented on July 18, 2024

I wrote some code to test fusion using cuBLASLT with a FusedLinearBias layer: https://github.com/EricLBuehler/mistral.rs/blob/44e8a2291d6d53fa125907925c0a4cc613cb8855/mistralrs-core/src/layers.rs#L401-L451

This gets rid of the error. Would you be interested in me submitting a PR to add the fused-linear-bias support directly to Linear?

from candle.

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.