当前位置: 首页 > news >正文

本地部署 Llama-3-EvoVLM-JP-v2

本地部署 Llama-3-EvoVLM-JP-v2

  • 0. 引言
  • 1. 关于 Llama-3-EvoVLM-JP-v2
  • 2. 本地部署
    • 2-0. 克隆代码
    • 2-1. 安装依赖模块
    • 2-2. 创建 Web UI
    • 2-3.启动 Web UI
    • 2-4. 访问 Web UI

0. 引言

Sakana AI 提出了一种称为进化模型合并的方法,并使用该方法创建大规模语言模型(LLM )、视觉语言模型(VLM)和图像生成模型,他们创建了具有各种功能的合并模型。这次,他们发布了一个新的日本 VLM,Llama-3-EvoVLM-JP-v2,它利用进化模型合并来实现多个图像的问答。此外,为了评估构建的模型,他们还将发布一个数据集:日语多图像视觉问答(JA-Multi-Image-VQA),以评估用日语回答有关多个图像的问题的能力。

1. 关于 Llama-3-EvoVLM-JP-v2

VLM研究LLM它是发展最快的领域之一。最近,VLM的研究不断取得进展,不仅提高了单图像描绘和问答的性能,而且还具备处理视频和多图像的能力。另一方面,这种新型的VLM主要是在英语国家开发的,在非英语国家仍然基本上不存在。日语也是如此;虽然已经开发了几种日语VLM,但这种类型的尖端VLM仍然不多。因此,Sakana AI 使用进化模型融合来创建这种新型的英语 VLM 和日语 VLM。他们认为通过合并这些LLM,他们可以快速构建一个尖端的日本 VLM。

在构建新的VLM时,底层模型是开源模型。LLM其中,他们选择了Llama-3,它具有高性能,并且各种额外训练的模型都是公开的。有几种使用 Llama-3 创建的高性能 VLM,但Mantis-8B-SigLIP-Llama-3是一种前所未有的 VLM,可以将输入图像放置在我选择的输入文本中的任何位置。高性能日语培训,帮助学生获得日语能力。LLM他们使用Llama-3-ELYZA-JP-8B 。首先,通过合并这两个模型,他们成功构建了“可以处理多个图像的日本 VLM”。此外,他们还添加了一个名为Bunny-v1.1-Llama-3-8B-V的高性能英文VLM来增强图像渲染能力。LLM这些部件也被添加到合并中。

2. 本地部署

2-0. 克隆代码

git clone https://huggingface.co/spaces/SakanaAI/Llama-3-EvoVLM-JP-v2; cd Llama-3-EvoVLM-JP-v2

2-1. 安装依赖模块

pip install git+https://github.com/TIGER-AI-Lab/Mantis.git

2-2. 创建 Web UI

# webui.py
import gradio as gr
import time
import subprocessimport torchfrom models.mllava import (MLlavaProcessor,LlavaForConditionalGeneration,prepare_inputs,
)
from models.conversation import Conversation, SeparatorStyle
from transformers import TextIteratorStreamer
from transformers.utils import is_flash_attn_2_available
from threading import Threaddevice = "cuda" if torch.cuda.is_available() else "cpu"
IMAGE_TOKEN = "<image>"
generation_kwargs = {"max_new_tokens": 1024,"num_beams": 1,"do_sample": False,"no_repeat_ngram_size": 3,
}if not is_flash_attn_2_available():subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"},shell=True)processor = MLlavaProcessor.from_pretrained("TIGER-Lab/Mantis-8B-siglip-llama3")
processor.tokenizer.pad_token = processor.tokenizer.eos_tokenmodel = LlavaForConditionalGeneration.from_pretrained("SakanaAI/Llama-3-EvoVLM-JP-v2",torch_dtype=torch.float16,attn_implementation="flash_attention_2",device_map=device,
).eval()# Set the system prompt
conv_template = Conversation(system="<|start_header_id|>system<|end_header_id|>\n\nあなたは誠実で優秀な日本人のアシスタントです。特に指示が無い場合は、常に日本語で回答してください。",roles=("user", "assistant"),messages=(),offset=0,sep_style=SeparatorStyle.LLAMA_3,sep="<|eot_id|>",
)def get_chat_messages(history):chat_history = []user_role = conv_template.roles[0]assistant_role = conv_template.roles[1]for i, message in enumerate(history):if isinstance(message[0], str):chat_history.append({"role": user_role, "text": message[0]})if i != len(history) - 1:assert message[1], "The bot message is not provided, internal error"chat_history.append({"role": assistant_role, "text": message[1]})else:assert not message[1], "the bot message internal error, get: {}".format(message[1])chat_history.append({"role": assistant_role, "text": ""})return chat_historydef get_chat_images(history):images = []for message in history:if isinstance(message[0], tuple):images.extend(message[0])return imagesdef add_message(history, message):return history, gr.MultimodalTextbox(interactive=False)def bot(history, message):images = message["files"] if message["files"] else Nonetext = message["text"].strip()if not text:raise gr.Error("You must enter a message!")num_image_tokens = text.count(IMAGE_TOKEN)# modify textif images and num_image_tokens < len(images):if num_image_tokens != 0:gr.Warning("The number of images uploaded is more than the number of <image> placeholders in the text. Will automatically prepend <image> to the text.")# prefix image tokenstext = IMAGE_TOKEN * (len(images) - num_image_tokens) + textif images and num_image_tokens > len(images):raise gr.Error("The number of images uploaded is less than the number of <image> placeholders in the text!")current_messages = []if images:current_messages += [[(image,), None] for image in images]if text:current_messages += [[text, None]]current_history = history + current_messages# chat_messages = get_chat_messages(current_history)# chat_images = get_chat_images(current_history)chat_messages = get_chat_messages(current_messages)chat_images = get_chat_images(current_messages)# Generate!inputs = prepare_inputs(None, chat_images, model, processor, history=chat_messages, **generation_kwargs)streamer = TextIteratorStreamer(processor, skip_prompt=True, skip_special_tokens=True)inputs["streamer"] = streamerthread = Thread(target=model.generate, kwargs=inputs)thread.start()buffer = ""for new_text in streamer:buffer += new_texttime.sleep(0.01)# yield buffercurrent_history[-1] = (current_history[-1][0], buffer)yield current_historyexamples = [{"text": "1番目と2番目の画像に写っている動物の違いは何ですか?簡潔に説明してください。","files": ["./examples/image_0.jpg", "./examples/image_1.jpg"],},{"text": "2枚の写真について、簡単にそれぞれ説明してください。","files": ["./examples/image_2.jpg", "./examples/image_3.jpg"],},
]with gr.Blocks(fill_height=True) as demo:chatbot = gr.Chatbot(elem_id="chatbot",bubble_full_width=False,scale=1,)chat_input = gr.MultimodalTextbox(interactive=True,file_types=["image"],placeholder="Enter message or upload images. Please use <image> to indicate the position of uploaded images",show_label=True,render=True,)examples = gr.Examples(examples, [chat_input], [])chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])bot_msg = chat_msg.then(bot, [chatbot, chat_input], chatbot, api_name="bot_response")bot_msg.then(lambda: gr.MultimodalTextbox(value=None, interactive=True), None, [chat_input])demo.queue().launch()

