![](http://ac.namu.la/20230322sac/9429c77a19766a570dc7ab23560fde627a7b1d4462aac758212dfedd1e19638e.jpg?expires=1719795600&key=T03PWk5S-ziLtVwjXb_mHQ)
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:1 and cuda:0!
라는 에러가 뜨는 상황입니다.
unsloth이 아닌 상황에서 모델을 훈련할 때는 다음과 같이 device map을 하나로 고정시켜서 해결했습니다.
# Load model
model = AutoModelForCausalLM.from_pretrained(
base_model,
quantization_config=bnb_config,
device_map=torch.device("cuda:0"), # 작업 일관성 문제로 device 0으로 고정
attn_implementation=attn_implementation)
model = AutoModelForCausalLM.from_pretrained(
base_model,
quantization_config=bnb_config,
device_map=torch.device("cuda:0"), # 작업 일관성 문제로 device 0으로 고정
attn_implementation=attn_implementation)
)
그런데 unsloth은 예제 코드에도 해당 부분을 설정하는 부분이 없는 듯 합니다.
from unsloth import FastLanguageModel
import torch
max_seq_length = 4096 # Choose any! We auto support RoPE Scaling internally!
dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.
import torch
max_seq_length = 4096 # Choose any! We auto support RoPE Scaling internally!
dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = "/model/llama/llama-3-8b",
max_seq_length = max_seq_length,
dtype = dtype,
load_in_4bit = load_in_4bit,
device_map=torch.device("cuda:0"), # 제가 임의로 추가해서 시도도 해봤지만 결과는 같았습니다.
)
model_name = "/model/llama/llama-3-8b",
max_seq_length = max_seq_length,
dtype = dtype,
load_in_4bit = load_in_4bit,
device_map=torch.device("cuda:0"), # 제가 임의로 추가해서 시도도 해봤지만 결과는 같았습니다.
)
계속 train을 적은 100개 샘플로 돌려가며 미세 파인튜닝을 시도하려는게 목적입니다.
처음에는 wandb랑 연결했을 때 오류가 발생하고 연결 안했을 때 발생하지 않아서 해당 부분을 종료하고 작업해서 해결했습니다만
이젠 wandb와 상관없이 처음 한 번 작동하고 이제 다시 train하려면 저 오류 해결없이는 trainer.train() 을 수행조차 못하네요.
device map 일치 방법이 해결책으로 알고있는데 이에 대한 방법이나 혹시 이 외의 다른 방법을 알고 계신 분의 도움을 요청합니다.