Views
No views yet
["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]pip install transformers torch autoawq1from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
2import torch
3
4model_path = "kawchar85/Llama2-TIFA-AWQ"
5
6# Load AWQ quantized model and tokenizer
7tokenizer = AutoTokenizer.from_pretrained(model_path)
8model = AutoModelForCausalLM.from_pretrained(
9 model_path,
10 torch_dtype=torch.float16,
11 device_map="auto"
12)
13
14# Create pipeline (optimized for ~8 second inference)
15pipe = pipeline(
16 "text-generation",
17 model=model,
18 tokenizer=tokenizer,
19 max_new_tokens=512,
20 do_sample=True,
21 temperature=0.7,
22 top_p=0.9,
23)
24
25# System prompt for TIFA question generation
26system_msg = """\
27You are a TIFA (Text-to-Image Faithfulness evaluation with question Answering) question generator. Given an image description, create exactly 4 visual verification questions with multiple choice answers. Each question should test different visual aspects that can be verified by looking at the image.
28
29Guidelines:
30- Focus on colors, shapes, objects, materials, spatial relationships, and other visually verifiable elements
31- Mix yes/no questions (2 choices: "no", "yes") and multiple choice questions (4 choices)
32- Each question should test a DIFFERENT aspect of the description
33- Ensure questions can be answered by visual inspection of the image
34- Use elements explicitly mentioned in the description
35- Include both positive verification (testing presence, answer: "yes") and negative verification (testing absence, answer: "no")
36- Make distractors realistic and relevant to the domain
37
38Format each question as:
39Q[number]: [question text]
40C: [comma-separated choices]
41A: [correct answer]
42
43Generate questions that test visual faithfulness between the description and image."""
44
45# Generate evaluation questions
46description = "a lighthouse overlooking the ocean"
47prompt = (
48 "<s>[INST] <<SYS>>\n"
49 f"{system_msg}\n"
50 "<</SYS>>\n\n"
51 f'Create 4 visual verification questions for this description: "{description}" [/INST]'
52)
53
54output = pipe(prompt)[0]['generated_text']
55response = output[len(prompt):]
56print(response)Q1: What type of structure is prominently featured in the image?
C: windmill, lighthouse, castle, tower
A: lighthouse
Q2: What body of water is the lighthouse overlooking?
C: lake, river, ocean, pond
A: ocean
Q3: Are there any mountains visible in the scene?
C: no, yes
A: no
Q4: Is the lighthouse positioned to overlook a body of water?
C: no, yes
A: yes| Aspect | Llama2-TIFA-AWQ | SmolLM2 Series |
|---|---|---|
| Starting point | TIFA-specialized model | General instruction models |
| Domain knowledge | ✅ Pre-existing TIFA expertise | ⭐ Learned during fine-tuning |
| Model size | ~7B parameters (AWQ quantized) | 135M - 1.7B parameters |
| Inference speed | ~8 seconds (AWQ optimized) | ~3 seconds (small models) |
| Training approach | Structural refinement + quantization | Full task learning |
| Memory efficiency | ✅ AWQ quantized | ⭐ Naturally smaller |
| Question quality | ✅ Deep domain knowledge | ⭐ Systematic structure |
1@misc{llama2-tifa-refined-2025,
2 title={Llama2-TIFA: Structural Refinement of LLaMA 2 for Text-to-Image Faithfulness Assessment},
3 author={kawchar85},
4 year={2025},
5 url={https://huggingface.co/kawchar85/Llama2-TIFA-AWQ},
6 note={Fine-tuned from tifa-benchmark/llama2_tifa_question_generation}
7}