(content)
| 92 | return blocks |
| 93 | |
| 94 | def compute_vlm_ppl(content): |
| 95 | VLLM_BASE_URL = "http://localhost:7000/v1" |
| 96 | MODEL_ID = "Qwen/Qwen2.5-VL-7B-Instruct" |
| 97 | |
| 98 | client = OpenAI( |
| 99 | api_key="EMPTY", # vLLM ignores auth |
| 100 | base_url=VLLM_BASE_URL, |
| 101 | timeout=Timeout(5000) |
| 102 | ) |
| 103 | |
| 104 | resp = client.chat.completions.create( |
| 105 | model=MODEL_ID, |
| 106 | messages=[{ |
| 107 | "role": "user", |
| 108 | "content": content, |
| 109 | }], |
| 110 | temperature=0.0, |
| 111 | max_tokens=1, |
| 112 | logprobs=0, |
| 113 | extra_body={ |
| 114 | "prompt_logprobs": 1, |
| 115 | "echo": True |
| 116 | } |
| 117 | ) |
| 118 | |
| 119 | lp_list = resp.to_dict()["prompt_logprobs"] # list[dict] |
| 120 | total_lp = 0.0 |
| 121 | n_text = 0 |
| 122 | |
| 123 | for token_entry in lp_list: |
| 124 | if not token_entry: |
| 125 | continue |
| 126 | # find the sub-entry with rank==1 (the real token) |
| 127 | token_info = next(v for v in token_entry.values() if v["rank"] == 1) |
| 128 | tok, lp = token_info["decoded_token"], token_info["logprob"] |
| 129 | |
| 130 | # skip image sentinels / padding |
| 131 | if re.fullmatch(r"<\|?image[^>]*\|?>", tok): |
| 132 | continue |
| 133 | |
| 134 | total_lp += lp |
| 135 | n_text += 1 |
| 136 | |
| 137 | return math.exp(-total_lp / n_text) |
| 138 | |
| 139 | def compute_interleaved_ppl(paper_name, poster_method): |
| 140 | base_dir = f'eval_poster_markdown/{paper_name}/{poster_method}' |
no test coverage detected