Vision-CAIR / MiniGPT-4

Open-sourced codes for MiniGPT-4 and MiniGPT-v2 (https://minigpt-4.github.io, https://minigpt-v2.github.io/)
https://minigpt-4.github.io
BSD 3-Clause "New" or "Revised" License
25.33k stars 2.91k forks source link

for people who want to use CPU #73

Open laoda512 opened 1 year ago

laoda512 commented 1 year ago

讲一下cpu的推理思路,大概需要60gb内存和6g显存 首先删掉对于gpuid的要求,或者干脆不传 parser.add_argument("--gpu-id", help="specify the gpu to load the model.")

所有用到--gpu-id的地方换成device='cpu' model = model_cls.from_config(model_config)#.to('cpu').to('cuda:{}'.format(args.gpu_id)) ... chat = Chat(model, vis_processor, device='cpu')#'cuda:{}'.format(args.gpu_id))

然后是这个文件中把gpu都换成cpu,但是原来有些模型是加载到cpu的,内存可能会吃不住,现在可以加载的gpu了 image

只是一个简单暴力修改,不确定有没有问题,就不提pr了,大家自己改吧

First, in demo.py remove the requirement for --gpu-id or just don't pass it at all,Replace all occurrences of --gpu-id with device='cpu'

Then, in the minigpt4/models/mini_gpt4.py, replace all instances of "gpu" with "cpu". However, some models were originally loaded onto the CPU, and the memory may not be sufficient. Now that the GPU can be used, it may be helpful to load the models onto the GPU instead

kenneth104 commented 1 year ago

谢谢提供思路,改好了,但由于服务器没有显卡,没有将CPU部分改为GPU。。 运行出错,还是有某些地方依赖CUDA

/www/anaconda3/envs/minigpt4/lib/python3.9/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: libtorch_cuda_cu.so: cannot open shared object file: No such file or directory warn(f"Failed to load image Python extension: {e}") Traceback (most recent call last): File "/www/MiniGPT-4/demo.py", line 10, in from minigpt4.common.config import Config File "/www/MiniGPT-4/minigpt4/init.py", line 15, in from minigpt4.datasets.builders import * File "/www/MiniGPT-4/minigpt4/datasets/builders/init.py", line 8, in from minigpt4.datasets.builders.base_dataset_builder import load_dataset_config File "/www/MiniGPT-4/minigpt4/datasets/builders/base_dataset_builder.py", line 21, in from minigpt4.processors.base_processor import BaseProcessor File "/www/MiniGPT-4/minigpt4/processors/init.py", line 9, in from minigpt4.processors.blip_processors import ( File "/www/MiniGPT-4/minigpt4/processors/blip_processors.py", line 12, in from minigpt4.processors.randaugment import RandomAugment File "/www/MiniGPT-4/minigpt4/processors/randaugment.py", line 8, in import cv2 File "/www/anaconda3/envs/minigpt4/lib/python3.9/site-packages/cv2/init.py", line 181, in bootstrap() File "/www/anaconda3/envs/minigpt4/lib/python3.9/site-packages/cv2/init.py", line 153, in bootstrap native_module = importlib.import_module("cv2") File "/www/anaconda3/envs/minigpt4/lib/python3.9/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) ImportError: libGL.so.1: cannot open shared object file: No such file or directory

rdkmaster commented 1 year ago

@laoda512 请问你有实操成功了没?CPU易得,GPU难求啊,我们也有类似痛点。

rdkmaster commented 1 year ago

@kenneth104 有进展没?后来是怎么解决这个问题的?

laoda512 commented 1 year ago

额,纯cpu我没试过,但是我觉得不把原来放cpu的改gpu应该就可以了。 @kenneth104 的问题我不清楚,但我看错误似乎是用了依赖gpu库的环境,应该有对位的cpu库的,可以试试删了重装

zxcvbn114514 commented 1 year ago

大佬,有没有什么办法可以把vits也放进gpu,或者放到第二块GPU上?我现在3090要1分钟才能对话一句,功耗最高才70w,显存占用也没达到预定的23g,而是17g

zxcvbn114514 commented 1 year ago

大佬,我是把图中的vit啥的都放到显卡中运行了,但是任务管理器显示处理的时候cpu的负载仍然很大,显卡都不怎么动。请问这是啥情况啊,有没有改善的方法

quartets commented 1 year ago

我的v100+32g Vram,在默认参数下跑13b对话很慢。我按指南里这句话进行了修改: 对于更强大的GPU,您可以在配置文件minigpt4_eval.yaml中将low_resource设置为False并使用更大的搜索宽度以16位运行模型。

改完参数后,对话基本上在3·5秒就回复我了。gpu和显存占用率提高了20%,还绰绰有余。

zxcvbn114514 commented 1 year ago

我的v100+32g Vram,在默认参数下跑13b对话很慢。我按指南里这句话进行了修改: 对于更强大的GPU,您可以在配置文件minigpt4_eval.yaml中将low_resource设置为False并使用更大的搜索宽度以16位运行模型。

改完参数后,对话基本上在3·5秒就回复我了。gpu和显存占用率提高了20%,还绰绰有余。

v100 32g吗? 3090放不下啊😂