davanstrien HF Staff commited on
Commit
dc4b779
·
verified ·
1 Parent(s): 6d83d01

Sync from GitHub via hub-sync

Browse files
Files changed (1) hide show
  1. olmocr2-vllm.py +17 -6
olmocr2-vllm.py CHANGED
@@ -55,7 +55,6 @@ from tqdm.auto import tqdm
55
  # lets the plain default-image command work. On the vllm/vllm-openai image it's a harmless no-op.
56
  os.environ.setdefault("VLLM_USE_FLASHINFER_SAMPLER", "0")
57
  from vllm import LLM, SamplingParams
58
- from vllm.sampling_params import GuidedDecodingParams
59
 
60
  logging.basicConfig(level=logging.INFO)
61
  logger = logging.getLogger(__name__)
@@ -369,13 +368,25 @@ def main(
369
  "stop": ["<|im_end|>", "<|endoftext|>"],
370
  }
371
 
372
- # Add guided decoding if requested (enforces YAML front matter structure)
 
 
 
373
  if guided_decoding:
374
  logger.info("Enabling guided decoding with YAML front matter regex")
375
- guided_params = GuidedDecodingParams(
376
- regex=r"---\nprimary_language: (?:[a-z]{2}|null)\nis_rotation_valid: (?:True|False|true|false)\nrotation_correction: (?:0|90|180|270)\nis_table: (?:True|False|true|false)\nis_diagram: (?:True|False|true|false)\n(?:---|---\n[\s\S]+)"
377
- )
378
- sampling_params_kwargs["guided_decoding"] = guided_params
 
 
 
 
 
 
 
 
 
379
 
380
  sampling_params = SamplingParams(**sampling_params_kwargs)
381
 
 
55
  # lets the plain default-image command work. On the vllm/vllm-openai image it's a harmless no-op.
56
  os.environ.setdefault("VLLM_USE_FLASHINFER_SAMPLER", "0")
57
  from vllm import LLM, SamplingParams
 
58
 
59
  logging.basicConfig(level=logging.INFO)
60
  logger = logging.getLogger(__name__)
 
368
  "stop": ["<|im_end|>", "<|endoftext|>"],
369
  }
370
 
371
+ # Add guided decoding if requested (enforces YAML front matter structure).
372
+ # vLLM 0.22.x renamed this API: GuidedDecodingParams (guided_decoding=) →
373
+ # StructuredOutputsParams (structured_outputs=). Import lazily + shim so the
374
+ # default path (guided_decoding=False) never touches the moved symbol.
375
  if guided_decoding:
376
  logger.info("Enabling guided decoding with YAML front matter regex")
377
+ front_matter_regex = r"---\nprimary_language: (?:[a-z]{2}|null)\nis_rotation_valid: (?:True|False|true|false)\nrotation_correction: (?:0|90|180|270)\nis_table: (?:True|False|true|false)\nis_diagram: (?:True|False|true|false)\n(?:---|---\n[\s\S]+)"
378
+ try:
379
+ from vllm.sampling_params import StructuredOutputsParams
380
+
381
+ sampling_params_kwargs["structured_outputs"] = StructuredOutputsParams(
382
+ regex=front_matter_regex
383
+ )
384
+ except ImportError:
385
+ from vllm.sampling_params import GuidedDecodingParams
386
+
387
+ sampling_params_kwargs["guided_decoding"] = GuidedDecodingParams(
388
+ regex=front_matter_regex
389
+ )
390
 
391
  sampling_params = SamplingParams(**sampling_params_kwargs)
392