ó
    �®žj«!  ã                   ó  • S r SSKrSSKJr  SSKJrJrJrJr  SSK	J
r
JrJr  SSKJr  SSKJr  SSKJrJr  \R(                  " \5      r " S	 S
\5      r " S S\5      r " S S\5      r " S S\\5      r " S S\5      r " S S\5      rg)z—Engine options for VLM inference.

This module defines engine-specific configuration options that are independent
of model specifications and prompts.
é    N)ÚEnum)ÚAnyÚDictÚLiteralÚOptional)ÚAnyUrlÚFieldÚmodel_validator)ÚAcceleratorDevice)Údefault_compile_model)ÚBaseVlmEngineOptionsÚVlmEngineTypec                   ón   • \ rS rSr% Sr\R                  r\\R                     \	S'   \
" SSS9r\\	S'   Srg	)
ÚAutoInlineVlmEngineOptionsé   zñOptions for auto-selecting the best local inference engine.

Automatically selects the best available local engine based on:
- Platform (macOS -> MLX, Linux/Windows -> Transformers/VLLM)
- Available hardware (CUDA, MPS, CPU)
- Model support
Úengine_typeFz=Prefer VLLM over Transformers when both are available on CUDA©ÚdefaultÚdescriptionÚprefer_vllm© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   ÚAUTO_INLINEr   r   Ú__annotations__r	   r   ÚboolÚ__static_attributes__r   ó    Úa/home/mande/repo/quber/.venv/lib/python3.13/site-packages/docling/datamodel/vlm_engine_options.pyr   r      s<   ‡ ñð 7D×6OÑ6O€K�˜×2Ñ2Ñ3ÓOáØØSñ€K�ö r!   r   c                   ó"  • \ rS rSr% Sr\R                  r\\R                     \	S'   \
" SSS9r\\   \	S'   \
" SS	S9r\\	S
'   \
" SSS9r\\	S'   \
" SSS9r\\	S'   \
" SSS9r\\   \	S'   \
" SSS9r\\	S'   \
" SSS9r\\	S'   \
" \SS9r\\	S'   Srg)ÚTransformersVlmEngineOptionsé5   z6Options for HuggingFace Transformers inference engine.r   Nú%Device to use (auto-detected if None)r   ÚdeviceTz0Load model in 8-bit precision using bitsandbytesÚload_in_8bitg      @z%Threshold for LLM.int8() quantizationÚllm_int8_thresholdFz"Whether the model is pre-quantizedÚ	quantizedz+PyTorch dtype (e.g., 'float16', 'bfloat16')Útorch_dtypeú.Allow execution of custom code from model repoÚtrust_remote_codez&Enable key-value caching for attentionÚuse_kv_cachezIWhether to compile the model with torch.compile() for better performance.©Údefault_factoryr   Úcompile_modelr   )r   r   r   r   r   r   ÚTRANSFORMERSr   r   r   r	   r'   r   r   r(   r   r)   Úfloatr*   r+   Ústrr-   r.   r   r1   r    r   r!   r"   r$   r$   5   sò   ‡ Ù@à7D×7QÑ7Q€K�˜×3Ñ3Ñ4ÓQá*/ØÐ"Iñ+€FˆHÐ&Ñ'ó ñ ØÐ"Tñ€L�$ó ñ !&ØÐ!Hñ!Ð˜ó ñ ØÐ#Gñ€Iˆtó ñ "'ØÐ"Oñ"€K�˜#‘ó ñ $ØÐ#SñÐ�tó ñ ØÐ"Jñ€L�$ó ñ  Ø-Ø_ñ€M�4ö r!   r$   c                   ón   • \ rS rSr% Sr\R                  r\\R                     \	S'   \
" SSS9r\\	S'   Srg	)
ÚMlxVlmEngineOptionséa   z<Options for Apple MLX inference engine (Apple Silicon only).r   Fr,   r   r-   r   N)r   r   r   r   r   r   ÚMLXr   r   r   r	   r-   r   r    r   r!   r"   r6   r6   a   s8   ‡ ÙFà.;×.?Ñ.?€K�˜×*Ñ*Ñ+Ó?á#ØÐ#SñÐ�tö r!   r6   c                   ó,   • \ rS rSrSrSrSrSrSrSr	Sr
g	)
ÚVllmCudaGraphModeép   ab  CUDA graph capture mode for the vLLM v1 engine.

Controls whether and how vLLM captures CUDA graphs to speed up inference.
CUDA graphs reduce kernel-launch overhead by replaying a recorded sequence
of CUDA operations instead of launching each kernel individually.

NONE:
    Disable CUDA graphs entirely; everything runs in eager mode.
    Fastest startup, lowest steady-state throughput.
    Best for short-lived processes, notebooks, and debugging.

FULL:
    Capture the entire forward pass as one monolithic CUDA graph.
    Maximum graph coverage but requires very static execution shapes;
    may fail with some models or dynamic workloads.

PIECEWISE:
    Capture segments of the model (e.g. transformer blocks) as multiple
    smaller graphs between selected ops.  Handles dynamic shapes better
    than FULL while still accelerating most of the forward pass.

FULL_AND_PIECEWISE:
    Hybrid mode (default in many vLLM versions): FULL graphs for
    decode-only batches; PIECEWISE graphs for prefill and mixed
    prefill+decode batches.  Usually the best throughput option for
    typical LLM serving workloads.

FULL_DECODE_ONLY:
    FULL CUDA graphs only for decode batches; prefill and mixed batches
    run in eager mode.  Dramatically reduces graph-capture time and
    memory footprint compared to FULL_AND_PIECEWISE while still
    accelerating token generation.
