CoolFace
Modelpublic

VulcanRaven/ChartQA-smolvlm

sourceHugging Faceapache-2.0updated 6mo agoView on Hugging Face
0likes
Model Card

ChartQA-smolvlm

SmolVLM-500M-Instruct fine-tuned with LoRA on ChartQA for chart question answering. LoRA adapters were merged into the base model for single-artifact deployment.

Model details

Base modelHuggingFaceTB/SmolVLM-500M-Instruct
DatasetHuggingFaceM4/ChartQA
TaskVisual question answering on chart/graph images
MethodLoRA (r=16, α=32, all projection layers, dropout=0.05)
Target modulesq_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
Precisionbfloat16
Epochs3
Batch size4
LR2e-4 with cosine warmup (5%)
OptimizerAdamW (fused)
MetricsExact Match, Relaxed Accuracy (5% tol), ANLS

Usage

Full model (recommended)

python
from PIL import Image
import torch
from transformers import AutoProcessor, AutoModelForImageTextToText

model_id = "VulcanRaven/ChartQA-smolvlm"
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForImageTextToText.from_pretrained(
    model_id, torch_dtype=torch.bfloat16
).cuda().eval()

image = Image.open("chart.png").convert("RGB")
query = "What is the highest value shown in the chart?"

messages = [{
    "role": "user",
    "content": [
        {"type": "image"},
        {"type": "text", "text": f"Question: {query}\nAnswer:"}
    ]
}]
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = processor(text=text, images=image, return_tensors="pt").to("cuda")
inputs["pixel_values"] = inputs["pixel_values"].to(torch.bfloat16)

with torch.inference_mode():
    gen_ids = model.generate(**inputs, max_new_tokens=32, do_sample=False)
answer = processor.tokenizer.decode(
    gen_ids[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True
).strip()
print(f"Q: {query}\nA: {answer}")

LoRA adapter variant (load + merge before inference)

python
from peft import PeftModel
from transformers import AutoModelForImageTextToText, AutoProcessor
import torch

base = AutoModelForImageTextToText.from_pretrained(
    "HuggingFaceTB/SmolVLM-500M-Instruct", torch_dtype=torch.bfloat16
)
model = PeftModel.from_pretrained(base, "VulcanRaven/ChartQA-smolvlm")
model = model.merge_and_unload().cuda().eval()
processor = AutoProcessor.from_pretrained("VulcanRaven/ChartQA-smolvlm")

# then run inference as above

Evaluation metrics

MetricDescription
Exact MatchNormalised string equality against any gold answer
Relaxed AccuracyNumeric tolerance of ±5%; falls back to exact match for non-numeric answers
ANLSAverage Normalised Levenshtein Similarity (threshold=0.5)

Design decisions

DecisionChoiceReason
Base modelSmolVLM-500M-InstructCompact VLM with strong chart understanding; fits in <4 GB VRAM
DatasetChartQAStandard benchmark for chart visual QA with multi-reference gold answers
Fine-tuningLoRA on all projection layersCovers attention + MLP; fast convergence with minimal memory overhead
Label maskingPrefix tokens masked to -100Model only learns to generate the answer, not repeat the question
DeploymentMerged full modelNo adapter loading code at inference; simpler and faster
Precisionbfloat16Numerically stable; works well even on resource-constrained GPUs

Training details

  • Hardware: NVIDIA Tesla T4
  • Data split: 80% train / 20% validation (from original train), full original test set
  • Validation: 50-batch subset evaluated after each epoch for speed
  • Best checkpoint: Saved based on highest Relaxed Accuracy on validation set
  • Gradient clipping: Max norm 1.0
  • Grad accumulation: 4 steps (effective batch size 16)