-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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
[Tracker] [bnb] Supporting device_map
containing GPU and CPU devices
#19090
Comments
UPDATE (for future readers): the title was changed. I think that the title of this issue is a little bit misleading. Technically, a custom For example, in the linked issue, this device_map = {
"transformer.wte": 0,
"transformer.wpe": 0,
"transformer.ln_f": 0,
"lm_head": 0,
"transformer.h.0": 0,
"transformer.h.1": 0,
"transformer.h.2": 0,
"transformer.h.3": 0,
"transformer.h.4": 0,
"transformer.h.5": 0,
"transformer.h.6": 0,
"transformer.h.7": 0,
"transformer.h.8": 0,
"transformer.h.9": 0,
"transformer.h.10": 0,
"transformer.h.11": 0
} And I believe that there will be no problem in using The original issue was not about a custom map. It was about supporting the |
device_map
device_map
containing GPU and CPU devices
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread. Please note that issues that do not follow the contributing guidelines are likely to be ignored. |
unstale |
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread. Please note that issues that do not follow the contributing guidelines are likely to be ignored. |
unstale I guess this will be my monthly routine... |
Hi |
I've just tested that PR and it works. Thank you! I tested it with a 13B model on GTX 3060. Without For some reason when I test it on my initial example, it gives this warning:
However, I was not able to reproduce it in my other more complex program. In the PR's discussion it was said:
I expected this much, but I think it's still better than nothing. Though, are there some gotchas in the fact that CPU layers are not converted to 8bit? Also, not sure how to proceed next. You said:
So I suppose this issue should remain open? I will then add more info to my initial issue at the |
Thank you very much for your feedback and happy that it worked for your usecase!
This is because you have set your
I did not quite get your question here, but CPU layers are kept in their native
Yes, it can remain open. But feel free also to jump in the PR #20281 to give your opinion on the question and stress about the fact that you think this feature is useful. You can also add more information on the |
I use the following code: pipe = pipeline(
model="EleutherAI/gpt-neo-125M",
max_length=32,
model_kwargs={
"device_map": device_map,
"load_in_8bit": load_in_8bit
}
)
print("\n", pipe("It was")[0]["generated_text"]) Not sure where I am supposed to set
I mean, purely from a technical standpoint, are there some downsides to mixing 8bit and 16/32bit layers? |
Thanks for sharing the code! It's clearer for me now, can you try to add
Indeed, from a technical standpoint I don't see any downside |
When I add
The full code for clarity: from transformers import pipeline
auto_map = False
load_in_8bit = True
if auto_map:
device_map = "auto"
else:
device_map = {
"transformer.wte": 0,
"transformer.wpe": 0,
"transformer.ln_f": "cpu",
"lm_head": 0,
"transformer.h.0": 0,
"transformer.h.1": "cpu",
"transformer.h.2": "cpu",
"transformer.h.3": "cpu",
"transformer.h.4": "cpu",
"transformer.h.5": "cpu",
"transformer.h.6": "cpu",
"transformer.h.7": "cpu",
"transformer.h.8": "cpu",
"transformer.h.9": "cpu",
"transformer.h.10": "cpu",
"transformer.h.11": "cpu"
}
pipe = pipeline(
model="EleutherAI/gpt-neo-125M",
device=0,
max_length=32,
model_kwargs={
"device_map": device_map,
"load_in_8bit": load_in_8bit
}
)
print("\n", pipe("It was")[0]["generated_text"]) The error occurs even when Also, in any case, the original error is pretty confusing. It says |
Thanks for sharing, I think it is fine, for now I would say that you can leave the pipeline without the reason it says |
I know, but to an end user it still will not be immediately clear what the problem is just by reading that error message. It also says how to fix it:
But it's absolutely not applicable in this situation, adding even more confusion. Maybe the call to |
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread. Please note that issues that do not follow the contributing guidelines are likely to be ignored. |
unstale Also, I added some comments in the PR discussion: |
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread. Please note that issues that do not follow the contributing guidelines are likely to be ignored. |
unstale Technically, I personally don't need this fix anymore, since in my project I applied the hack described in the PR. |
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread. Please note that issues that do not follow the contributing guidelines are likely to be ignored. |
This should be solved by the introduction of |
Yes, indeed it works. Thank you, @younesbelkada! For completeness sake, here's the final working version: import torch
from transformers import BitsAndBytesConfig, pipeline
device_map = {
"transformer.wte": 0,
"transformer.wpe": 0,
"transformer.ln_f": "cpu",
"lm_head": 0,
"transformer.h.0": 0,
"transformer.h.1": "cpu",
"transformer.h.2": "cpu",
"transformer.h.3": "cpu",
"transformer.h.4": "cpu",
"transformer.h.5": "cpu",
"transformer.h.6": "cpu",
"transformer.h.7": "cpu",
"transformer.h.8": "cpu",
"transformer.h.9": "cpu",
"transformer.h.10": "cpu",
"transformer.h.11": "cpu"
}
quantization_config = BitsAndBytesConfig(
load_in_8bit=True,
llm_int8_enable_fp32_cpu_offload=True,
llm_int8_skip_modules=["lm_head"]
)
pipe = pipeline(
model="EleutherAI/gpt-neo-125M",
max_length=32,
torch_dtype=torch.float16,
model_kwargs={
"device_map": device_map,
"quantization_config": quantization_config
}
)
print("\n", pipe("It was")[0]["generated_text"]) |
Feature request
We should be able to provide custom
device_map
when using 8-bit models usingbitsandbytes
. This would enable users having more control over the modules they want to quantize.Linked issue: bitsandbytes-foundation/bitsandbytes#40
Motivation
Users should be able to pass their own custom
device_map
and chose which module should be quantized or notYour contribution
Try coding this enhancement!
The text was updated successfully, but these errors were encountered: