feat(exp): 四个 Arm 的实验编排与基准脚本
同一模型、同一批 5184 张图、同样 100 epoch,只换监督信号: - Arm C: VLM 重描述(唯一长 caption) - Arm D: 同 C 数据,模型缩到 13.4M(5.1M 非嵌入) - Arm E: prompt 压成 4 个共享模板 - Arm F: 颜色 + 车身两级模板 结果:C/D 颜色词被忽略(码一致率 0.75 / 0.60), E 降到 0.000 且色相 3/4 命中,F 在 20 格交叉积上只剩 1 列稳定。 bench_strata: strata(Qwen3.8)视觉描述的延迟与吞吐基准,1.06 s/img。 compare_gen: 多检查点批量出图对比。pdl.sh: 分片下载辅助。
This commit is contained in:
1 parent
5d2d3a2fb5
commit
9e29277715
7 files changed
+307
No files matched your search
@@ -0,0 +1,88 @@
|
||||
"""Benchmark the local strata vision endpoint on captioning."""
|
||||
import base64
|
||||
import io
|
||||
import json
|
||||
import tarfile
|
||||
import time
|
||||
import urllib.request
|
||||
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
|
||||
URL = "http://127.0.0.1:8080/v1/chat/completions"
|
||||
MODEL = "qwen3.8-flash-next-gyro-gyro-s"
|
||||
|
||||
|
||||
def post(payload, timeout=300):
|
||||
data = json.dumps(payload).encode()
|
||||
req = urllib.request.Request(URL, data=data, headers={"Content-Type": "application/json"})
|
||||
t0 = time.time()
|
||||
with urllib.request.urlopen(req, timeout=timeout) as r:
|
||||
body = json.loads(r.read().decode())
|
||||
return body, time.time() - t0
|
||||
|
||||
|
||||
def b64_jpeg(im, side=512):
|
||||
im = im.convert("RGB")
|
||||
w, h = im.size
|
||||
s = side / max(w, h)
|
||||
if s < 1:
|
||||
im = im.resize((int(w * s), int(h * s)), Image.BICUBIC)
|
||||
buf = io.BytesIO()
|
||||
im.save(buf, format="JPEG", quality=88)
|
||||
return base64.b64encode(buf.getvalue()).decode()
|
||||
|
||||
|
||||
def main():
|
||||
blobs = []
|
||||
with tarfile.open("../data_mm/shards/cc3m-0000.tar") as tf:
|
||||
for m in tf:
|
||||
if m.isfile() and m.name.endswith(".txt"):
|
||||
cap = tf.extractfile(m).read().decode("utf-8", "ignore").strip()
|
||||
if "car" in cap.lower():
|
||||
key = m.name[:-4]
|
||||
try:
|
||||
jm = tf.getmember(key + ".jpg")
|
||||
except KeyError:
|
||||
continue
|
||||
blobs.append(Image.open(io.BytesIO(tf.extractfile(jm).read())))
|
||||
if len(blobs) >= 4:
|
||||
break
|
||||
|
||||
prompt = ("Describe this image in one detailed sentence. "
|
||||
"Include the main subject's colour, what it is doing, and the setting. "
|
||||
"Answer with the sentence only, no preamble.")
|
||||
|
||||
print(f"{'run':>4} {'wall_s':>7} {'ptok':>5} {'ctok':>5} {'tok/s':>7} caption")
|
||||
for i, im in enumerate(blobs):
|
||||
b64 = b64_jpeg(im)
|
||||
payload = {
|
||||
"model": MODEL,
|
||||
"messages": [{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{"type": "text", "text": prompt},
|
||||
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{b64}"}},
|
||||
],
|
||||
}],
|
||||
"max_tokens": 80,
|
||||
"temperature": 0.2,
|
||||
"chat_template_kwargs": {"enable_thinking": False},
|
||||
}
|
||||
try:
|
||||
body, dt = post(payload)
|
||||
except Exception as e:
|
||||
print(f"{i:>4} ERROR {e}")
|
||||
continue
|
||||
ch = body["choices"][0]["message"]
|
||||
txt = (ch.get("content") or "").strip().replace("\n", " ")
|
||||
usage = body.get("usage", {})
|
||||
pt, ct = usage.get("prompt_tokens", 0), usage.get("completion_tokens", 0)
|
||||
tps = ct / dt if dt > 0 else 0
|
||||
print(f"{i:>4} {dt:7.2f} {pt:5d} {ct:5d} {tps:7.1f} {txt[:110]}")
|
||||
if ch.get("reasoning_content"):
|
||||
print(f" (reasoning: {ch['reasoning_content'][:80]})")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user