恒美微站
首页
关于我们
建站服务
主题模板
案例展示
资讯中心
联系我们
如何用InternVL3-2B-AWQ做图像问答:从单图描述到多轮对话的5个实用示例
首页
资讯中心
/
如何用InternVL3-2B-AWQ做图像问答:从单图描述到多轮对话的5个实用示例
如何用InternVL3-2B-AWQ做图像问答:从单图描述到多轮对话的5个实用示例
发布时间:2026/10/17 5:59:32
【免费下载链接】InternVL3-2B-AWQ项目地址https://ai.gitcode.com/OpenGVLab/InternVL3-2B-AWQ点击查看免费下载InternVL3-2B-AWQ是一款轻量级多模态大语言模型MLLM的 4-bit AWQ 量化版本专为图像问答、单图描述、多图对比和多轮对话场景设计。它由视觉编码器 InternViT、MLP 投影器和语言模型 Qwen2.5-1.5B 组成遵循 ViT-MLP-LLM 架构AWQ 量化让它在显存占用大幅降低的同时保留接近全精度的图像理解能力。本文用 5 个实用示例带你从单图一句话描述一步步走到多图多轮对话全程只需 transformers 和几行 Python 代码。一、为什么选 InternVL3-2B-AWQ 做图像问答特性说明 AWQ 4-bit 量化bits4, group_size128显存占用约为 16-bit 版本的 1/4️ 动态分辨率图像按 448×448 切片最多支持 12 块 缩略图️ 多轮对话通过history参数维护上下文 多模态能力支持单图、多图、视频帧问答在 config.json 中可以看到关键量化配置quantization_config: { bits: 4, group_size: 128, quant_method: awq }对话模板由 conversation.py 提供模板名为internvl2_5而对话入口chat()方法定义在 modeling_internvl_chat.py 中。二、快速加载模型一段代码跑起来使用transformers4.37.2加载 AWQ 量化版本只需几行import torch from transformers import AutoTokenizer, AutoModel model AutoModel.from_pretrained( OpenGVLab/InternVL3-2B-AWQ, torch_dtypetorch.bfloat16, low_cpu_mem_usageTrue, use_safetensorsTrue, trust_remote_codeTrue).eval().cuda() tokenizer AutoTokenizer.from_pretrained( OpenGVLab/InternVL3-2B-AWQ, trust_remote_codeTrue, use_fastFalse) 加载前请确认已安装autoawq与transformers否则量化权重无法正确加载。图像预处理逻辑动态切片 448px 归一化可在 README 的 Quick Start 一节找到归一化均值/方差与 preprocessor_config.json 保持一致image_mean: [0.485, 0.456, 0.406], image_std: [0.229, 0.224, 0.225], size: 448下面所有示例都会复用load_image()负责把图片切成 tile 并转成pixel_values和统一的生成配置generation_config dict(max_new_tokens1024, do_sampleTrue)三、5 个实用示例从单图描述到多轮对话示例 1单图简要描述——最基础的图像问答把图片转成pixel_values再在问题里加上image占位符模型就会自动看图说话pixel_values load_image(./examples/image1.jpg, max_num12).to(torch.bfloat16).cuda() question image\nPlease describe the image shortly. response model.chat(tokenizer, pixel_values, question, generation_config) print(fUser: {question}\nAssistant: {response})要点image占位符会被替换为视觉 tokenimgIMG_CONTEXT.../IMG_CONTEXT/img替换逻辑见 modeling_internvl_chat.py。如果问题里没写imagechat()方法会自动在开头补上。示例 2单图多轮对话——围绕同一张图连续追问多轮对话的关键是return_historyTrue它会返回上文的(question, response)列表下一轮直接传入即可。# 第一轮详细描述 question image\nPlease describe the image in detail. response, history model.chat( tokenizer, pixel_values, question, generation_config, historyNone, return_historyTrue) print(fUser: {question}\nAssistant: {response}) # 第二轮基于同一张图写一首诗复用 history question Please write a poem according to the image. response, history model.chat( tokenizer, pixel_values, question, generation_config, historyhistory, return_historyTrue) print(fUser: {question}\nAssistant: {response}) 第二轮提问里不需要再重复image——历史上下文里已经带着图片信息了。历史拼接逻辑在 modeling_internvl_chat.py 中实现。示例 3多图拼接对比——一次看懂两张图把两张图的 tile 沿第 0 维拼接用一个image占位符表示拼接后的一张大图pixel_values1 load_image(./examples/image1.jpg, max_num12).to(torch.bfloat16).cuda() pixel_values2 load_image(./examples/image2.jpg, max_num12).to(torch.bfloat16).cuda() pixel_values torch.cat((pixel_values1, pixel_values2), dim0) question image\nDescribe the two images in detail. response, history model.chat(tokenizer, pixel_values, question, generation_config, historyNone, return_historyTrue) print(fUser: {question}\nAssistant: {response}) # 追问两图的异同 question What are the similarities and differences between these two images. response, history model.chat(tokenizer, pixel_values, question, generation_config, historyhistory, return_historyTrue) print(fUser: {question}\nAssistant: {response})示例 4独立多图对话——分别描述、再跨图比较与示例 3 不同这里用两个image占位符并传入num_patches_list告诉模型每张图各占多少 tilenum_patches_list [pixel_values1.size(0), pixel_values2.size(0)] question Image-1: image\nImage-2: image\nDescribe the two images in detail. response, history model.chat( tokenizer, pixel_values, question, generation_config, num_patches_listnum_patches_list, historyNone, return_historyTrue) print(fUser: {question}\nAssistant: {response}) question What are the similarities and differences between these two images. response, history model.chat( tokenizer, pixel_values, question, generation_config, num_patches_listnum_patches_list, historyhistory, return_historyTrue) print(fUser: {question}\nAssistant: {response})什么时候用哪种想让模型把多图当一张拼图整体理解时用示例 3想让模型分清图 1 说了什么、图 2 说了什么再做比较时用示例 4。示例 5批量图片问答——一次处理多张图需要处理一批图片时用batch_chat()一次性推理比循环调用快得多。它要求传入num_patches_list和与之一一对应的questions列表questions [image\nDescribe the image in detail.] * len(num_patches_list) responses model.batch_chat( tokenizer, pixel_values, num_patches_listnum_patches_list, questionsquestions, generation_configgeneration_config) for question, response in zip(questions, responses): print(fUser: {question}\nAssistant: {response})⚠️ 注意batch_chat()不支持多轮对话见 modeling_internvl_chat.py 中的NotImplementedError检查需要多轮请回到chat()。四、参数调优与进阶技巧参数作用建议值max_num单图最多切分 tile 数普通照片 4~6细节图 12max_new_tokens最大生成长度描述类 256~512推理类 1024do_sample是否采样创作类True问答类False更稳定num_patches_list每张图 tile 数列表独立多图时必填 更多用法视频多轮对话、流式输出TextIteratorStreamer、LMDeploy 部署可参考 README.md 的Inference with Transformers与Streaming Output两节多卡部署可用 README 中的split_model()方案把 ViT 和 LLM 分层放置。五、常见问题速查Q1加载时提示 AWQ 相关 ImportError先安装依赖pip install autoawq transformers4.37.2并确认 GPU 支持。Q2回答里图片信息丢失检查问题中是否包含image独立多图模式需要与num_patches_list对应数量的占位符且pixel_values的总行数等于sum(num_patches_list)断言见 modeling_internvl_chat.py。Q3显存不够怎么办AWQ 版本已量化到 4-bit是 2B 系列中最省显存的形态仍紧张时可降低max_num减少 tile 数或改用 8-bit 方案对比效果。Q4多轮对话第二轮后上下文越来越长可手动裁剪history只保留最近几轮或在一轮结束后把history置空重新开始。掌握以上 5 个示例后你已能覆盖绝大多数图像问答场景单图描述、围绕单图的多轮追问、多图拼接对比、独立多图比较以及批量图片处理。InternVL3-2B-AWQ 的小巧体积 AWQ 量化让它成为在消费级显卡上落地多模态应用的理想选择动手试试吧赞分享【免费下载链接】InternVL3-2B-AWQ项目地址https://ai.gitcode.com/OpenGVLab/InternVL3-2B-AWQ点击查看免费下载相关推荐BLIP-2 实战指南用 Hugging Face Transformers 实现图像描述、视觉问答与多轮对话BLIP 2 实战指南用 Hugging Face Transformers 实现图像描述、视觉问答与多轮对话 本篇技术指南以 Transformers Tu示例工程CANN/driver DCMI系统时间查询dcmi\_get\_system\_timea nameZH CN_TOPIC_0000002485455440 /a 函数原型a namez驱动开发人工智能CANNBongoCat桌宠完整指南如何免费装好这只感应键鼠的离线桌面宠物BongoCat桌宠完整指南如何免费装好这只感应键鼠的离线桌面宠物 BongoCat桌宠 是一款开源、跨平台的桌面互动伙伴基于 Tauri 构建Windo开发工具高性能计算文档上一篇Apache DataFusion查询优先级抢占机制实现细节下一篇10分钟装好Buzz本地离线语音转文字完整指南创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考