Chuyển tới nội dung chính

{/* Trang này được tạo tự động từ SKILL.md của kỹ năng bởi website/scripts/generate-skill-docs.py. Chỉnh sửa nguồn SKILL.md, không phải trang này. */}

Llava

Trợ lý ngôn ngữ và tầm nhìn lớn. Cho phép điều chỉnh hướng dẫn trực quan và hội thoại dựa trên hình ảnh. Kết hợp bộ mã hóa hình ảnh CLIP với các mô hình ngôn ngữ Vicuna/Llama. Hỗ trợ trò chuyện nhiều lượt bằng hình ảnh, trả lời câu hỏi trực quan và hướng dẫn sau. Sử dụng cho các chatbot ngôn ngữ thị giác hoặc các nhiệm vụ hiểu hình ảnh. Tốt nhất để phân tích hình ảnh đàm thoại.

Siêu dữ liệu kỹ năng

NguồnTùy chọn — cài đặt với
`Hermes skills install official/mlops/llava
`
Đường dẫn

optional-skills/mlops/llava ` | | Phiên bản |

1.0.0 ` | | Tác giả | Nghiên cứu dàn nhạc | | Giấy phép | MIT | | Phụ thuộc |

transformers

, `torch

, pillow | | Nền tảng | Linux, macOS, Windows | | Thẻ |

LLaVA

, `Vision-Language

, `Multimodal

, `Visual Question Answering

, `Image Chat

, `CLIP

, `Vicuna

, `Conversational AI

, `Instruction Tuning

, VQA |

Tham khảo: đầy đủ SKILL.md

thông tin

Sau đây là định nghĩa kỹ năng đầy đủ mà Hermes tải khi kỹ năng này được kích hoạt. Đây là những gì tác nhân coi là hướng dẫn khi kỹ năng được kích hoạt.

LLaVA - Trợ lý ngôn ngữ lớn và tầm nhìn

Mô hình ngôn ngữ tầm nhìn nguồn mở để hiểu hình ảnh đàm thoại.

Khi nào nên sử dụng LLaVA`Sử dụng khi:

  • Xây dựng chatbot ngôn ngữ tầm nhìn
  • Trả lời câu hỏi trực quan (VQA)
  • Mô tả và chú thích hình ảnh
  • Cuộc hội thoại hình ảnh nhiều lượt
  • Hướng dẫn trực quan sau đây
  • Hiểu tài liệu bằng hình ảnh`Số liệu:
  • 23.000+ sao GitHub
  • Khả năng ở cấp độ GPT-4V (được nhắm mục tiêu)
  • Giấy phép Apache 2.0
  • Nhiều kích cỡ mô hình (thông số 7B-34B)

Thay vào đó hãy sử dụng các lựa chọn thay thế:

  • GPT-4V: Chất lượng cao nhất, dựa trên API
  • CLIP: Phân loại không bắn đơn giản
  • BLIP-2: Chỉ tốt hơn cho phụ đề
  • Flamingo: Nghiên cứu, không phải nguồn mở

Bắt đầu nhanh

Cài đặt


# Clone repository
git clone https://GitHub.com/haotian-liu/LLaVA
cd LLaVA

# Install
pip install -e .

`
``###Cách sử dụng cơ bản

``` python
from llava.model.builder import load_pretrained_model
from llava.mm_utils import get_model_name_from_path, process_images, tokenizer_image_token
from llava.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN
from llava.conversation import conv_templates
from PIL import Image
import torch

# Load model
model_path = "liuhaotian/llava-v1.5-7b"
tokenizer, model, image_processor, context_len = load_pretrained_model(
model_path=model_path,
model_base=None,
model_name=get_model_name_from_path(model_path)
)

# Load image
image = Image.open("image.jpg")
image_tensor = process_images([image], image_processor, model.config)
image_tensor = image_tensor.to(model.device, dtype=torch.float16)

# Create conversation
conv = conv_templates["llava_v1"].copy()
conv.append_message(conv.roles[0], DEFAULT_IMAGE_TOKEN + "\nWhat is in this image?")
conv.append_message(conv.roles[1], None)
prompt = conv.get_prompt()

# Generate response
input_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors='pt').unsqueeze(0).to(model.device)

with torch.inference_mode():
output_ids = model.generate(
input_ids,
images=image_tensor,
do_sample=True,
temperature=0.2,
max_new_tokens=512
)

response = tokenizer.decode(output_ids[0], skip_special_tokens=True).strip()
print(response)

`
``##Mẫu có sẵn

| Người mẫu | Thông số | VRAM | Chất lượng |
|-------|-------------|------|--------|
| LLaVA-v1.5-7B | 7B | ~14 GB | Tốt |
| LLaVA-v1.5-13B | 13B | ~28 GB | Tốt hơn |
| LLaVA-v1.6-34B | 34B | ~70GB | Tốt nhất |

`Python

# Load different models
model_7b = "liuhaotian/llava-v1.5-7b"
model_13b = "liuhaotian/llava-v1.5-13b"
model_34b = "liuhaotian/llava-v1.6-34b"

# 4-bit quantization for lower VRAM
load_4bit = True # Reduces VRAM by ~4×

`

## Cách sử dụng CLI

``` bash

# Single image query
Python -m llava.serve.CLI \
--model-path liuhaotian/llava-v1.5-7b \
--image-file image.jpg \
--query "What is in this image?"

# Multi-turn conversation
Python -m llava.serve.CLI \
--model-path liuhaotian/llava-v1.5-7b \
--image-file image.jpg
# Then type questions interactively

`

