Update readme sample code
#1
by
nikita-savelyev-cerebras
- opened
README.md
CHANGED
|
@@ -22,22 +22,23 @@ vllm serve tiny-random/kimi-k2.5 --trust-remote-code
|
|
| 22 |
- Transformers
|
| 23 |
|
| 24 |
```python
|
|
|
|
|
|
|
| 25 |
import torch
|
| 26 |
from transformers import AutoModel, AutoProcessor
|
| 27 |
|
| 28 |
model_id = "tiny-random/kimi-k2.5"
|
|
|
|
|
|
|
| 29 |
messages = [
|
| 30 |
{
|
| 31 |
-
|
| 32 |
-
|
|
|
|
| 33 |
{
|
| 34 |
-
|
| 35 |
-
|
| 36 |
},
|
| 37 |
-
{
|
| 38 |
-
"type": "text",
|
| 39 |
-
"text": "describe this image"
|
| 40 |
-
}
|
| 41 |
],
|
| 42 |
}
|
| 43 |
]
|
|
@@ -51,11 +52,9 @@ model = AutoModel.from_pretrained(
|
|
| 51 |
device_map="cuda",
|
| 52 |
trust_remote_code=True,
|
| 53 |
)
|
| 54 |
-
inputs = processor
|
| 55 |
messages,
|
| 56 |
-
tokenize=True,
|
| 57 |
add_generation_prompt=True,
|
| 58 |
-
return_dict=True,
|
| 59 |
return_tensors="pt"
|
| 60 |
).to(model.device)
|
| 61 |
inputs.pop("token_type_ids", None)
|
|
|
|
| 22 |
- Transformers
|
| 23 |
|
| 24 |
```python
|
| 25 |
+
import base64
|
| 26 |
+
import requests
|
| 27 |
import torch
|
| 28 |
from transformers import AutoModel, AutoProcessor
|
| 29 |
|
| 30 |
model_id = "tiny-random/kimi-k2.5"
|
| 31 |
+
image_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"
|
| 32 |
+
image_base64 = base64.b64encode(requests.get(image_url).content).decode()
|
| 33 |
messages = [
|
| 34 |
{
|
| 35 |
+
'role': 'user',
|
| 36 |
+
'content': [
|
| 37 |
+
{'type': 'text', 'text': 'Describe this image in detail.'},
|
| 38 |
{
|
| 39 |
+
'type': 'image_url',
|
| 40 |
+
'image_url': f'data:image/png;base64,{image_base64}',
|
| 41 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
],
|
| 43 |
}
|
| 44 |
]
|
|
|
|
| 52 |
device_map="cuda",
|
| 53 |
trust_remote_code=True,
|
| 54 |
)
|
| 55 |
+
inputs = processor(
|
| 56 |
messages,
|
|
|
|
| 57 |
add_generation_prompt=True,
|
|
|
|
| 58 |
return_tensors="pt"
|
| 59 |
).to(model.device)
|
| 60 |
inputs.pop("token_type_ids", None)
|