ÚNONEÚFULLÚ	PIECEWISEÚFULL_AND_PIECEWISEÚFULL_DECODE_ONLYr   N)r   r   r   r   r   r<   r=   r>   r?   r@   r    r   r!   r"   r:   r:   p   s%   † ñ ðD €DØ€DØ€IØ-ÐØ)Ór!   r:   c                   ó   • \ rS rSr% Sr\R                  r\\R                     \	S'   \
" SSS9r\\   \	S'   \
" SS	S9r\\	S
'   \
" SSS9r\\	S'   \
" SSS9r\\	S'   \
" \R*                  SS9r\\	S'   \
" SSS9r\\	S'   Srg)ÚVllmVlmEngineOptionséš   z<Options for vLLM inference engine (high-throughput serving).r   Nr&   r   r'   é   z%Number of GPUs for tensor parallelismÚtensor_parallel_sizegÍÌÌÌÌÌì?zFraction of GPU memory to useÚgpu_memory_utilizationFr,   r-   ztCUDA graph capture mode (vLLM v1 engine only). See VllmCudaGraphMode for the available options and their trade-offs.Úcudagraph_modeÚautoag  vLLM model implementation backend. Accepted values depend on the installed vLLM version; common values are 'auto', 'vllm', and 'transformers'. 'auto' uses vLLM's native implementation when available and otherwise falls back to the Transformers modeling backend; 'vllm' forces the native implementation; 'transformers' forces the Transformers modeling backend.Ú
model_implr   )r   r   r   r   r   r   ÚVLLMr   r   r   r	   r'   r   r   rE   ÚintrF   r3   r-   r   r:   r>   rG   rI   r4   r    r   r!   r"   rB   rB   š   sÊ   ‡ ÙFà/<×/AÑ/A€K�˜×+Ñ+Ñ,ÓAá*/ØÐ"Iñ+€FˆHÐ&Ñ'ó ñ !&ØÐFñ!Ð˜#ó ñ %*ØÐ!@ñ%Ð˜Eó ñ $ØÐ#SñÐ�tó ñ ).Ø!×+Ñ+ðTñ)€NÐ%ó ñ ØðGñ
€J�ö 
r!   rB   c                   óö   • \ rS rSr% Sr\" SS9r\\S'   \" \	" S5      SS9r
\	\S	'   \" \S
S9r\\\4   \S'   \" \SS9r\\\4   \S'   \" SSS9r\\S'   \" SSS9r\\S'   \" SS9\S\S\4S j5       5       rSrg)ÚApiVlmEngineOptionséÉ   zƒOptions for API-based VLM services.

Supports multiple API variants:
- Generic OpenAI-compatible API
- Ollama
- LM Studio
- OpenAI
zAPI variant to use)r   r   ú*http://localhost:11434/v1/chat/completionszAPI endpoint URLr   ÚurlzHTTP headers for authenticationr/   Úheadersz3Additional API parameters (model, max_tokens, etc.)Úparamsg      N@zRequest timeout in secondsÚtimeoutrD   zNumber of concurrent requestsÚconcurrencyÚbefore)ÚmodeÚdataÚreturnc                 ó2  • [        U[        5      (       d  U$ SU;  a  0 UES[        R                  0EnSU;  a]  US   nU[        R                  :X  a
  0 UESS0EnU$ U[        R
                  :X  a
  0 UESS0EnU$ U[        R                  :X  a  0 UESS0EnU$ )z@Supply default engine_type and URL when not explicitly provided.r   rP   rO   z)http://localhost:1234/v1/chat/completionsz*https://api.openai.com/v1/chat/completions)Ú
isinstanceÚdictr   ÚAPIÚ
API_OLLAMAÚAPI_LMSTUDIOÚ
API_OPENAI)ÚclsrW   r   s      r"   Ú_apply_defaultsÚ#ApiVlmEngineOptions._apply_defaultsç   s¾   € ô ˜$¤×%Ñ%ØˆKØ Ó$Ø=�dÐ=˜M¬=×+<Ñ+<Ñ=ˆDØ˜ÓØ˜}Ñ-ˆKØœm×6Ñ6Ó6ØT˜$ÐT Ð'SÑT�ð
 ˆð	 ¤× :Ñ :Ó:ØS˜$ÐS Ð'RÑS�ð ˆð ¤× 8Ñ 8Ó8ØT˜$ÐT Ð'SÑT�Øˆr!   r   N)r   r   r   r   r   r	   r   r   r   r   rP   r[   rQ   r   r4   rR   r   rS   r3   rT   rK   r
   Úclassmethodra   r    r   r!   r"   rM   rM   É   sË   ‡ ññ "'Ð3GÑ!H€K�ÓHáÙÐCÓDØ&ñ€Cˆó ñ
 $ØÐ*Kñ€GˆT�#�s�(‰^ó ñ #ØØIñ€FˆD��c�‰Nó ñ
  4Ð5QÑR€GˆUÓRá QÐ4SÑT€K�ÓTá˜(Ñ#Øð 3ð ¨3ó ó ó $ór!   rM   )r   ÚloggingÚenumr   Útypingr   r   r   r   Úpydanticr   r	   r
   Ú%docling.datamodel.accelerator_optionsr   Údocling.datamodel.settingsr   Ú)docling.models.inference_engines.vlm.baser   r   Ú	getLoggerr   Ú_logr   r$   r6   r4   r:   rB   rM   r   r!   r"   Ú<module>rm      s�   ðñó Ý ß /Ó /ç 3Ñ 3å CÝ <÷ð
 ×Ò˜Ó"€ôÐ!5ô ô,$Ð#7ô $ôXÐ.ô ô'*˜˜Tô '*ôT'Ð/ô 'ô^.Ð.õ .r!   