llm_agent

This commit is contained in:
2025-04-15 09:26:24 +08:00
parent ad850221c5
commit 9400ae904a
25 changed files with 52650 additions and 39 deletions

25
minicpm.py Normal file
View File

@ -0,0 +1,25 @@
# Load model directly
from transformers import AutoModel, AutoTokenizer
import torch
from PIL import Image
model = AutoModel.from_pretrained(
"openbmb/MiniCPM-o-2_6",
trust_remote_code=True,
attn_implementation='flash_attention_2',
torch_dtype=torch.bfloat16,
# device_map="auto"
)
model = model.eval().cuda()
tokenizer = AutoTokenizer.from_pretrained('openbmb/MiniCPM-o-2_6', use_fast=True, trust_remote_code=True)
img1 = Image.open('/home/ieemoo0337/projects/datasets/constrast_pair/8850813311020/8850813311020.jpg')
img2 = Image.open('/home/ieemoo0337/projects/datasets/constrast_pair/8850511321499/8850511321499.jpg')
question = '描述第一张图像的1。'
msgs = [{'role': 'user', 'content': [img1, img2, question]}]
answer = model.chat(
msgs=msgs,
tokenizer=tokenizer
)
print(answer)