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

How to specify FastLanguageModel into specific gpu #1513

Open
Hyfred opened this issue Jan 7, 2025 · 2 comments
Open

How to specify FastLanguageModel into specific gpu #1513

Hyfred opened this issue Jan 7, 2025 · 2 comments

Comments

@Hyfred
Copy link

Hyfred commented Jan 7, 2025

In my code, I need to load two models, one specify "cuda:0" one for "cuda:1"
But it doesn't work, my code snippet is shown as below:

`
#. Specify devices for each model
device_model1 = torch.device("cuda:1")
device_model2 = torch.device("cuda:0")
model1, tokenizer = FastLanguageModel.from_pretrained(
model_name = "unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit",
max_seq_length = max_seq_length,
dtype = None,
load_in_4bit = True,
)
model1.to(device_model1)

model2, tokenizer = FastLanguageModel.from_pretrained(
model_name = "unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit",
max_seq_length = max_seq_length,
dtype = None,
load_in_4bit = True,
)
model2.to(device_model2)
`

Any comment would be helpful, thanks!!

@Hyfred
Copy link
Author

Hyfred commented Jan 7, 2025

now the error is:

Exception has occurred: RuntimeError
CUDA error: invalid device ordinal
CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1
Compile with TORCH_USE_CUDA_DSA to enable device-side assertions.
File "/home/a1/unsloth_llama_finetune.py", line 40, in
model1.to(device_model1)
RuntimeError: CUDA error: invalid device ordinal
CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1
Compile with TORCH_USE_CUDA_DSA to enable device-side assertions.

@danielhanchen
Copy link
Contributor

Sorry currently Unsloth does not function on Python runtimes which expose 2 or more GPUs - it's still an active area of developmenet

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

No branches or pull requests

2 participants