You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import torch
if torch.cuda.is_available():
print(f"GPU: {torch.cuda.get_device_name(0)} is available and will be used.")
else:
print("CUDA is not available. CPU will be used.")
dash_line = '-'.join('' for x in range(100))
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
from datasets import load_dataset
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, GenerationConfig, TrainingArguments, Trainer
from peft import LoraConfig, get_peft_model, TaskType
import torch
import time
import evaluate
import pandas as pd
import numpy as np
Q. Why?
A. When working with the large variant of the model for prediction, PyTorch doesn't use the GPU, so I had to manually move it with .to('cuda'). To avoid having to move everything manually (tokenizer, dataset, model) I started using the with device syntax. Now I'm trying to train it using PEFT with LoRA, and as my GPU has only 4GB VRAM, I used the base variant this time, keeping the manual specification for the device to be used but the error shown happens.
Q: Does it work if I remove it:
A: It actually works, even when setting the device to CPU, PyTorch somehow ignores it and can, with the base variant of the model, automatically use the GPU as saw in nvidia-smi using about 3.8 GB VRAM when running the script.
So IDK why sometimes PyTorch automatically uses the GPU, others not, but for some reason when trying to force it to use the GPU with PEFT LoRa, the error happens.
For now I'm just relying on the automatic device detection. But I still think there's something not working properly somewhere.
System Info
Transformers 4.41.2
PyTorch 2.3.1+cu121
Python 3.12.3
Ubuntu 24.04
GPU: NVIDIA GeForce GTX 1650
Who can help?
No response
Information
Tasks
examples
folder (such as GLUE/SQuAD, ...)Reproduction
`%pip install --quiet torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
%pip install --quiet -U datasets
%pip install --quiet torchdata
%pip install --quiet setuptools
%pip install --quiet transformers
%pip install --quiet evaluate
%pip install --quiet rouge_score
%pip install --quiet loralib
%pip install --quiet peft
%pip install --quiet ipywidgets
The code shown above throws Expected a 'cuda' device type for generator but found 'cpu'
Expected behavior
Should not throw the error as the entire code is running under "with torch.device(device):" with device='cuda'
The text was updated successfully, but these errors were encountered: