SpiridonSunRotator commited on
Commit
901890b
·
verified ·
1 Parent(s): 16c367b

Added transformers usage example

Browse files
Files changed (1) hide show
  1. README.md +46 -1
README.md CHANGED
@@ -24,4 +24,49 @@ Model checkpoint is saved in [compressed_tensors](https://github.com/neuralmagic
24
  * To use the model in `transformers` update the package to stable release of Mistral-3
25
 
26
  `pip install git+https://github.com/huggingface/[email protected]`
27
- * To use the model in `vLLM` update the package to version `vllm>=0.8.0`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  * To use the model in `transformers` update the package to stable release of Mistral-3
25
 
26
  `pip install git+https://github.com/huggingface/[email protected]`
27
+ * To use the model in `vLLM` update the package to version `vllm>=0.8.0`.
28
+
29
+ And example of inference via transformers is provided below:
30
+
31
+ # pip install accelerate
32
+
33
+ from transformers import AutoProcessor, AutoModelForImageTextToText
34
+ from PIL import Image
35
+ import requests
36
+ import torch
37
+
38
+ model_id = "ISTA-DASLab/Mistral-Small-3.1-24B-Instruct-2503-GPTQ-4b-128g"
39
+
40
+ model = AutoModelForImageTextToText.from_pretrained(
41
+ model_id, device_map="auto"
42
+ ).eval()
43
+
44
+ processor = AutoProcessor.from_pretrained(model_id)
45
+
46
+ messages = [
47
+ {
48
+ "role": "system",
49
+ "content": [{"type": "text", "text": "You are a helpful assistant."}]
50
+ },
51
+ {
52
+ "role": "user",
53
+ "content": [
54
+ {"type": "image", "image": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg"},
55
+ {"type": "text", "text": "Describe this image in detail."}
56
+ ]
57
+ }
58
+ ]
59
+
60
+ inputs = processor.apply_chat_template(
61
+ messages, add_generation_prompt=True, tokenize=True,
62
+ return_dict=True, return_tensors="pt"
63
+ ).to(model.device, dtype=torch.bfloat16)
64
+
65
+ input_len = inputs["input_ids"].shape[-1]
66
+
67
+ with torch.inference_mode():
68
+ generation = model.generate(**inputs, max_new_tokens=100, do_sample=False)
69
+ generation = generation[0][input_len:]
70
+
71
+ decoded = processor.decode(generation, skip_special_tokens=True)
72
+ print(decoded)