Comments (3)
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.
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.
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)
- Is it advisable to avoid variable shadowing when using Candle?
- candle-flash-attn infinite compile time HOT 1
- Model Context Not Resetting Between Requests Leading to Invalid Responses
- Tensor not dropped after another tensor was assigned to variable in cuda HOT 3
- Mamba model is broken with `f16` precision HOT 1
- Slow YOLOv8 using MKL
- candle examples fail on cuda with CUDA_DEVICE_NO_ERROR. Device caps of 7.5 HOT 2
- Parler TTS support?
- Positional encoding in DINOv2: Case without interpolation
- new model : DINOv2 reg4 with weights from PlantCLEF 2024 HOT 1
- Retrieving softmax_lse in candle-flash-attn HOT 1
- load_image and load_image_and_resize return different permutations
- How to get raw tensor data? HOT 2
- Qwen/Qwen2-7B doesn't work properly in the example qwen
- Gemma 2 support HOT 2
- Add `QTensor::quantize_onto` to remove a redundant dtoh copy?
- some token duplicated in candle-examples trocr
- Change single value of tensor HOT 3
- Indexing the first dim of a 2D tensor with a 1D tensor HOT 2
- How to get all layers attentions?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from candle.