Skip to content
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

bitsandbytes compatibility (#163 #163

Merged
merged 3 commits into from
Feb 8, 2023
Merged

bitsandbytes compatibility (#163 #163

merged 3 commits into from
Feb 8, 2023

Conversation

gsarti
Copy link
Member

@gsarti gsarti commented Feb 3, 2023

Description

With bitsandbytes v0.37.0 Int8 matmul backward is officially supported. For Inseq, this means that all gradient-based methods become viable for 8-bit models (addressing points raised in #141 and bitsandbytes-foundation/bitsandbytes#67).

Example usage (tested from this branch and transformers==4.27.0.dev0) with T5-11b in a Google Colab session with 15Gb GPU RAM:

!pip install --quiet bitsandbytes
!pip install git+https://github.com/huggingface/transformers.git
!pip install --quiet --upgrade accelerate
!pip install --quiet sentencepiece
!pip install --quiet git+https://github.com/inseq-team/inseq@8bit-compatibility

import inseq
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer

model_id=f"ybelkada/t5-11b-sharded"

tokenizer = AutoTokenizer.from_pretrained(model_id)
model_8bit = AutoModelForSeq2SeqLM.from_pretrained(model_id, device_map="auto", load_in_8bit=True)

t5_xxl = inseq.load_model(model_8bit, "saliency", tokenizer=model_id)
out = t5_xxl.attribute(
    "translate English to German: Inseq now supports saliency attribution with 8-bit models!"
)

The main fix to enable interoperability is to prevent casting the model to default device if it is loaded in int8.

@gsarti gsarti added this to the 0.3.4 milestone Feb 3, 2023
@gsarti gsarti linked an issue Feb 3, 2023 that may be closed by this pull request
@gsarti gsarti added the enhancement New feature or request label Feb 3, 2023
@gsarti gsarti changed the title bitsandbytes compatibility bitsandbytes compatibility (#163 Feb 8, 2023
@gsarti gsarti merged commit 6bbc5f8 into main Feb 8, 2023
@gsarti gsarti deleted the 8bit-compatibility branch February 24, 2023 08:16
@gsarti gsarti added this to the v0.5 milestone Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test case for larger (prompting-based) language models (+ LLM.int8())
1 participant