vllm.model_executor.models.unlimited_ocr2
¶
Optional page-count stopping guard for Unlimited-OCR-2.
Classes:
-
PageCountGuard–Per-request page-count state machine over the generated tokens.
-
PageCountGuardLogitsProcessor–Page-count guard for Unlimited-OCR-2 multi-page parsing.
PageCountGuard
¶
Per-request page-count state machine over the generated tokens.
CPU-friendly core of the processor: token bookkeeping is plain Python ints/lists, only the one-row logits edit touches torch.
Methods:
-
seed_expected_pages–Count the prompt's page markers; called once the prompt is known.
-
step–Apply the guard to one row of logits, in place.
Source code in vllm/model_executor/models/unlimited_ocr2.py
seed_expected_pages(prompt_ids)
¶
Count the prompt's page markers; called once the prompt is known.
step(output_ids, logits)
¶
Apply the guard to one row of logits, in place.
Source code in vllm/model_executor/models/unlimited_ocr2.py
PageCountGuardLogitsProcessor
¶
Bases: LogitsProcessor
Page-count guard for Unlimited-OCR-2 multi-page parsing.
In the multi-page layout ("<PAGE><image>" * n_pages + "Multi page
parsing.") the model must emit exactly one <PAGE> marker per prompt
page marker. This request-level guard enforces that contract, mirroring
the reference _uocr_page_count_guard:
- while fewer
<PAGE>markers than prompt pages have been generated, EOS is masked so a page cannot be terminated early; - once the page count is reached EOS is allowed, and generating further
<PAGE>markers forces EOS; - each page is capped at
max_page_tokensgenerated tokens -- hitting the cap forces<PAGE>(next page) or EOS (last page); - prompts without a
<PAGE>marker (single-page requests) pass through.
Forced transitions yield to existing token masks from other sampling constraints when their target token is unavailable. EOS is retained if suppressing it would leave no finite logits.
Register it via the CLI::
--logits-processors \
vllm.model_executor.models.unlimited_ocr2:PageCountGuardLogitsProcessor
Per-request parameters are read from SamplingParams.extra_args
(page_token_id, eos_token_id, max_page_tokens); the token ids
fall back to hf_config.sparse_attention_config.page_token_id and
hf_config.eos_token_id when not given. The processor is inactive for
requests (or v1 configs) where no page token id can be resolved.
GPU state is keyed by the persistent request slot. The prompt is scanned once; subsequent steps scan only newly committed output tokens.
Source code in vllm/model_executor/models/unlimited_ocr2.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |