-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathexample_t5gemma2_usage.py
More file actions
59 lines (50 loc) · 1.72 KB
/
Copy pathexample_t5gemma2_usage.py
File metadata and controls
59 lines (50 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
"""
Example usage of the vLLM BART plugin with T5Gemma2.
This script demonstrates how to use T5Gemma2 models with vLLM
after installing the BART plugin and the custom transformers fork.
"""
import vllm_bart_plugin
from vllm import LLM, SamplingParams
from vllm.assets.image import ImageAsset
def main():
"""Run T5Gemma2 model examples."""
model_name = "google/t5gemma-2-270m-270m"
print(f"Loading {model_name}...")
llm = LLM(
model=model_name,
trust_remote_code=True,
enforce_eager=True,
max_model_len=1024,
)
params = SamplingParams(
temperature=0.0,
max_tokens=64,
)
outputs = llm.generate(
[
{ # Simple text-to-text inference
"prompt": "Translate English to French: The president of the United States is",
},
{ # Explicit encoder/decoder prompt
"encoder_prompt": {
"prompt": "",
"multi_modal_data": {
"text": "Summarize: Machine learning is a field of study in artificial intelligence.",
},
},
"decoder_prompt": "Machine",
},
{ # Multimodal inference example (if the model supports vision tasks via its SigLIP encoder)
"prompt": "Describe this image in detail.",
"multi_modal_data": {"image": ImageAsset("stop_sign").pil_image},
},
],
sampling_params=params,
)
for i, o in enumerate(outputs):
generated_text = o.outputs[0].text
print(f"\n--- Output {i+1} ---")
print(generated_text)
if __name__ == "__main__":
main()