Model reference · open weights
Llama-3.1-Dragonfly-Med is an open-weight language model from togethercomputer. AxForge deploys and operates it for you on dedicated EU-owned hardware — with the licence handled where one is required.
Available as managed deployment — configured and operated for you on dedicated EU hardware, quoted per deployment.
What it is
| Maker | togethercomputer |
|---|---|
| Type | Language models |
| Task | Vision + text |
| Context | 8k tokens |
| Released | 2024-10-10 |
| Popularity | 56 downloads / month |
| Licence | Open, with conditions |
About
Note: Users are permitted to use this model in accordance with the Llama 3.1 Community License Agreement. Additionally, due to the licensing restrictions of the dataset used to train this model, which prohibits commercial use, the Dragonfly-Med model is restricted to non-commercial use only.
Dragonfly-Med is a multimodal biomedical visual-language model, trained by instruction tuning on Llama 3.1.
The primary use of Dragonfly-Med is research on large visual-language models. It is primarily intended for researchers and hobbyists in natural language processing, machine learning, and artificial intelligence.
Create a conda environment and install necessary packages
conda env create -f environment.yml
conda activate dragonfly_env
Install flash attention
pip install flash-attn --no-build-isolation
As a final step, please run the following command.
pip install --upgrade -e .
If you have successfully completed the installation process, then you should be able to follow the steps below.
Question: Provide a brief description of the given image.
Load necessary packages
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
Instantiate the tokenizer, processor, and model.
device = torch.device("cuda:0")
tokenizer = AutoTokenizer.from_pretrained("togethercomputer/Llama-3.1-8B-Dragonfly-Med-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-Med-v2")
model = model.to(torch.bfloat16)
model = model.to(device)
Now, lets load the image and process them.
image = Image.open("ROCO_04197.jpg")
image = image.convert("RGB")
images = [image]
# images = [None] # if you do not want to pass any images
text_prompt = "user\n\nProvide a brief description of the given image.assistant\n\n"
inputs = processor(text=[text_prompt], images=images, max_length=1024, return_tensors="pt", is_generate=True)
inputs = inputs.to(device)
Finally, let us generate the responses from the model
temperature = 0
with torch.inference_mode():
generation_output = model.generate(**inputs, max_new_tokens=1024, eos_token_id=tokenizer.encode(""), do_sample=temperature > 0, temperature=temperature, use_cache=True)
generation_text = processor.batch_decode(generation_output, skip_special_tokens=False)
An example response.
Computed tomography scan showing a large heterogenous mass in the pelvis
See more details in the "Implementation" section of our paper.
See more details in the "Results" section of our paper.
We would like to acknowledge the following resources that were instrumental in the development of Dragonfly:
@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)
From the published model card. Full card on the HuggingFace links in the sidebar.
Using it via the API
Once AxForge deploys llama-3-1-dragonfly-med for you, it answers on the OpenAI-compatible API — the same base URL and keys as every other model. (llama-3-1-dragonfly-med below is illustrative; you get the exact model name on deployment.)
$ curl -sS https://api.axforge.ai/v1/chat/completions \
-H "Authorization: Bearer $AXFORGE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"llama-3-1-dragonfly-med","messages":[{"role":"user","content":"Hello"}]}'
Create an account — your API key is available in the console. 5M tokens/month currently included with every new account at launch.