-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
Gemma2: RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:7 and cuda:0! (when checking argument for argument index in method wrapper_CUDA__index_select) #34706
Comments
Can you take a look at this @SunMarc or @MekkCyber ? |
v4.43.4 doesn't have the issue |
Hi @LysandreJik , this potential feature regression in Transformers have caused issues in our library (NVIDIA TensorRT Model Optimizer) when our users want to run quantization on multi-GPUs. Currently, our users need to revert back to Transformers v4.43.4. We appreciate if you can help prioritize this. Thanks! |
Hi @hchings @Terrencezzj, thanks for specifying that v4.43.4 does work, I am looking into the problem |
Hi, I found that there was no accelerate config. You can create an accelerate config file with multigpu config and try running the below hoping you loaded the model and tokenizer before. Refer here to create config.yaml file to support multiGPU Inference
|
Hi, I got the same error with Accelerator. Please noticed that my script was not inference, it's |
The issue arises from how |
In case this is relevant, if the model is in training mode, it seems to work from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = 'google/gemma-2-2b'
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
model.train()
messages = "Any Context"
input_ids = tokenizer.encode(messages, return_tensors="pt").to("cuda")
gen_tokens = model(input_ids) |
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 issue has not been resolved. |
Can confirm that this is still an issue. Exception is raised when I run this (almost same as example from docs, only changed model from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b")
model = AutoModelForCausalLM.from_pretrained(
"google/gemma-2-9b",
device_map="auto",
)
input_text = "Write me a poem about Machine Learning."
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
outputs = model(**input_ids) Using System Info
@MekkCyber should I create an issue on |
This should be fixed by this PR from @zucchini-nlp ! Please give it a try cc @alexrs-cohere |
@alexrs-cohere sorry my mistake, the issue with |
The issue is still not fixed. I reused the code from @aklemen using "google/gemma-2-2b": from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-2b")
model = AutoModelForCausalLM.from_pretrained(
"google/gemma-2-2b",
device_map="auto",
)
input_text = "Write me a poem about Machine Learning."
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
outputs = model(**input_ids) Error:
System Info
|
@HichemAK the fix was not part of the last release, so you can install from |
Oh my bad ! Thank you for the response |
Maybe I am missing a something but using from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-2b")
model = AutoModelForCausalLM.from_pretrained(
"google/gemma-2-2b",
device_map="auto",
)
input_text = "Write me a poem about Machine Learning."
input_ids = tokenizer(input_text, return_tensors="pt").to(model.device) # <---- Change here
outputs = model(**input_ids) |
System Info
transformers
version: 4.47.0.dev0Who can help?
No response
Information
Tasks
examples
folder (such as GLUE/SQuAD, ...)Reproduction
Expected behavior
If set one gpu visible, no error
The text was updated successfully, but these errors were encountered: