echo / MVP /test_multimodal_forward.py
void0x14
feat: multimodal model anahtar teslim + test + rapor
598b018 unverified
Raw History Blame Contribute Delete
2.89 kB
import sys, traceback
print("STEP 0: imports", flush=True)
import torch
from transformers import Qwen3_5ForConditionalGeneration, AutoTokenizer, Qwen3VLProcessor, Qwen2VLImageProcessor, Qwen3VLVideoProcessor
MODEL_DIR = "/home/void0x14/Documents/echo/MVP/artifacts/qwen35-distilled-n4-multimodal"
print("STEP 1: tokenizer", flush=True)
tok = AutoTokenizer.from_pretrained(MODEL_DIR)
print(" image_token_id:", getattr(tok, "image_token_id", None), flush=True)
print(" video_token_id:", getattr(tok, "video_token_id", None), flush=True)
print(" pad:", tok.pad_token, flush=True)
print("STEP 2: image processor", flush=True)
img_pp = Qwen2VLImageProcessor.from_pretrained(MODEL_DIR)
print("STEP 3: video processor", flush=True)
try:
vid_pp = Qwen3VLVideoProcessor.from_pretrained(MODEL_DIR)
print(" video processor OK", flush=True)
except Exception as e:
print(" video processor FAIL:", type(e).__name__, str(e)[:200], flush=True)
vid_pp = None
print("STEP 4: processor bypass", flush=True)
from transformers import AutoConfig
cfg = AutoConfig.from_pretrained(MODEL_DIR)
print(" cfg image_token_id:", cfg.image_token_id, flush=True)
proc = Qwen3VLProcessor.__new__(Qwen3VLProcessor)
proc.image_token = "<|image_pad|>"
proc.video_token = "<|video_pad|>"
proc.vision_start_token = "<|vision_start|>"
proc.vision_end_token = "<|vision_end|>"
proc.image_token_id = cfg.image_token_id
proc.video_token_id = cfg.video_token_id
proc.vision_start_token_id = cfg.vision_start_token_id
proc.vision_end_token_id = cfg.vision_end_token_id
proc.tokenizer = tok
proc.image_processor = img_pp
proc.video_processor = vid_pp
proc.chat_template = tok.chat_template
print(" processor bypass OK", flush=True)
print("TOKEN SABITLERI KURULDU", flush=True)
print("STEP 5: load model", flush=True)
model = Qwen3_5ForConditionalGeneration.from_pretrained(MODEL_DIR, torch_dtype=torch.float32)
model.eval()
print(" model loaded", flush=True)
print("STEP 6: build inputs", flush=True)
import numpy as np
from PIL import Image
img = Image.new("RGB", (224, 224), (120, 60, 200))
messages = [{"role": "user", "content": [{"type": "image"}, {"type": "text", "text": "Bu resimde ne var?"}]}]
text = tok.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
print(" chat text:", text[:120], flush=True)
inputs = proc(text=[text], images=[img], return_tensors="pt")
print(" input keys:", list(inputs.keys()), flush=True)
print(" input_ids shape:", inputs["input_ids"].shape, flush=True)
print(" pixel_values shape:", inputs["pixel_values"].shape, flush=True)
print("STEP 7: forward", flush=True)
with torch.no_grad():
out = model(**inputs)
print("LOGITS:", tuple(out.logits.shape), flush=True)
pred = out.logits[0, -1].argmax().item()
print(" last token pred:", pred, tok.decode([pred])[:50], flush=True)
print("MULTIMODAL FORWARD OK", flush=True)