Views
No views yet
vllm for efficient inference. Below is a custom wrapper class designed to handle the hierarchical generation process.NLP_MODEL_PATH: Path to your Spacy model (e.g., en_core_web_sm).VLLM_MODEL_PATH: Path to this model (local or HF hub ID).prompt/generate_meme.txt: The text file containing the system prompt for CoT generation.1from vllm import LLM, SamplingParams
2
3# 1. Configuration
4# Replace with your actual model path or Hugging Face ID
5MODEL_PATH = "Your-HF-Org/HUMOR-COT"
6
7# 2. Initialize the vLLM engine
8# Note: Qwen2.5-VL requires specific pixel arguments for the visual encoder
9llm = LLM(
10 model=MODEL_PATH,
11 trust_remote_code=True,
12 limit_mm_per_prompt={"image": 1},
13 mm_processor_kwargs={
14 "min_pixels": 28 * 28,
15 "max_pixels": 1280 * 28 * 28,
16 "fps": 1,
17 },
18 gpu_memory_utilization=0.3
19)
20
21def generate_meme(image_path, prompt):
22 """
23 Simple function to generate text from an image.
24 """
25 # Construct the message in Qwen2.5-VL format
26 messages = [
27 {"role": "system", "content": "You are a helpful assistant."},
28 {"role": "user", "content": [
29 {"type": "image", "image": image_path},
30 {"type": "text", "text": prompt}
31 ]}
32 ]
33
34 # Set sampling parameters
35 sampling_params = SamplingParams(temperature=0.7, max_tokens=256)
36
37 # Run inference
38 outputs = llm.chat(messages=messages, sampling_params=sampling_params)
39 return outputs[0].outputs[0].text
40
41if __name__ == "__main__":
42 # 3. Minimal Main Execution
43 image_file = "assets/test_image.jpg"
44 user_prompt = "Generate a humorous meme caption.\nTag: Work Life\nContext: Monday morning."
45
46 # Run and print
47 caption = generate_meme(image_file, user_prompt)
48 print(caption)
49box_1: text, box_2: text.| Model | Humor (0-5) | Readability (0-5) | Human-Likeness Score (%) |
|---|---|---|---|
| Qwen2.5-7B-Instruct (Base) | 2.39 | 3.35 | 75.7% |
| GPT-4o | 2.70 | 3.79 | 91.3% |
| HUMOR-COT (Ours) | 2.68 | 3.70 | 91.5% |

1@article{li2025perception,
2 title={From Perception to Punchline: Empowering VLM with the Art of In-the-wild Meme},
3 author={Li, Xueyan and Xue, Yingyi and Jiang, Mengjie and Zhu, Qingzi and Niu, Yazhe},
4 journal={arXiv preprint arXiv:2512.24555},
5 year={2025}
6}
7