## Giao diện người dùng web (Gradio)

``` bash

# Launch Gradio interface
Python -m llava.serve.gradio_web_server \
--model-path liuhaotian/llava-v1.5-7b \
--load-4bit # Optional: reduce VRAM

# Access at http://localhost:7860

`

## Cuộc trò chuyện nhiều lượt

``` python

# Initialize conversation
conv = conv_templates["llava_v1"].copy()

# Turn 1
conv.append_message(conv.roles[0], DEFAULT_IMAGE_TOKEN + "\nWhat is in this image?")
conv.append_message(conv.roles[1], None)
response1 = generate(conv, model, image) # "A dog playing in a park"

# Turn 2
conv.messages[-1][1] = response1 # Add previous response
conv.append_message(conv.roles[0], "What breed is the dog?")
conv.append_message(conv.roles[1], None)
response2 = generate(conv, model, image) # "Golden Retriever"

# Turn 3
conv.messages[-1][1] = response2
conv.append_message(conv.roles[0], "What time of day is it?")
conv.append_message(conv.roles[1], None)
response3 = generate(conv, model, image)

`

## Nhiệm vụ chung

### Chú thích hình ảnh

``` python
question = "Describe this image in detail."
response = ask(model, image, question)

`

### Trả lời câu hỏi trực quan

`Python
question = "How many people are in the image?"
response = ask(model, image, question)

`

### Phát hiện đối tượng (văn bản)

`Python
question = "List all the objects you can see in this image."
response = ask(model, image, question)

`

### Hiểu cảnh

`Python
question = "What is happening in this scene?"
response = ask(model, image, question)

`

### Hiểu tài liệu

`Python
question = "What is the main topic of this document?"
response = ask(model, document_image, question)

`

## Đào tạo mô hình tùy chỉnh

`bash

# Stage 1: Feature alignment (558K image-caption pairs)
bash scripts/v1_5/pretrain.sh

# Stage 2: Visual instruction tuning (150K instruction data)
bash scripts/v1_5/finetune.sh

`

## Lượng tử hóa (giảm VRAM)

``` python

# 4-bit quantization
tokenizer, model, image_processor, context_len = load_pretrained_model(
model_path="liuhaotian/llava-v1.5-13b",
model_base=None,
model_name=get_model_name_from_path("liuhaotian/llava-v1.5-13b"),
load_4bit=True # Reduces VRAM ~4×
)

# 8-bit quantization
load_8bit=True # Reduces VRAM ~2×

`

## Các phương pháp hay nhất
1. **Bắt đầu với model 7B** - VRAM chất lượng tốt, dễ quản lý
2. **Sử dụng lượng tử hóa 4 bit** - Giảm đáng kể VRAM
3. **Yêu cầu GPU** - CPU suy luận cực kỳ chậm
4. **Lời nhắc rõ ràng** - Câu hỏi cụ thể nhận được câu trả lời tốt hơn
5. **Cuộc trò chuyện nhiều lượt** - Duy trì bối cảnh cuộc trò chuyện
6. **Nhiệt độ 0,2-0,7** - Cân bằng tính sáng tạo/nhất quán
7. **max_new_tokens 512-1024** - Để biết phản hồi chi tiết
8. **Xử lý hàng loạt** - Xử lý nhiều hình ảnh một cách tuần tự

## Hiệu suất

| Người mẫu | VRAM (FP16) | VRAM (4-bit) | Tốc độ (mã thông báo/giây) |
|-------|--------------||--------------|-----------|
| 7B | ~14 GB | ~4 GB | ~20 |
| 13B | ~28 GB | ~8 GB | ~12 |
| 34B | ~70 GB | ~18GB | ~5 |

*Trên GPU A100*

## Điểm chuẩn

LLaVA đạt được điểm số cạnh tranh về:
- **VQAv2**: 78,5%
- **GQA**: 62,0%
- **MM-Vet**: 35,4%
- **MMBench**: 64,3%

## Hạn chế
1. **Ảo giác** - Có thể mô tả những thứ không có trong hình ảnh
2. **Lý luận về không gian** - Khó khăn với vị trí chính xác
3. **Văn bản nhỏ** - Khó đọc chữ in nhỏ
4. **Đếm đối tượng** - Không chính xác đối với nhiều đối tượng
5. **Yêu cầu về VRAM** - Cần GPU mạnh mẽ
6. **Tốc độ suy luận** - Chậm hơn CLIP

## Tích hợp với các framework`###LangChain

``` python
from langchain.LLMs.base import LLM`class LLaVALLM(LLM):
def _call(self, prompt, stop=None):

# Custom LLaVA inference
return response

LLM = LLaVALLM()

`
``###Ứng dụng Gradio

``` python
import gradio as gr`def chat(image, text, history):
response = ask_llava(model, image, text)
return response`demo = gr.ChatInterface(
chat,
additional_inputs=[gr.Image(type="pil")],
title="LLaVA Chat"
)
demo.launch()

`

## Tài nguyên
- **GitHub**: https://GitHub.com/haotian-liu/LLaVA ⭐ 23.000+

- **Giấy**: https://arxiv.org/abs/2304.08485
- **Bản demo**: https://llava.hliu.cc
- **Người mẫu**: https://huggingface.co/liuhaotian
- **Giấy phép**: Apache 2.0