File size: 2,425 Bytes
d5049a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from __future__ import annotations

import argparse
import os

import torch
from transformers import AutoConfig

from .common import (
    apply_chat_template,
    build_messages,
    load_rows,
    move_to_device,
    normalized_row,
    tokenizer_fingerprint,
)
from .modeling import load_base_model, load_processor


def main() -> None:
    parser = argparse.ArgumentParser(description="Qwen3.5 VLM environment preflight")
    parser.add_argument("--model", required=True)
    parser.add_argument("--data-dir", required=True)
    parser.add_argument("--split", default="train")
    parser.add_argument("--num-views", type=int, default=1)
    parser.add_argument("--max-length", type=int, default=2048)
    parser.add_argument("--load-model", action="store_true")
    parser.add_argument("--attn-implementation", default="sdpa")
    args = parser.parse_args()

    if not os.path.isdir(args.model):
        raise SystemExit(f"Local model directory does not exist: {args.model}")
    config = AutoConfig.from_pretrained(
        args.model, trust_remote_code=True, local_files_only=True
    )
    if not hasattr(config, "vision_config"):
        raise SystemExit(
            f"{args.model} is not recognized as a multimodal model (no vision_config)"
        )
    processor = load_processor(args.model)
    fingerprint = tokenizer_fingerprint(processor.tokenizer)
    row = normalized_row(load_rows(args.data_dir, args.split)[0])
    batch = apply_chat_template(
        processor,
        build_messages(row["question"], row["image_paths"], args.num_views),
        add_generation_prompt=True,
        max_length=args.max_length,
    )
    print(f"model_type={getattr(config, 'model_type', 'unknown')}")
    print(f"tokenizer_size={len(processor.tokenizer)}")
    print(f"tokenizer_sha256={fingerprint}")
    print(f"prompt_tokens={batch['input_ids'].shape[1]}")
    print(f"batch_keys={sorted(batch)}")
    if args.load_model:
        if not torch.cuda.is_available():
            raise SystemExit("--load-model requested but CUDA is unavailable")
        model = load_base_model(
            args.model, attn_implementation=args.attn_implementation
        ).cuda().eval()
        with torch.inference_mode():
            outputs = model(**move_to_device(batch, torch.device("cuda")))
        print(f"forward_logits_shape={tuple(outputs.logits.shape)}")
    print("PREFLIGHT_OK")


if __name__ == "__main__":
    main()