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

[Accelerator] Fix issue with 8bit models #1155

Merged
merged 7 commits into from
Mar 8, 2023

Conversation

younesbelkada
Copy link
Contributor

@younesbelkada younesbelkada commented Mar 6, 2023

What does this PR do?

Fixes #1147

In theory it is not possible to fine-tune 8-bit models except if you use adapters that can be used only is a PeftModel is used for training (I also need to test the snippet below with a PeftModel to make sure this is relevant or not). EDIT: passing an 8bit PeftModel through accelerator.prepare seems to work fine.

But in some systems you can use the accelerator to load an 8bit model and use it out of the training scope (e.g. get the model's logits and use it in another model)

I am not sure if we should support 8-bit models using Accelerator, but if so, I propose the following changes in this PR
Happy also to revert the tests / bnb dependency

To reproduce:

import torch
import torch.nn.functional as F

from transformers import AutoModelForCausalLM
from datasets import load_dataset
from accelerate import Accelerator

model = AutoModelForCausalLM.from_pretrained(
    "EleutherAI/gpt-neo-125m",
    load_in_8bit=True,
    device_map="balanced",
)

accelerator = Accelerator()


model = accelerator.prepare(model)

cc @sgugger

Ran all the slow tests and got errors on DeepSpeed and FSDP tests but not sure if the failing is related to my PR

Screenshot 2023-03-06 at 18 24 12

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Mar 6, 2023

The documentation is not available anymore as the PR was closed or merged.

@younesbelkada
Copy link
Contributor Author

younesbelkada commented Mar 6, 2023

I think this PR is only necessary in case people want to design systems that uses 8-bit models in their training loop without backpropagating on the 8-bit model (for example in RLHF), as using adapters works already out of the box right now

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

src/accelerate/accelerator.py Outdated Show resolved Hide resolved
Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
Comment on lines +188 to +190
model = AutoModelForCausalLM.from_pretrained(
"EleutherAI/gpt-neo-125m", device_map=device_map, load_in_8bit=True, llm_int8_enable_fp32_cpu_offload=True
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sgugger I think this will fail as the docker image is not using the main branch of transformers no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

happy to skip it until the next release of transformers

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we are not installing from source.

@younesbelkada younesbelkada marked this pull request as ready for review March 8, 2023 13:21
Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incompatible with 8bit models
3 participants