Update Quickstart
Browse files
README.md
CHANGED
@@ -12,13 +12,55 @@ pipeline_tag: image-text-to-text
|
|
12 |
|
13 |
---
|
14 |
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
|
|
|
|
|
|
18 |
|
19 |
-
|
|
|
|
|
20 |
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
</div>
|
23 |
|
24 |
## Model
|
@@ -47,35 +89,6 @@ llava-llama-3-8b-v1_1-hf is a LLaVA model fine-tuned from [meta-llama/Meta-Llama
|
|
47 |
| LLaVA-Llama-3-8B-v1.1 | 72.3 | 66.4 | 31.6 | 36.8 | 70.1 | 70.0 | 72.9 | 47.7 | 86.4 | 62.6 | 59.0 | 1469/349 | 45.1 |
|
48 |
|
49 |
|
50 |
-
## QuickStart
|
51 |
-
|
52 |
-
### Chat with lmdeploy
|
53 |
-
|
54 |
-
1. Installation
|
55 |
-
```
|
56 |
-
pip install 'lmdeploy>=0.4.0'
|
57 |
-
pip install git+https://github.com/haotian-liu/LLaVA.git
|
58 |
-
```
|
59 |
-
|
60 |
-
2. Run
|
61 |
-
|
62 |
-
```python
|
63 |
-
from lmdeploy import pipeline, ChatTemplateConfig
|
64 |
-
from lmdeploy.vl import load_image
|
65 |
-
pipe = pipeline('xtuner/llava-llama-3-8b-v1_1-hf',
|
66 |
-
chat_template_config=ChatTemplateConfig(model_name='llama3'))
|
67 |
-
|
68 |
-
image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/tests/data/tiger.jpeg')
|
69 |
-
response = pipe(('describe this image', image))
|
70 |
-
print(response)
|
71 |
-
```
|
72 |
-
|
73 |
-
More details can be found on [inference](https://lmdeploy.readthedocs.io/en/latest/inference/vl_pipeline.html) and [serving](https://lmdeploy.readthedocs.io/en/latest/serving/api_server_vl.html) docs.
|
74 |
-
|
75 |
-
### Chat with CLI
|
76 |
-
|
77 |
-
See [here](https://huggingface.co/xtuner/llava-llama-3-8b-v1_1-hf/discussions/1)!
|
78 |
-
|
79 |
|
80 |
## Citation
|
81 |
|
|
|
12 |
|
13 |
---
|
14 |
|
15 |
+
## QuickStart
|
16 |
+
|
17 |
+
### Chat with lmdeploy
|
18 |
+
|
19 |
+
1. Installation
|
20 |
+
```
|
21 |
+
pip install 'lmdeploy>=0.4.0'
|
22 |
+
pip install git+https://github.com/haotian-liu/LLaVA.git
|
23 |
+
```
|
24 |
+
|
25 |
+
2. Run
|
26 |
+
|
27 |
+
Running with pure `transformers` library
|
28 |
+
|
29 |
+
```python
|
30 |
+
from transformers import (
|
31 |
+
LlavaProcessor,
|
32 |
+
LlavaForConditionalGeneration,
|
33 |
+
)
|
34 |
+
import torch
|
35 |
+
from PIL import Image
|
36 |
+
import requests
|
37 |
+
|
38 |
+
MODEL_NAME = "Seungyoun/llava-llama-3-8b-hf"
|
39 |
|
40 |
+
processor = LlavaProcessor.from_pretrained(MODEL_NAME)
|
41 |
+
# add 128257 <image> , <pad>
|
42 |
+
processor.tokenizer.add_tokens(["<|image|>", "<pad>"], special_tokens=True)
|
43 |
|
44 |
+
model = LlavaForConditionalGeneration.from_pretrained(MODEL_NAME).to("cuda:0")
|
45 |
+
# resize embeddings
|
46 |
+
model.resize_token_embeddings(len(processor.tokenizer))
|
47 |
|
48 |
|
49 |
+
# prepare image and text prompt, using the appropriate prompt template
|
50 |
+
url = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTd4g61TSw890IYKBbPMgXPyWAKdVOpWWUAF0-FGzgX2Q&s"
|
51 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
52 |
+
prompt = "A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions. USER: <|image|>\nWhat is shown in this image? ASSISTANT:" # FIX : Chat template
|
53 |
+
|
54 |
+
inputs = processor(prompt, image, return_tensors="pt").to("cuda:0")
|
55 |
+
|
56 |
+
# autoregressively complete prompt
|
57 |
+
output = model.generate(**inputs, max_new_tokens=100)
|
58 |
+
|
59 |
+
print(processor.decode(output[0], skip_special_tokens=True))
|
60 |
+
# What is shown in this image? ASSISTANT: The image shows a heartwarming scene of two dogs sitting together on a couch. The dogs are of different breeds, one being a golden retriever and the other being a tabby cat. The dogs are sitting close together, indicating a strong bond between them. The image captures a beautiful moment of companionship between two different species. sit on couch. golden retriever and tabby cat. dogs are sitting together. companionship between two different species.
|
61 |
+
```
|
62 |
+
---
|
63 |
+
|
64 |
</div>
|
65 |
|
66 |
## Model
|
|
|
89 |
| LLaVA-Llama-3-8B-v1.1 | 72.3 | 66.4 | 31.6 | 36.8 | 70.1 | 70.0 | 72.9 | 47.7 | 86.4 | 62.6 | 59.0 | 1469/349 | 45.1 |
|
90 |
|
91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
## Citation
|
94 |
|