MiniCPM-o icon indicating copy to clipboard operation
MiniCPM-o copied to clipboard

[BUG] MiniCPM-o-2_6-gguf内存和磁盘占用满后一直卡住

Open JV-X opened this issue 1 month ago • 1 comments

是否已有关于该错误的issue或讨论? | Is there an existing issue / discussion for this?

  • [X] 我已经搜索过已有的issues和讨论 | I have searched the existing issues / discussions

该问题是否在FAQ中有解答? | Is there an existing answer for this in FAQ?

  • [X] 我已经搜索过FAQ | I have searched FAQ

当前行为 | Current Behavior

我下载了MiniCPM-o-2_6-gguf/Model-7.6B-Q8_0.gguf模型,然后用llama_cpp_python 加载后尝试问模型进行一些对话,遇到了两个问题,第一个问题是,当我执行这个脚本时候,遇到了TypeError: can only concatenate str (not "list") to str,代码和报错如下: 代码:

# 指定本地模型文件路径
model_path = "/home/hygx/.cache/modelscope/hub/OpenBMB/MiniCPM-o-2_6-gguf/Model-7.6B-Q8_0.gguf"

# 替换为你的图片文件路径
image_path = "/home/hygx/code/MiniCPM-o/assets/worldmap_ck.jpg"

import base64
from llama_cpp import Llama

def image_to_base64_data_uri(file_path):
    with open(file_path, "rb") as img_file:
        base64_data = base64.b64encode(img_file.read()).decode('utf-8')
        return f"data:image/png;base64,{base64_data}"

# 指定本地模型文件路径
llm = Llama(model_path=model_path)

# 替换为你的图片文件路径
data_uri = image_to_base64_data_uri(image_path)

messages = [
    {"role": "system", "content": "You are an assistant who perfectly describes images."},
    {
        "role": "user",
        "content": [
            {"type": "text", "text": "Describe this image in detail please."},
            {"type": "image_url", "image_url": {"url": data_uri}}
        ]
    }
]

response = llm.create_chat_completion(messages)
print(response["choices"][0]["text"])

报错:

# 指定本地模型文件路径
model_path = "/home/hygx/.cache/modelscope/hub/OpenBMB/MiniCPM-o-2_6-gguf/Model-7.6B-Q8_0.gguf"

# 替换为你的图片文件路径
image_path = "/home/hygx/code/MiniCPM-o/assets/worldmap_ck.jpg"

import base64
from llama_cpp import Llama

def image_to_base64_data_uri(file_path):
    with open(file_path, "rb") as img_file:
        base64_data = base64.b64encode(img_file.read()).decode('utf-8')
        return f"data:image/png;base64,{base64_data}"

# 指定本地模型文件路径
llm = Llama(model_path=model_path)

# 替换为你的图片文件路径
data_uri = image_to_base64_data_uri(image_path)

messages = [
    {"role": "system", "content": "You are an assistant who perfectly describes images."},
    {
        "role": "user",
        "content": [
            {"type": "text", "text": "Describe this image in detail please."},
            {"type": "image_url", "image_url": {"url": data_uri}}
        ]
    }
]

response = llm.create_chat_completion(messages)
print(response["choices"][0]["text"])

当我把代码改成下面这样的时候(改了messages变量):

# 指定本地模型文件路径
model_path = "/home/hygx/.cache/modelscope/hub/OpenBMB/MiniCPM-o-2_6-gguf/Model-7.6B-Q8_0.gguf"

# 替换为你的图片文件路径
image_path = "/home/hygx/code/MiniCPM-o/assets/worldmap_ck.jpg"

import base64
from llama_cpp import Llama

def image_to_base64_data_uri(file_path):
    with open(file_path, "rb") as img_file:
        base64_data = base64.b64encode(img_file.read()).decode('utf-8')
        return f"data:image/png;base64,{base64_data}"

# 指定本地模型文件路径
llm = Llama(model_path=model_path)

# 替换为你的图片文件路径
data_uri = image_to_base64_data_uri(image_path)


messages = [
	{"role": "system", "content": "You are an assistant who perfectly describes images."},
	{
		"role": "user",
		"content": "Describe this image in detail please."
	}
]

response = llm.create_chat_completion(messages)
print(response["choices"][0]["text"])

报错消失了,但是我的电脑的内存和磁盘占用飙升,直接占满了,并且程序一直卡在这里,没有生成出结果,我用的是i9-14900KF CPU 和16G内存,我不确定这个模型的配置要求是什么,可以告知一下吗?另外我的第一份代码为什么会报错?

期望行为 | Expected Behavior

能和模型进行对话交互

复现方法 | Steps To Reproduce

No response

运行环境 | Environment

- OS: Windows 11 with WSL2
- Python:3.10
- Transformers:4.44.2
- PyTorch:2.2.0
- CUDA (`python -c 'import torch; print(torch.version.cuda)'`):12.1
- CPU: i9-14900 KF 
- 内存: 16GB

备注 | Anything else?

No response

JV-X avatar Jan 16 '25 02:01 JV-X