-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add Support for BitNet Architecture Inference #2664
base: main
Are you sure you want to change the base?
Add Support for BitNet Architecture Inference #2664
Conversation
Signed-off-by: José Carlos García <[email protected]>
Signed-off-by: José Carlos García <[email protected]>
Signed-off-by: José Carlos García <[email protected]>
The bit-linear tests that you added seem to be broken, would you mind having a look? |
Signed-off-by: José Carlos García <[email protected]>
Done! @LaurentMazare |
Thanks, could you also provide details on how the model results were lined up with the python implementation? Did you ensure that the logits generated by the candle version are somewhat in line? |
@LaurentMazare Everything stems from: The Era of 1-bit LLMs - Training Tips, Code, FAQ Since the inference for Llama and Linear was already implemented in this project, I used the existing Llama implementation as a foundation and applied the following changes, based on the paper and as seen here:
In principle, unless I’m mistaken, everything seems consistent with the Python implementation. You can test it in situ as follows: cargo run --example llama-bitnet --features metal Thank you so much for reviewing! |
In order to check the consistency, the best would be to generate the logits for the same prompt on the candle and python side and check that they are reasonably close. That's what we do for most models before adding them, would you mind giving it a try? |
Since this is my first contribution, I don't have much experience with this, but it seems that the logits from the Python implementation and my implementation are similar: I used the code from this link in Python, and in the code I created, I added a print of the logits (in Candle) and a print of the Here’s what I observed: Candle: Python: They seem equivalent, except for numerical error. |
I have been checking and the transformers library does not have support for these models, however, using the code from the model repository, it generates the same logits. |
I'd love to see this support the just released Falcon3 1.58bit model :) |
Not working with this model! I'll check asap :) Thank you for reporting it! @codesoda |
Signed-off-by: José Carlos García <[email protected]>
@JoseCarlosGarcia95 Great work, and thank you for this. I don't want to slow down the completion of this PR, but it should be noted somewhere that this PR does not work when loading the model from a |
Signed-off-by: José Carlos García <[email protected]>
@noppej Thank you! I’m currently working on adding support for quantized models in parallel. The models available at https://huggingface.co/tiiuae/Falcon3-1B-Instruct-1.58bit and https://huggingface.co/HF1BitLLM/Llama3-8B-1.58-100B-tokens/tree/main are already quantized, so this PR isn’t compatible with them. My goal is to create a separate PR to support both models and also include support for the methods outlined here: https://github.com/microsoft/BitNet/tree/main. |
I hope you’re doing well. I wanted to kindly follow up on this PR to see if there’s anything else needed from my side to facilitate the review or integration. Thank you again for your time and support, and I look forward to hearing back! |
Fyi #2683 |
Introduction
Hello! My name is José Carlos, and I hold a degree in Mathematics. Alongside other talented individuals, I co-founded a company where we focus on AI and infrastructure solutions.
I’ve always believed that BitNet is one of the most significant breakthroughs of the past year. I have a personal obsession with this architecture, as it embodies the potential to balance performance and efficiency in language models—a pursuit that deeply motivates me.
Changes Made
Added Support for BitNet Architecture Inference:
New Example Added:
Supported HF Models:
The following models were tested successfully:
"1bitLLM/bitnet_b1_58-large"
: BitNet B1 58 Large."1bitLLM/bitnet_b1_58-3B"
: BitNet B1 58 3B.Future support will be added for:
"HF1BitLLM/Llama3-8B-1.58-100B-tokens"
: Llama 3 (8B, 1.58).Known Limitations
I plan to address these in future updates and prepare a PR with:
Roadmap
Thank you for considering this PR! Feedback is welcome, and I’m excited to continue contributing to this amazing project. 😊