InternLM / InternLM/InternLM-XComposer
Cuda error When I try muti gpu inference(+lora).
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 175
- PR merge metrics
- No merged PRs in 30d
Description
A cuda error occurs when loading a model using lora and executing muti gpu inference.
Below is the code I used.
```
import sys
sys.path.insert(0, '.')
sys.path.insert(0, '..')
import argparse
import torch
from transformers import AutoModel, AutoTokenizer
from examples.utils import auto_configure_device_map
from peft import PeftConfig, PeftModel
from transformers import AutoModelForCausalLM
torch.set_grad_enabled(False)
parser = argparse.ArgumentParser()
parser.add_argument("--num_gpus", default=1, type=int)
parser.add_argument("--dtype", default='fp16', type=str)
args = parser.parse_args()
ckpt_lora = "/home/jovyan/insik/LVLM/InternLM-XComposer/finetune/output/finetune/checkpoint-312/"
tokenizer = AutoTokenizer.from_pretrained(ckpt_lora, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(ckpt_lora, low_cpu_mem_usage=True, torch_dtype=torch.float16, device_map="auto", trust_remote_code=True).eval()
# init model and tokenizer
if args.dtype == 'fp16':
model.half().cuda()
elif args.dtype == 'fp32':
model.cuda()
if args.num_gpus > 1:
from accelerate import dispatch_model
device_map = auto_configure_device_map(args.num_gpus)
model = dispatch_model(model, device_map=device_map)
tokenizer = AutoTokenizer.from_pretrained('/home/jovyan/insik/LVLM/internlm-xcomposer2-vl-7b', trust_remote_code=True)
text = ' What units are on the screen now?.'
image = '/home/jovyan/cr_test.png'
with torch.cuda.amp.autocast():
response, _ = model.chat(tokenizer, query=text, image=image, history=[], do_sample=False)
print(response)
```
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:3 and cuda:0! (when checking argument for argument weight in method wrapper_CUDA__cudnn_convolution)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.