Files
xpu-llm-ports/lfm3/tests/vl/check_processor.py
T
Pascal LinxweilerandClaude Opus 5.5 1834792bb8 lfm3: add INT4, FP8 per-channel and VL notes, tests, eval and results
Sync the repo with the working directory: full NOTES.md (rounds 4-5, LFM3-VL),
VL tests and test images, quality eval, AutoRound W4A16 quantization scripts
and calibration recipe, the variant.sh MODEL/DOCKER_ENV options, and the
remaining benchmark results. Large regenerable artifacts (INT4 checkpoint,
ref_vl.pt, raw logprob dumps) stay out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 13:59:43 +01:00

26 lines
1.4 KiB
Python

"""Plugin's vendored processor (no trust_remote_code) vs Liquid's remote processor: same ids + pixels.
python3 check_processor.py mine|ref OUT.pt (run each in its own process; 'ref' does not import the plugin)"""
import sys, torch, numpy as np
from PIL import Image
from transformers import AutoProcessor
which, out = sys.argv[1], sys.argv[2]
if which == "mine":
import vllm_lfm3
vllm_lfm3.register()
proc = AutoProcessor.from_pretrained("/vl", trust_remote_code=(which == "ref"))
print(which, type(proc).__module__, type(proc.image_processor).__module__)
rng = np.random.default_rng(0)
res = {}
for (w, h) in [(640, 480), (100, 60), (2400, 400), (1024, 1024), (1920, 1080)]:
img = Image.fromarray(rng.integers(0, 255, (h, w, 3), dtype=np.uint8))
msgs = [{"role": "user", "content": [{"type": "image"}, {"type": "text", "text": "hi"}]}]
text = proc.apply_chat_template(msgs, add_generation_prompt=True, tokenize=False)
res[(w, h)] = dict(proc(text=text, images=[img], return_tensors="pt"))
torch.save(res, out)
if which == "mine":
ref = torch.load(out.replace("mine", "ref"))
for k, a in res.items():
b = ref[k]
print(k, "grid", a["image_grid_thw"].tolist(), "image tokens", int((a["input_ids"] == 125030).sum()),
"ids equal", torch.equal(a["input_ids"], b["input_ids"]), "pixels equal", torch.equal(a["pixel_values"], b["pixel_values"]))