
    5pjb              	          S SK r S SKrS SKJrJr  S SKJr  S SKJr  S SKJ	r	J
r
  S SKJrJr  SSKJrJrJr  \	(       a  SS	KJr  SS
KJr  SSKJr  \R0                  " \5      rS\S\4S jrSrSrSSS.S\S\S-  S\S-  S\4S jjr  " S S\!\5      r" " S S\!\5      r# " S S\!\5      r$\ " S S5      5       r%\ " S S5      5       r&g)     N)	dataclassfield)datetime)Enum)TYPE_CHECKINGOptional)InferenceEndpointErrorInferenceEndpointTimeoutError   )get_sessionloggingparse_datetimeHfApiInferenceClientAsyncInferenceClientcustom_imagereturnc                     SU ;   a  SU 0$ U $ )a  Build the `model.image` payload of an Inference Endpoint from a user-provided image dict.

`model.image` is a union keyed by variant (`{"vLLM": {...}}`, `{"custom": {...}}`, ...). Only a flat
container dict has a top-level `url` (required server-side, and no variant is named `url`), so dicts with
one are wrapped in `{"custom": ...}`. Everything else is forwarded as-is, so variants added to the API
later work without a release.
urlcustom )r   s    `/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/huggingface_hub/_inference_endpoints.py_build_endpoint_image_payloadr      s     ,''    )sGLangvLLM)r   )tensor_parallel_sizedata_parallel_sizeimager    r!   c                <   [        [        U 5      S5      nUc  [        S5      eUS[        4US[        44 HF  u  pEnUc  M  X6;  d  M  [
        R                  " SU SU SSR                  U5       S	3[        5        MH     U0 X   E0n Ub  XU   S
'   Ub  X U   S'   U $ )a  Write the parallelism sizes into a `model.image` payload.

They are engine settings, so they live inside the engine config (`{"vLLM": {"url": ..., "tensorParallelSize": 8}}`)
rather than at the top level. Returns a new image dict, the input is left untouched.
Nz=Cannot set the parallelism sizes: the image payload is empty.r    r!   `z!` is not a known setting of the 'zA' image: the API will silently drop it. Engines that support it: z, .tensorParallelSizedataParallelSize)	nextiter
ValueError_TENSOR_PARALLEL_IMAGE_KEYS_DATA_PARALLEL_IMAGE_KEYSwarningswarnjoinUserWarning)r"   r    r!   	image_keyvaluename	supporteds          r   _set_parallelism_in_imager5   )   s     T%[$'IXYY 
57RS	13LM#Y !;MMD6:9+ F--1YYy-A,B!E# ,5+,-E'1Ei-.%/Ai+,Lr   c                   4    \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rg)InferenceEndpointStatusK   pendinginitializingupdatingupdateFailedrunningpausedfailedscaledToZeror   N)__name__
__module____qualname____firstlineno__PENDINGINITIALIZINGUPDATINGUPDATE_FAILEDRUNNINGPAUSEDFAILEDSCALED_TO_ZERO__static_attributes__r   r   r   r7   r7   K   s*    G!LH"MGFF#Nr   r7   c                   $    \ rS rSrSrSrSrSrSrg)InferenceEndpointTypeV   public	protectedauthenticatedprivater   N)	rA   rB   rC   rD   PUBlIC	PROTECTEDAUTHENTICATEDPRIVATErM   r   r   r   rO   rO   V   s    FI#MGr   rO   c                       \ rS rSrSrSrSrg)InferenceEndpointScalingMetric]   pendingRequestshardwareUsager   N)rA   rB   rC   rD   PENDING_REQUESTSHARDWARE_USAGErM   r   r   r   rZ   rZ   ]   s    ($Nr   rZ   c            #       >   \ rS rSr% Sr\" SS9r\\S'   \\S'   \" SS9r	\\S'   \" SS9r
\\S'   \" SS9r\\S	'   \" SS9r\S
-  \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SS9r\\-  S
-  \S'   \" SSS9rS\S'   \ S9S\S\S\\-  S
-  S\S   SS 4
S jj5       rS:S jr\S;S j5       r \S<S j5       r!S=S \"S
-  S!\"SS 4S" jjr#S>S# jr$S
S
S
S
S
S
S
S
S
S
S
S
S
S
S
S
S$.S%\S
-  S&\S
-  S'\S
-  S(\"S
-  S)\"S
-  S*\"S
-  S\S
-  S\S
-  S\S
-  S\S
-  S+\S
-  S,\%\   S
-  S-\%\   S
-  S.\"S
-  S/\"S
-  S0\\\4   S
-  SS 4"S1 jjr&S>S2 jr'S?S3\SS 4S4 jjr(S>S5 jr)S:S6 jr*S:S7 jr+S8r,g
)@InferenceEndpointb   a5  
Contains information about a deployed Inference Endpoint.

Args:
    name (`str`):
        The unique name of the Inference Endpoint.
    namespace (`str`):
        The namespace where the Inference Endpoint is located.
    repository (`str`):
        The name of the model repository deployed on this Inference Endpoint.
    status ([`InferenceEndpointStatus`]):
        The current status of the Inference Endpoint.
    url (`str`, *optional*):
        The URL of the Inference Endpoint, if available. Only a deployed Inference Endpoint will have a URL.
    framework (`str`):
        The machine learning framework used for the model.
    revision (`str`):
        The specific model revision deployed on the Inference Endpoint.
    task (`str`):
        The task associated with the deployed model.
    created_at (`datetime.datetime`):
        The timestamp when the Inference Endpoint was created.
    updated_at (`datetime.datetime`):
        The timestamp of the last update of the Inference Endpoint.
    type ([`InferenceEndpointType`]):
        The type of the Inference Endpoint (public, authenticated, private).
    raw (`dict`):
        The raw dictionary data returned from the API.
    token (`str` or `bool`, *optional*):
        Authentication token for the Inference Endpoint, if set when requesting the API. Will default to the
        locally saved token if not provided. Pass `token=False` if you don't want to send your token to the server.

Example:
    ```python
    >>> from huggingface_hub import get_inference_endpoint
    >>> endpoint = get_inference_endpoint("my-text-to-image")
    >>> endpoint
    InferenceEndpoint(name='my-text-to-image', ...)

    # Get status
    >>> endpoint.status
    'running'
    >>> endpoint.url
    'https://my-text-to-image.region.vendor.endpoints.huggingface.cloud'

    # Run inference
    >>> endpoint.client.text_to_image(...)

    # Pause endpoint to save $$$
    >>> endpoint.pause()

    # ...
    # Resume and wait for deployment
    >>> endpoint.resume()
    >>> endpoint.wait()
    >>> endpoint.client.text_to_image(...)
    ```
F)initr3   	namespace
repositorystatushealth_routeNr   )reprrc   	frameworkrevisiontask
created_at
updated_attype)rh   raw)rh   compare_tokenr   _apitokenapir   c                 N    Uc  SSK Jn  U" 5       nUc  UR                  nU " XX4S9$ )z&Initialize object from raw dictionary.r   r   )ro   rd   rq   rr   )hf_apir   rs   )clsro   rd   rs   rt   r   s         r   from_rawInferenceEndpoint.from_raw   s0    
 ;%'C=IIE sHHr   c                 $    U R                  5         g)z$Populate fields from raw dictionary.N)_populate_from_rawselfs    r   __post_init__InferenceEndpoint.__post_init__   s    !r   c                 t    U R                   c  [        S5      eSSKJn  U" U R                   U R                  S9$ )zReturns a client to make predictions on this Inference Endpoint.

Returns:
    [`InferenceClient`]: an inference client pointing to the deployed endpoint.

Raises:
    [`InferenceEndpointError`]: If the Inference Endpoint is not yet deployed.
Cannot create a client for this Inference Endpoint as it is not yet deployed. Please wait for the Inference Endpoint to be deployed using `endpoint.wait()` and try again.r   r   modelrs   )r   r	   inference._clientr   rq   )r}   r   s     r   clientInferenceEndpoint.client   sA     88(o  	7((++
 	
r   c                 t    U R                   c  [        S5      eSSKJn  U" U R                   U R                  S9$ )a  Returns a client to make predictions on this Inference Endpoint.

Returns:
    [`AsyncInferenceClient`]: an asyncio-compatible inference client pointing to the deployed endpoint.

Raises:
    [`InferenceEndpointError`]: If the Inference Endpoint is not yet deployed.
r   r   r   r   )r   r	   "inference._generated._async_clientr   rq   )r}   r   s     r   async_clientInferenceEndpoint.async_client   sB     88(o  	M#((++
 	
r   timeoutrefresh_everyc                    Ub  US:  a  [        S5      eUS::  a  [        S5      e[        R                  " 5       n U R                  [        R                  :X  a  [        SU R                   S35      eU R                  [        R                  :X  a  [        SU R                   S35      eU R                  [        R                  :X  a  U R                  b  U R                  R                  S5       SU R                  R                  S5       3n[        5       R                  X@R                  R!                  U R"                  S9S	9nUR$                  S
:X  a  [&        R)                  S5        U $ Ub'  [        R                  " 5       U-
  U:  a  [+        S5      e[&        R)                  SU R                   SU S35        [        R,                  " U5        U R/                  5         GM  )a  Wait for the Inference Endpoint to be deployed.

Information from the server will be fetched every 1s. If the Inference Endpoint is not deployed after `timeout`
seconds, a [`InferenceEndpointTimeoutError`] will be raised. The [`InferenceEndpoint`] will be mutated in place with the latest
data.

Args:
    timeout (`int`, *optional*):
        The maximum time to wait for the Inference Endpoint to be deployed, in seconds. If `None`, will wait
        indefinitely.
    refresh_every (`int`, *optional*):
        The time to wait between each fetch of the Inference Endpoint status, in seconds. Defaults to 5s.

Returns:
    [`InferenceEndpoint`]: the same Inference Endpoint, mutated in place with the latest data.

Raises:
    [`InferenceEndpointError`]
        If the Inference Endpoint ended up in a failed state.
    [`InferenceEndpointTimeoutError`]
        If the Inference Endpoint is not deployed after `timeout` seconds.
r   z`timeout` cannot be negative.z!`refresh_every` must be positive.zInference Endpoint z> failed to deploy. Please check the logs for more information.z> failed to update. Please check the logs for more information./)rs   )headers   z'Inference Endpoint is ready to be used.z<Timeout while waiting for Inference Endpoint to be deployed.z(Inference Endpoint is not deployed yet (z). Waiting zs...)r*   timerf   r7   rK   r	   r3   rH   rI   r   rstriprg   lstripr   getrr   _build_hf_headersrq   status_codeloggerinfor
   sleepfetch)r}   r   r   start_health_urlresponses         r   waitInferenceEndpoint.wait   s   . 7Q;<==A@AA		{{5<<<,)$))4rs  {{5CCC,)$))4rs  {{5===$((BV!%!5 6a8I8I8P8PQT8U7VW&=,,[))B]B]dhdodoB]Bp,q''3.KK IJK"99;&078vwwKKB4;;-{[hZiimnoJJ}%JJL- r   c                     U R                   R                  U R                  U R                  U R                  S9nUR
                  U l        U R                  5         U $ )zFetch latest information about the Inference Endpoint.

Returns:
    [`InferenceEndpoint`]: the same Inference Endpoint, mutated in place with the latest data.
r3   rd   rs   )rr   get_inference_endpointr3   rd   rq   ro   r{   r}   objs     r   r   InferenceEndpoint.fetch*  sJ     ii..DII_c_j_j.k77!r   )acceleratorinstance_sizeinstance_typemin_replicamax_replicascale_to_zero_timeoutre   ri   rj   rk   r   container_commandcontainer_argsr    r!   secretsr   r   r   r   r   r   r   r   r   r    r!   r   c                    U R                   R                  U R                  U R                  UUUUUUUUU	U
UUUUUUU R                  S9nUR
                  U l        U R                  5         U $ )a.  Update the Inference Endpoint.

This method allows the update of either the compute configuration, the deployed model, or both. All arguments are
optional but at least one must be provided.

This is an alias for [`HfApi.update_inference_endpoint`]. The current object is mutated in place with the
latest data from the server.

Args:
    accelerator (`str`, *optional*):
        The hardware accelerator to be used for inference (e.g. `"cpu"`).
    instance_size (`str`, *optional*):
        The size or type of the instance to be used for hosting the model (e.g. `"x4"`).
    instance_type (`str`, *optional*):
        The cloud instance type where the Inference Endpoint will be deployed (e.g. `"intel-icl"`).
    min_replica (`int`, *optional*):
        The minimum number of replicas (instances) to keep running for the Inference Endpoint.
    max_replica (`int`, *optional*):
        The maximum number of replicas (instances) to scale to for the Inference Endpoint.
    scale_to_zero_timeout (`int`, *optional*):
        The duration in minutes before an inactive endpoint is scaled to zero.

    repository (`str`, *optional*):
        The name of the model repository associated with the Inference Endpoint (e.g. `"gpt2"`).
    framework (`str`, *optional*):
        The machine learning framework used for the model (e.g. `"custom"`).
    revision (`str`, *optional*):
        The specific model revision to deploy on the Inference Endpoint (e.g. `"6c0e6080953db56375760c0471a8c5f2929baf11"`).
    task (`str`, *optional*):
        The task on which to deploy the model (e.g. `"text-classification"`).
    custom_image (`dict`, *optional*):
        The container image to run. Either a dict keyed by image variant (e.g.
        `{"vLLM": {"url": "vllm/vllm-openai:v0.23.0", "port": 8000}}`, also `sGLang`, `tgi`, `tei`,
        `llamacpp`, `hfServe`, ...), which is forwarded as-is, or a flat dict describing a custom
        container (e.g. `{"url": ..., "port": ...}`), which is sent as `{"custom": ...}`.
    container_command (`list[str]`, *optional*):
        Override the container entrypoint command (maps to `model.command` in the API payload). Works with
        both managed engine images (e.g. vLLM, SGLang) and custom images.
    container_args (`list[str]`, *optional*):
        Arguments appended to the container entrypoint (maps to `model.args` in the API payload). Works with
        both managed engine images (e.g. vLLM, SGLang) and custom images.
    tensor_parallel_size (`int`, *optional*):
        Number of accelerators to shard a single model copy across (vLLM and SGLang images). When
        `custom_image` is not given, the image currently configured on the endpoint is fetched and updated
        in place, as the API requires `model.image` as a whole.
    data_parallel_size (`int`, *optional*):
        Number of model copies to run, one per accelerator (vLLM images).
    secrets (`dict[str, str]`, *optional*):
        Secret values to inject in the container environment.
Returns:
    [`InferenceEndpoint`]: the same Inference Endpoint, mutated in place with the latest data.
)r3   rd   r   r   r   r   r   r   re   ri   rj   rk   r   r   r   r    r!   r   rs   )rr   update_inference_endpointr3   rd   rq   ro   r{   )r}   r   r   r   r   r   r   re   ri   rj   rk   r   r   r   r    r!   r   r   s                     r   updateInferenceEndpoint.update5  s    V ii11nn#''##"7!%/)!51++' 2 
. 77!r   c                     U R                   R                  U R                  U R                  U R                  S9nUR
                  U l        U R                  5         U $ )a/  Pause the Inference Endpoint.

A paused Inference Endpoint will not be charged. It can be resumed at any time using [`InferenceEndpoint.resume`].
This is different from scaling the Inference Endpoint to zero with [`InferenceEndpoint.scale_to_zero`], which
would be automatically restarted when a request is made to it.

This is an alias for [`HfApi.pause_inference_endpoint`]. The current object is mutated in place with the
latest data from the server.

Returns:
    [`InferenceEndpoint`]: the same Inference Endpoint, mutated in place with the latest data.
r   )rr   pause_inference_endpointr3   rd   rq   ro   r{   r   s     r   pauseInferenceEndpoint.pause  sJ     ii00dii4>>aealal0m77!r   
running_okc                     U R                   R                  U R                  U R                  XR                  S9nUR
                  U l        U R                  5         U $ )a  Resume the Inference Endpoint.

This is an alias for [`HfApi.resume_inference_endpoint`]. The current object is mutated in place with the
latest data from the server.

Args:
    running_ok (`bool`, *optional*):
        If `True`, the method will not raise an error if the Inference Endpoint is already running. Defaults to
        `True`.

Returns:
    [`InferenceEndpoint`]: the same Inference Endpoint, mutated in place with the latest data.
)r3   rd   r   rs   )rr   resume_inference_endpointr3   rd   rq   ro   r{   )r}   r   r   s      r   resumeInferenceEndpoint.resume  sP     ii11dnnS^S^ 2 
 77!r   c                     U R                   R                  U R                  U R                  U R                  S9nUR
                  U l        U R                  5         U $ )a;  Scale Inference Endpoint to zero.

An Inference Endpoint scaled to zero will not be charged. It will be resumed on the next request to it, with a
cold start delay. This is different from pausing the Inference Endpoint with [`InferenceEndpoint.pause`], which
would require a manual resume with [`InferenceEndpoint.resume`].

This is an alias for [`HfApi.scale_to_zero_inference_endpoint`]. The current object is mutated in place with the
latest data from the server.

Returns:
    [`InferenceEndpoint`]: the same Inference Endpoint, mutated in place with the latest data.
r   )rr    scale_to_zero_inference_endpointr3   rd   rq   ro   r{   r   s     r   scale_to_zeroInferenceEndpoint.scale_to_zero  sM     ii88diiSWSaSaimitit8u77!r   c                 v    U R                   R                  U R                  U R                  U R                  S9  g)a4  Delete the Inference Endpoint.

This operation is not reversible. If you don't want to be charged for an Inference Endpoint, it is preferable
to pause it with [`InferenceEndpoint.pause`] or scale it to zero with [`InferenceEndpoint.scale_to_zero`].

This is an alias for [`HfApi.delete_inference_endpoint`].
r   N)rr   delete_inference_endpointr3   rd   rq   r|   s    r   deleteInferenceEndpoint.delete  s,     			++dnn\`\g\g+hr   c                 (   U R                   S   U l        U R                   S   S   U l        U R                   S   S   U l        U R                   S   R	                  S5      U l        U R                   S   U l        U R                   S   S   U l        U R                   S   S	   U l        U R                   S   S
   U l	        [        U R                   S   S   5      U l        [        U R                   S   S   5      U l        U R                   S   U l        g)zmPopulate fields from raw dictionary.

Called in __post_init__ + each time the Inference Endpoint is updated.
r3   r   re   rf   stater   healthRouteri   rj   rk   	createdAt	updatedAtrn   N)ro   r3   re   rf   r   r   rg   ri   rj   rk   r   rl   rm   rn   r|   s    r   r{   $InferenceEndpoint._populate_from_raw  s     HHV$	((7+L9hhx(188H%))%0 HH]3 '*;7)*5HHW%f-	(();K)HI(();K)HIHHV$	r   )rl   ri   rg   r3   ro   re   rj   rf   rk   rn   rm   r   )NN)r   N)r   r   )r   r   )N   )r   ra   )T)-rA   rB   rC   rD   __doc__r   r3   str__annotations__re   rf   r7   rg   r   ri   rj   rk   rl   r   rm   rn   rO   ro   dictrq   boolrr   classmethodr   rx   r~   propertyr   r   intr   r   listr   r   r   r   r   r{   rM   r   r   r   ra   ra   b   s   9x 5!D#!N'J'&+&7F#75)L#)'Ct' E2Is2u51Hc15u-D#- e%8J8 e%8J8"'U"?D
? 5!C! !&5% @FC$J@ue4D'4bfII#&I/2TzD/@INVW^N_I	I I" 
 
* 
 
*3C$J 3c 3J] 3j	 #'$($("&"&,0!% $#$(.2+/+/)-)-)d 4Z	d
 Tzd Tzd 4Zd 4Zd  #Tzd $Jd :d *d Djd Tkd   9t+!d" S	D(#d$ "Dj%d&  $J'd( c3h$&)d* 
+dL$ 1D *$i%r   ra   c            	           \ rS rSr% Sr\\S'   \\S'   \\S'   \\S'   \\S'   \\S'   \\S	'   \\S
'   \S-  \S'   \\S'   \S-  \S'   \\S'   \\S'   \\S'   \\S'   \	S\
S\S\SS 4S j5       rSrg)InferenceEndpointHardwarei  a  
Contains information about a hardware configuration available for Inference Endpoints.

The `vendor`, `region`, `accelerator`, `instance_type` and `instance_size` fields are exactly the values to pass to
[`create_inference_endpoint`] (or `hf endpoints deploy`) to deploy on this hardware.

Args:
    id (`str`):
        Unique hardware identifier, e.g. `"aws-us-east-1-nvidia-l4-x1"`.
    vendor (`str`):
        The cloud provider hosting the hardware, e.g. `"aws"`.
    region (`str`):
        The cloud region the hardware is available in, e.g. `"us-east-1"`.
    accelerator (`str`):
        The type of hardware accelerator, e.g. `"cpu"`, `"gpu"` or `"neuron"`.
    instance_type (`str`):
        The cloud instance type, e.g. `"nvidia-l4"`.
    instance_size (`str`):
        The instance size multiplier, e.g. `"x1"`.
    architecture (`str`):
        Human-readable hardware description, e.g. `"Nvidia L4"`.
    num_accelerators (`int`):
        Number of accelerator units per replica.
    num_cpus (`int`, *optional*):
        Number of vCPUs per replica.
    memory_gb (`float`):
        RAM per replica, in GB.
    gpu_memory_gb (`int`, *optional*):
        Total GPU memory per replica, in GB (i.e. summed over `num_accelerators`). `None` for non-GPU hardware.
    price_per_hour (`float`):
        Cost per replica per hour, in USD.
    status (`str`):
        Availability of the hardware: `"available"`, `"low_availability"`, `"not_available"`, `"reserved"` or
        `"deprecated"`.
    max_accelerators (`int`):
        Maximum number of accelerators of this type the namespace is allowed to run.
    used_accelerators (`int`):
        Number of accelerators of this type currently used by the namespace.

Example:
    ```python
    >>> from huggingface_hub import list_inference_endpoints_hardware
    >>> hardware = list_inference_endpoints_hardware()
    >>> hardware[0]
    InferenceEndpointHardware(id='aws-us-east-1-nvidia-l4-x1', vendor='aws', region='us-east-1', ...)
    ```
idvendorregionr   r   r   architecturenum_acceleratorsNnum_cpus	memory_gbgpu_memory_gbprice_per_hourrf   max_acceleratorsused_acceleratorsro   r   c                    US   nU " US   UUUS   US   US   US   US   UR                  S5      US	   UR                  S
5      US   US   US   US   S9$ )zhInitialize object from a raw compute dictionary, nested under a vendor and a region in the API response.quotar   r   instanceTypeinstanceSizer   numAcceleratorsnumCpusmemoryGbgpuMemoryGbpricePerHourrf   maxAcceleratorsusedAccelerators)r   r   r   r   r   r   r   r   r   r   r   r   rf   r   r   )r   )rw   ro   r   r   r   s        r   rx   "InferenceEndpointHardware.from_raw5  s     G4yM*n-n-^, !23WWY'*o''-0~.x="#45#$67
 	
r   r   )rA   rB   rC   rD   r   r   r   r   floatr   r   rx   rM   r   r   r   r   r     s    .` 	GKKDj:K
4 
C 
 
A\ 
 
r   r   )'r   r-   dataclassesr   r   r   enumr   typingr   r   huggingface_hub.errorsr	   r
   utilsr   r   r   rv   r   r   r   r   r   
get_loggerrA   r   r   r   r+   r,   r   r5   r   r7   rO   rZ   ra   r   r   r   r   <module>r      s      (   * X 7 7 2H			H	%
 
 
  1 %  (,%)	 * d
	
 
D$c4 $C %S$ %
 M% M% M%` U
 U
 U
r   