2-3.启动 Web UI

python webui.py

2-4. 访问 Web UI

使用浏览器打开 http://localhost:7860,

在这里插入图片描述
完结!

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 分布式事务一站式解决方案-Seata
  • 【OpenCV C++20 学习笔记】物体检测-Ballard和Guil霍夫变换
  • 常见框架漏洞 上 (Thinkphp、struts2、Spring、Shiro)
  • Linux中NFS配置
  • 【实现100个unity特效之15】最简单的方法使用shader graphs实现2d非像素和像素树叶草的随风摇摆效果
  • 在Linux上安装Conda以支持Go 1.19
  • 快速体验LLaMA-Factory 私有化部署和高效微调Llama3模型(曙光超算互联网平台异构加速卡DCU)
  • 快速掌握Vue:基础命令详解
  • 大数据应用【大数据导论】
  • 揭露黑产新势力:Akira勒索软件家族深度解析
  • [ERR] 1273 - Unknown collation: ‘utf8mb4_0900_ai_ci‘(已解决)
  • 【linux】linux中特殊权限管理--FACL详细用法教程与应用实战
  • Unity初识
  • C语言深度剖析(部分)--剩下随缘更新
  • 2024.08.01 校招 实习 内推 面经
  • [iOS]Core Data浅析一 -- 启用Core Data
  • chrome扩展demo1-小时钟
  • echarts的各种常用效果展示
  • JAVA_NIO系列——Channel和Buffer详解
  • puppeteer stop redirect 的正确姿势及 net::ERR_FAILED 的解决
  • seaborn 安装成功 + ImportError: DLL load failed: 找不到指定的模块 问题解决
  • session共享问题解决方案
  • Vue学习第二天
  • 从 Android Sample ApiDemos 中学习 android.animation API 的用法
  • 从零开始的无人驾驶 1
  • 基于Vue2全家桶的移动端AppDEMO实现
  • 开源SQL-on-Hadoop系统一览
  • 如何邀请好友注册您的网站(模拟百度网盘)
  • 入手阿里云新服务器的部署NODE
  • 使用阿里云发布分布式网站,开发时候应该注意什么?
  • 一起来学SpringBoot | 第三篇:SpringBoot日志配置
  • ​MySQL主从复制一致性检测
  • ​补​充​经​纬​恒​润​一​面​
  • # Redis 入门到精通(一)数据类型(4)
  • # 利刃出鞘_Tomcat 核心原理解析(八)-- Tomcat 集群
  • #100天计划# 2013年9月29日
  • (1)Android开发优化---------UI优化
  • (173)FPGA约束:单周期时序分析或默认时序分析
  • (2)STM32单片机上位机
  • (done) NLP “bag-of-words“ 方法 (带有二元分类和多元分类两个例子)词袋模型、BoW
  • (LeetCode C++)盛最多水的容器
  • (苍穹外卖)day03菜品管理
  • (附表设计)不是我吹!超级全面的权限系统设计方案面世了
  • (六)什么是Vite——热更新时vite、webpack做了什么
  • (十)c52学习之旅-定时器实验
  • (四)软件性能测试
  • (贪心 + 双指针) LeetCode 455. 分发饼干
  • (原)记一次CentOS7 磁盘空间大小异常的解决过程
  • (转) SpringBoot:使用spring-boot-devtools进行热部署以及不生效的问题解决
  • (转)IOS中获取各种文件的目录路径的方法
  • (转)负载均衡,回话保持,cookie
  • .net 开发怎么实现前后端分离_前后端分离:分离式开发和一体式发布
  • .NET 同步与异步 之 原子操作和自旋锁(Interlocked、SpinLock)(九)
  • .net2005怎么读string形的xml,不是xml文件。
  • .NetCore+vue3上传图片 Multipart body length limit 16384 exceeded.