import json, torchfrom safetensors import safe_openfrom huggingface_hub import hf_hub_downloadfrom transformers import AutoProcessor, Qwen3VLForConditionalGeneration MODEL_PATH = "Gyubeum/Qwen3-VL-8B-Instruct-UI-Genie-BT-256K"DEVICE = "cuda" model = Qwen3VLForConditionalGeneration.from_pretrained( MODEL_PATH, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True,).to(DEVICE).eval()processor = AutoProcessor.from_pretrained(MODEL_PATH, max_pixels=1_048_576) # `score.weight` is not wired into the base CausalLM class, so load it separately.index = json.load(open(hf_hub_download(MODEL_PATH, "model.safetensors.index.json")))shard = hf_hub_download(MODEL_PATH, index["weight_map"]["score.weight"])with safe_open(shard, framework="pt") as f: w = f.get_tensor("score.weight")score_head = torch.nn.Linear(w.shape[1], w.shape[0], bias=False)with torch.no_grad(): score_head.weight.copy_(w)score_head = score_head.to(DEVICE, dtype=torch.bfloat16) # score = score_head(hidden_states[:, last_non_pad_index, :])