license: llama3.1
language:
- en
pipeline_tag: image-text-to-text
tags:
- text-generation-inference
蜻蜓模型卡片
注意:用户需遵守Llama 3.1社区许可协议使用本模型。
模型详情
蜻蜓是基于Llama 3.1通过指令微调训练的多模态视觉语言模型。
模型来源
- 代码仓库: https://github.com/togethercomputer/Dragonfly
- 论文: https://arxiv.org/abs/2406.00977
用途
蜻蜓模型主要用于大型视觉语言模型的研究,主要面向自然语言处理、机器学习和人工智能领域的研究人员及爱好者。
快速开始
💿 安装指南
创建conda环境并安装必要组件
conda env create -f environment.yml
conda activate dragonfly_env
安装flash attention
pip install flash-attn --no-build-isolation
最后执行以下命令完成安装
pip install --upgrade -e .
🧠 推理演示
成功安装后,可参照以下步骤运行模型。
问题:这张图片的笑点在哪里?

加载必要组件
import torch
from PIL import Image
from transformers import AutoProcessor, AutoTokenizer
from dragonfly.models.modeling_dragonfly import DragonflyForCausalLM
from dragonfly.models.processing_dragonfly import DragonflyProcessor
from pipeline.train.train_utils import random_seed
初始化组件
device = torch.device("cuda:0")
tokenizer = AutoTokenizer.from_pretrained("togethercomputer/Llama-3.1-8B-Dragonfly-v2")
clip_processor = AutoProcessor.from_pretrained("openai/clip-vit-large-patch14-336")
image_processor = clip_processor.image_processor
processor = DragonflyProcessor(image_processor=image_processor, tokenizer=tokenizer, image_encoding_style="llava-hd")
model = DragonflyForCausalLM.from_pretrained("togethercomputer/Llama-3.1-8B-Dragonfly-v2")
model = model.to(torch.bfloat16)
model = model.to(device)
加载并处理图像
image = Image.open("./test_images/skateboard.png")
image = image.convert("RGB")
images = [image]
text_prompt = "<|start_header_id|>user<|end_header_id|>\n\n这张图片的笑点在哪里?<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
inputs = processor(text=[text_prompt], images=images, max_length=4096, return_tensors="pt", is_generate=True)
inputs = inputs.to(device)
生成模型响应
temperature = 0
with torch.inference_mode():
generation_output = model.generate(**inputs, max_new_tokens=1024, eos_token_id=tokenizer.encode("<|eot_id|>"), do_sample=temperature > 0, temperature=temperature, use_cache=True)
generation_text = processor.batch_decode(generation_output, skip_special_tokens=False)
示例输出
这张图片的幽默感来源于将狗狗的面部与达芬奇名作《蒙娜丽莎》身体的超现实拼贴。蒙娜丽莎以其神秘的微笑闻名于世,当艺术家将狗狗生动的面部表情与画作沉静神秘的气质相结合时,这种出人意料的混搭产生了令人会心一笑的效果。动物天性流露的表情与经典艺术形象的强烈反差,构成了这幅图像独特的喜剧张力<|eot_id|>
训练详情
详见论文实现章节。
评估结果
详见论文结果章节。
🏆 致谢
蜻蜓模型的开发得益于以下关键资源:
📚 文献引用
@misc{thapa2024dragonfly,
title={Dragonfly: Multi-Resolution Zoom-In Encoding Enhances Vision-Language Models},
author={Rahul Thapa and Kezhen Chen and Ian Covert and Rahul Chalamala and Ben Athiwaratkun and Shuaiwen Leon Song and James Zou},
year={2024},
eprint={2406.00977},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
模型卡片作者
Rahul Thapa, Kezhen Chen, Rahul Chalamala
联系方式
Rahul Thapa (rahulthapa@together.ai), Kezhen Chen (kezhen@together.ai)