Text Generation
Safetensors
English
llama
text-to-image-evaluation
faithfulness
lora
tifa
llama2
question-generation
4-bit precision
awq
Instructions to use kawchar85/Llama2-TIFA-AWQ with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Local Apps Settings
- vLLM
How to use kawchar85/Llama2-TIFA-AWQ with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "kawchar85/Llama2-TIFA-AWQ" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "kawchar85/Llama2-TIFA-AWQ", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/kawchar85/Llama2-TIFA-AWQ
- SGLang
How to use kawchar85/Llama2-TIFA-AWQ with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "kawchar85/Llama2-TIFA-AWQ" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "kawchar85/Llama2-TIFA-AWQ", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "kawchar85/Llama2-TIFA-AWQ" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "kawchar85/Llama2-TIFA-AWQ", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use kawchar85/Llama2-TIFA-AWQ with Docker Model Runner:
docker model run hf.co/kawchar85/Llama2-TIFA-AWQ
Update README.md
Browse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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model:
|
| 4 |
+
- tifa-benchmark/llama2_tifa_question_generation
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
tags:
|
| 7 |
+
- text-to-image-evaluation
|
| 8 |
+
- faithfulness
|
| 9 |
+
- lora
|
| 10 |
+
- tifa
|
| 11 |
+
- llama2
|
| 12 |
+
- question-generation
|
| 13 |
+
language: en
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# Llama2-TIFA-AWQ
|
| 17 |
+
|
| 18 |
+
## Model Description
|
| 19 |
+
|
| 20 |
+
Llama2-TIFA-AWQ is a fine-tuned and AWQ-quantized version of [tifa-benchmark/llama2_tifa_question_generation](https://huggingface.co/tifa-benchmark/llama2_tifa_question_generation) that addresses structural limitations in the original TIFA question generation model while providing **significantly faster inference**. The model combines structural refinement with AWQ quantization to achieve optimal performance-speed balance for TIFA question generation.
|
| 21 |
+
|
| 22 |
+
## Key Innovation: Fixing Structural Issues
|
| 23 |
+
|
| 24 |
+
This model represents a **refinement approach** rather than training from scratch:
|
| 25 |
+
- **Original model strength**: Deep TIFA domain knowledge and question generation capabilities
|
| 26 |
+
- **Original model issues**:
|
| 27 |
+
- Generated multiple questions for the same attribute
|
| 28 |
+
- Lacked negative verification questions
|
| 29 |
+
- **This solution**: Structural fine-tuning to enforce 4-question format while preserving domain expertise
|
| 30 |
+
|
| 31 |
+
## AWQ Quantization: Performance Optimization
|
| 32 |
+
|
| 33 |
+
This model includes **AWQ (Activation-aware Weight Quantization)** for optimal inference speed:
|
| 34 |
+
|
| 35 |
+
### Performance Comparison
|
| 36 |
+
- **SmolLM2 models**: ~3 seconds (baseline small models)
|
| 37 |
+
- **Original LLaMA 2**: ~20 seconds (full precision)
|
| 38 |
+
- **Llama2-TIFA-AWQ**: ~8 seconds (**2.5x faster** than full precision)
|
| 39 |
+
|
| 40 |
+
## Intended Use
|
| 41 |
+
|
| 42 |
+
This model generates exactly 4 structured visual verification questions for text-to-image evaluation:
|
| 43 |
+
- **Mixed question types**: Both yes/no and multiple choice questions
|
| 44 |
+
- **Comprehensive coverage**: Colors, shapes, objects, materials, spatial relationships
|
| 45 |
+
- **Balanced verification**: Both positive presence and negative absence testing
|
| 46 |
+
- **Controlled structure**: Exactly 4 questions without redundancy
|
| 47 |
+
|
| 48 |
+
## Model Details
|
| 49 |
+
|
| 50 |
+
- **Base Model**: tifa-benchmark/llama2_tifa_question_generation (LLaMA 2 architecture)
|
| 51 |
+
- **Model Size**: ~7B parameters (AWQ quantized)
|
| 52 |
+
- **Fine-tuning Method**: LoRA (Low-Rank Adaptation) for structural refinement
|
| 53 |
+
- **Quantization**: AWQ (Activation-aware Weight Quantization)
|
| 54 |
+
- **Training Framework**: Transformers + TRL + PEFT
|
| 55 |
+
- **License**: apache-2.0
|
| 56 |
+
|
| 57 |
+
## Training Details
|
| 58 |
+
|
| 59 |
+
### Structural Refinement Configuration
|
| 60 |
+
- **Training Method**: Supervised Fine-Tuning with LoRA on pre-trained TIFA model
|
| 61 |
+
- **LoRA Configuration**:
|
| 62 |
+
- r: 32
|
| 63 |
+
- lora_alpha: 64
|
| 64 |
+
- lora_dropout: 0.05
|
| 65 |
+
- Target modules: `["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]`
|
| 66 |
+
|
| 67 |
+
- **Training Parameters**:
|
| 68 |
+
- Epochs: 2
|
| 69 |
+
- Learning Rate: 3e-4
|
| 70 |
+
- Batch Size: 6
|
| 71 |
+
- Gradient Accumulation: 5 steps
|
| 72 |
+
- Max Sequence Length: 768
|
| 73 |
+
- LR Scheduler: Cosine with 5% warmup
|
| 74 |
+
- Precision: FP16
|
| 75 |
+
|
| 76 |
+
### Enhanced Dataset
|
| 77 |
+
- **Size**: 18,000 examples with structured 4-question format
|
| 78 |
+
- **Focus**: Teaching proper question structure and negative verification
|
| 79 |
+
- **Validation**: Category-balanced split ensuring robust evaluation
|
| 80 |
+
- **Format**: LLaMA 2 chat template with preprocessed text format
|
| 81 |
+
|
| 82 |
+
## Usage
|
| 83 |
+
|
| 84 |
+
### Installation
|
| 85 |
+
|
| 86 |
+
```bash
|
| 87 |
+
pip install transformers torch autoawq
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
### Basic Usage
|
| 91 |
+
|
| 92 |
+
```python
|
| 93 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 94 |
+
import torch
|
| 95 |
+
|
| 96 |
+
model_path = "kawchar85/Llama2-TIFA-AWQ"
|
| 97 |
+
|
| 98 |
+
# Load AWQ quantized model and tokenizer
|
| 99 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 100 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 101 |
+
model_path,
|
| 102 |
+
torch_dtype=torch.float16,
|
| 103 |
+
device_map="auto"
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
# Create pipeline (optimized for ~8 second inference)
|
| 107 |
+
pipe = pipeline(
|
| 108 |
+
"text-generation",
|
| 109 |
+
model=model,
|
| 110 |
+
tokenizer=tokenizer,
|
| 111 |
+
max_new_tokens=512,
|
| 112 |
+
do_sample=True,
|
| 113 |
+
temperature=0.7,
|
| 114 |
+
top_p=0.9,
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
# System prompt for TIFA question generation
|
| 118 |
+
system_msg = """\
|
| 119 |
+
You 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.
|
| 120 |
+
|
| 121 |
+
Guidelines:
|
| 122 |
+
- Focus on colors, shapes, objects, materials, spatial relationships, and other visually verifiable elements
|
| 123 |
+
- Mix yes/no questions (2 choices: "no", "yes") and multiple choice questions (4 choices)
|
| 124 |
+
- Each question should test a DIFFERENT aspect of the description
|
| 125 |
+
- Ensure questions can be answered by visual inspection of the image
|
| 126 |
+
- Use elements explicitly mentioned in the description
|
| 127 |
+
- Include both positive verification (testing presence, answer: "yes") and negative verification (testing absence, answer: "no")
|
| 128 |
+
- Make distractors realistic and relevant to the domain
|
| 129 |
+
|
| 130 |
+
Format each question as:
|
| 131 |
+
Q[number]: [question text]
|
| 132 |
+
C: [comma-separated choices]
|
| 133 |
+
A: [correct answer]
|
| 134 |
+
|
| 135 |
+
Generate questions that test visual faithfulness between the description and image."""
|
| 136 |
+
|
| 137 |
+
# Generate evaluation questions
|
| 138 |
+
description = "a lighthouse overlooking the ocean"
|
| 139 |
+
prompt = (
|
| 140 |
+
"<s>[INST] <<SYS>>\n"
|
| 141 |
+
f"{system_msg}\n"
|
| 142 |
+
"<</SYS>>\n\n"
|
| 143 |
+
f'Create 4 visual verification questions for this description: "{description}" [/INST]'
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
output = pipe(prompt)[0]['generated_text']
|
| 147 |
+
response = output[len(prompt):]
|
| 148 |
+
print(response)
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
### Example Output
|
| 152 |
+
|
| 153 |
+
**For "a lighthouse overlooking the ocean":**
|
| 154 |
+
```
|
| 155 |
+
Q1: What type of structure is prominently featured in the image?
|
| 156 |
+
C: windmill, lighthouse, castle, tower
|
| 157 |
+
A: lighthouse
|
| 158 |
+
|
| 159 |
+
Q2: What body of water is the lighthouse overlooking?
|
| 160 |
+
C: lake, river, ocean, pond
|
| 161 |
+
A: ocean
|
| 162 |
+
|
| 163 |
+
Q3: Are there any mountains visible in the scene?
|
| 164 |
+
C: no, yes
|
| 165 |
+
A: no
|
| 166 |
+
|
| 167 |
+
Q4: Is the lighthouse positioned to overlook a body of water?
|
| 168 |
+
C: no, yes
|
| 169 |
+
A: yes
|
| 170 |
+
```
|
| 171 |
+
|
| 172 |
+
## Advantages Over Original Model
|
| 173 |
+
|
| 174 |
+
### Structural Improvements
|
| 175 |
+
- **Controlled output**: Exactly 4 questions instead of variable numbers
|
| 176 |
+
- **No redundancy**: Eliminates multiple questions per attribute
|
| 177 |
+
- **Negative verification**: Includes proper negative questions (absent elements)
|
| 178 |
+
|
| 179 |
+
### Preserved Strengths
|
| 180 |
+
- **Domain expertise**: Retains deep TIFA knowledge from original training
|
| 181 |
+
- **Question quality**: Maintains high-quality question formulation
|
| 182 |
+
- **Visual focus**: Strong emphasis on verifiable visual elements
|
| 183 |
+
- **Natural language**: Experienced question generation capabilities
|
| 184 |
+
|
| 185 |
+
## Comparison with SmolLM2 Series
|
| 186 |
+
|
| 187 |
+
| Aspect | Llama2-TIFA-AWQ | SmolLM2 Series |
|
| 188 |
+
|--------|-----------------|----------------|
|
| 189 |
+
| **Starting point** | TIFA-specialized model | General instruction models |
|
| 190 |
+
| **Domain knowledge** | ✅ Pre-existing TIFA expertise | ⭐ Learned during fine-tuning |
|
| 191 |
+
| **Model size** | ~7B parameters (AWQ quantized) | 135M - 1.7B parameters |
|
| 192 |
+
| **Inference speed** | ~8 seconds (AWQ optimized) | ~3 seconds (small models) |
|
| 193 |
+
| **Training approach** | Structural refinement + quantization | Full task learning |
|
| 194 |
+
| **Memory efficiency** | ✅ AWQ quantized | ⭐ Naturally smaller |
|
| 195 |
+
| **Question quality** | ✅ Deep domain knowledge | ⭐ Systematic structure |
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
## Citation
|
| 199 |
+
|
| 200 |
+
```bibtex
|
| 201 |
+
@misc{llama2-tifa-refined-2025,
|
| 202 |
+
title={Llama2-TIFA: Structural Refinement of LLaMA 2 for Text-to-Image Faithfulness Assessment},
|
| 203 |
+
author={kawchar85},
|
| 204 |
+
year={2025},
|
| 205 |
+
url={https://huggingface.co/kawchar85/Llama2-TIFA-AWQ},
|
| 206 |
+
note={Fine-tuned from tifa-benchmark/llama2_tifa_question_generation}
|
| 207 |
+
}
|
| 208 |
+
```
|
| 209 |
+
|
| 210 |
+
## Model Ecosystem
|
| 211 |
+
|
| 212 |
+
This model complements the broader TIFA question generation ecosystem:
|
| 213 |
+
|
| 214 |
+
**Specialized TIFA models:**
|
| 215 |
+
- **Llama2-TIFA** ← *You are here* (Domain expert, refined structure)
|
| 216 |
+
|
| 217 |
+
**General→TIFA models:**
|
| 218 |
+
- **[SmolLM2-135M-Instruct-TIFA](https://huggingface.co/kawchar85/SmolLM2-135M-Instruct-TIFA)**: Compact version
|
| 219 |
+
- **[SmolLM2-360M-Instruct-TIFA](https://huggingface.co/kawchar85/SmolLM2-360M-Instruct-TIFA)**: Balanced version
|
| 220 |
+
- **[SmolLM2-1.7B-Instruct-TIFA](https://huggingface.co/kawchar85/SmolLM2-1.7B-Instruct-TIFA)**: Structured version
|
| 221 |
+
- **[SmolLM2-1.7B-Instruct-TIFA-Random](https://huggingface.co/kawchar85/SmolLM2-1.7B-Instruct-TIFA-Random)**: Flexible version
|