Update README.md
Browse files
README.md
CHANGED
|
@@ -40,21 +40,32 @@ Zamba2-VL-2.7B performs strongly against models of comparable size and inference
|
|
| 40 |
|
| 41 |
All numbers are run on the Zyphra evaluation harness (based on VLMEvalKit). Other models are ordered by total parameter count. Bold indicates the best score in each row, while <u>underlined</u> values indicate the lowest score.
|
| 42 |
|
|
|
|
| 43 |
## Quick start
|
| 44 |
|
| 45 |
### Prerequisites
|
| 46 |
|
| 47 |
-
To use Zamba2-VL, install `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
1. `git clone https://github.com/huggingface/transformers.git`
|
| 50 |
-
2. `cd transformers && pip install .`
|
| 51 |
|
| 52 |
To install dependencies necessary to run Mamba2 kernels, install `mamba-ssm` from source (due to compatibility issues with PyTorch) as well as `causal-conv1d`:
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
|
| 59 |
You can run the model without using the optimized Mamba2 kernels, but it is **not** recommended as it will result in significantly higher latency and memory usage.
|
| 60 |
|
|
@@ -62,15 +73,33 @@ You can run the model without using the optimized Mamba2 kernels, but it is **no
|
|
| 62 |
### Inference
|
| 63 |
|
| 64 |
```python
|
| 65 |
-
from transformers import
|
| 66 |
import torch
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
```
|
|
|
|
| 40 |
|
| 41 |
All numbers are run on the Zyphra evaluation harness (based on VLMEvalKit). Other models are ordered by total parameter count. Bold indicates the best score in each row, while <u>underlined</u> values indicate the lowest score.
|
| 42 |
|
| 43 |
+
|
| 44 |
## Quick start
|
| 45 |
|
| 46 |
### Prerequisites
|
| 47 |
|
| 48 |
+
To use Zamba2-VL, install `zamba2-vl` branch from our fork of `transformers` library, which is based on the v4.57.1 of `transformers`:
|
| 49 |
+
```bash
|
| 50 |
+
pip install "transformers @ git+https://github.com/Zyphra/transformers.git@zamba2-vl"
|
| 51 |
+
pip install qwen-vl-utils==0.0.2
|
| 52 |
+
pip install flash_attn
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
The command above relies on requirements for `transformers v4.57.1` being installed in your environment. If you're installing in a fresh Python environment, you might want to specify a specific extra, like `[dev-torch]`, to install all the dependencies:
|
| 56 |
+
```bash
|
| 57 |
+
pip install "transformers[dev-torch] @ git+https://github.com/Zyphra/transformers.git@zamba2-vl"
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
For the fastest setup, ensure your environment matches an existing flash_attn wheel, otherwise the installation will build from source.
|
| 61 |
|
|
|
|
|
|
|
| 62 |
|
| 63 |
To install dependencies necessary to run Mamba2 kernels, install `mamba-ssm` from source (due to compatibility issues with PyTorch) as well as `causal-conv1d`:
|
| 64 |
|
| 65 |
+
```bash
|
| 66 |
+
pip install --no-build-isolation "causal-conv1d @ git+https://github.com/Zyphra/z-causal-conv1d.git@zamba2-vl"
|
| 67 |
+
pip install --no-build-isolation "mamba-ssm @ git+https://github.com/Zyphra/mamba.git@zamba2-vl"
|
| 68 |
+
```
|
| 69 |
|
| 70 |
You can run the model without using the optimized Mamba2 kernels, but it is **not** recommended as it will result in significantly higher latency and memory usage.
|
| 71 |
|
|
|
|
| 73 |
### Inference
|
| 74 |
|
| 75 |
```python
|
| 76 |
+
from transformers import Zamba2_VLForConditionalGeneration, Zamba2_VLProcessor
|
| 77 |
import torch
|
| 78 |
+
from PIL import Image
|
| 79 |
+
from qwen_vl_utils import process_vision_info
|
| 80 |
+
import requests
|
| 81 |
+
|
| 82 |
+
device = "cuda"
|
| 83 |
+
processor = Zamba2_VLProcessor.from_pretrained("Zyphra/Zamba2-VL-2.7B", temporal_patch_size=1)
|
| 84 |
+
model = Zamba2_VLForConditionalGeneration.from_pretrained("Zyphra/Zamba2-VL-2.7B", device_map=device, torch_dtype=torch.bfloat16, attn_implementation="flash_attention_2")
|
| 85 |
+
|
| 86 |
+
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
| 87 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 88 |
+
question = "What do you see in the image? Give us some detail."
|
| 89 |
+
num_img_tokens = 3400
|
| 90 |
+
|
| 91 |
+
conversation = [
|
| 92 |
+
{"role": "user", "content": [
|
| 93 |
+
{"type": "image", "image": image, "max_pixels" : num_img_tokens * 28 * 28, "min_pixels" : 10 * 28 * 28},
|
| 94 |
+
{"type": "text", "text": question},
|
| 95 |
+
]
|
| 96 |
+
},
|
| 97 |
+
]
|
| 98 |
+
prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
|
| 99 |
+
images, _ = process_vision_info(conversation)
|
| 100 |
+
inputs = processor(text=prompt, images=images, add_special_tokens=True, return_tensors="pt")
|
| 101 |
+
inputs = {key: value.to(device) for key, value in inputs.items()}
|
| 102 |
+
|
| 103 |
+
outputs = model.generate(**inputs, max_new_tokens=100)
|
| 104 |
+
print(processor.tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))
|
| 105 |
```
|