sophiamyang commited on
Commit
3a0e7b6
·
verified ·
1 Parent(s): b29cff9

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +45 -0
README.md CHANGED
@@ -198,6 +198,7 @@ pip install --upgrade mistral_common
198
 
199
  You can also make use of a ready-to-go [docker image](https://github.com/vllm-project/vllm/blob/main/Dockerfile).
200
 
 
201
  ```py
202
  from vllm import LLM
203
  from vllm.sampling_params import SamplingParams
@@ -241,6 +242,50 @@ outputs = llm.chat(messages, sampling_params=sampling_params)
241
  print(outputs[0].outputs[0].text)
242
  ```
243
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
 
245
  **_Server_**
246
 
 
198
 
199
  You can also make use of a ready-to-go [docker image](https://github.com/vllm-project/vllm/blob/main/Dockerfile).
200
 
201
+ #### Text understanding example
202
  ```py
203
  from vllm import LLM
204
  from vllm.sampling_params import SamplingParams
 
242
  print(outputs[0].outputs[0].text)
243
  ```
244
 
245
+ #### Image understanding example
246
+ ```py
247
+ from vllm import LLM
248
+ from vllm.sampling_params import SamplingParams
249
+ from huggingface_hub import hf_hub_download
250
+ from datetime import datetime, timedelta
251
+
252
+ model_name = "mistralai/Pixtral-Large-Instruct-2411"
253
+
254
+ def load_system_prompt(repo_id: str, filename: str) -> str:
255
+ file_path = hf_hub_download(repo_id=repo_id, filename=filename)
256
+ with open(file_path, 'r') as file:
257
+ system_prompt = file.read()
258
+ today = datetime.today().strftime('%Y-%m-%d')
259
+ yesterday = (datetime.today() - timedelta(days=1)).strftime('%Y-%m-%d')
260
+ model_name = repo_id.split("/")[-1]
261
+ return system_prompt.format(name=model_name, today=today, yesterday=yesterday)
262
+
263
+ SYSTEM_PROMPT = load_system_prompt(model_name, "SYSTEM_PROMPT.txt")
264
+
265
+ user_prompt = "Describe this image in one sentence."
266
+
267
+ image_url = "https://picsum.photos/id/237/200/300"
268
+
269
+ messages = [
270
+ {
271
+ "role": "system",
272
+ "content": SYSTEM_PROMPT
273
+ },
274
+ {
275
+ "role": "user",
276
+ "content": [{"type": "text", "text": user_prompt}, {"type": "image_url", "image_url": {"url": image_url}}]
277
+ },
278
+ ]
279
+
280
+ sampling_params = SamplingParams(max_tokens=128_000)
281
+
282
+ # note that running this model on GPU requires over 300 GB of GPU RAM
283
+ llm = LLM(model=model_name, tokenizer_mode="mistral", tensor_parallel_size=8, limit_mm_per_prompt={"image": 4})
284
+
285
+ outputs = llm.chat(messages, sampling_params=sampling_params)
286
+
287
+ print(outputs[0].outputs[0].text)
288
+ ```
289
 
290
  **_Server_**
291