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>
56 lines
2.2 KiB
Python
56 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Image cost split: CPU preprocessing (Liquid's processor, vendored) and XPU vision tower + projector
|
|
(our plugin inside a vLLM engine, via LLM.apply_model, synchronized), per image size.
|
|
|
|
python3 encoder_timing.py MODEL_DIR IMAGE OUT.json
|
|
"""
|
|
import json, statistics, sys, time
|
|
import torch
|
|
from PIL import Image
|
|
|
|
|
|
def main():
|
|
from vllm import LLM
|
|
from transformers import AutoProcessor
|
|
import vllm_lfm3
|
|
|
|
model_dir, image, out = sys.argv[1:4]
|
|
vllm_lfm3.register()
|
|
proc = AutoProcessor.from_pretrained(model_dir)
|
|
src = Image.open(image).convert("RGB")
|
|
sizes = {"512x512": (512, 512), "1024x768": (1024, 768), "1024x1024": (1024, 1024),
|
|
"1920x1080": (1920, 1080), "2048x2048": (2048, 2048)}
|
|
llm = LLM(model=model_dir, dtype="bfloat16", max_model_len=8192, gpu_memory_utilization=0.4,
|
|
limit_mm_per_prompt={"image": 4}, enforce_eager=True)
|
|
res = {}
|
|
for name, size in sizes.items():
|
|
im = src.resize(size, Image.BICUBIC)
|
|
cpu = []
|
|
for _ in range(5):
|
|
t0 = time.perf_counter()
|
|
x = proc.image_processor(images=[im], return_tensors="pt")
|
|
cpu.append((time.perf_counter() - t0) * 1000)
|
|
pv, grid = x["pixel_values"], x["image_grid_thw"]
|
|
|
|
def run(model, pv=pv, grid=grid):
|
|
dev = next(model.parameters()).device
|
|
pv_d = pv.to(dev)
|
|
times = []
|
|
for i in range(8):
|
|
torch.xpu.synchronize(); t0 = time.perf_counter()
|
|
with torch.no_grad():
|
|
model.multi_modal_projector(model.vision_tower(pv_d, grid.tolist()))
|
|
torch.xpu.synchronize(); times.append((time.perf_counter() - t0) * 1000)
|
|
return times[2:] # first runs warm up kernels for this shape
|
|
|
|
gpu = llm.apply_model(run)[0]
|
|
res[name] = {"image_tokens": int(grid.prod()) // 4, "patches": int(grid.prod()),
|
|
"preprocess_cpu_ms": round(statistics.median(cpu), 1),
|
|
"encoder_xpu_ms": round(statistics.median(gpu), 1)}
|
|
print(name, res[name], flush=True)
|
|
json.dump(res, open(out, "w"), indent=1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|