§
    “©ºjØ  ã                   ól   — d dl mZmZ d dlmZmZ d dlZd dlmZ  G d„ deej        j	        ¦  «        Z
dS )é    )ÚABCÚabstractmethod)ÚAnyÚCallableN)ÚTensorc            	       óê   — e Zd ZdZedeeef         fd„¦   «         Zede	eee
f         eee
f         f         fd„¦   «         Zedededeeef         fd„¦   «         Zedeeef         fd„¦   «         Zd	S )
ÚServableModuleaI  The ServableModule provides a simple API to make your model servable.

    .. warning::  This is an :ref:`experimental <versioning:Experimental API>` feature.

    Here is an example of how to use the ``ServableModule`` module.

    .. code-block:: python

        from typing import Dict, Any, Callable

        import torch

        from pytorch_lightning import Trainer
        from pytorch_lightning.demos.boring_classes import BoringModel
        from pytorch_lightning.serve.servable_module_validator import ServableModule, ServableModuleValidator


        class ServableBoringModel(BoringModel, ServableModule):
            def configure_payload(self) -> Dict[str, Any]:
                return {"body": {"x": list(range(32))}}

            def configure_serialization(self) -> Tuple[Dict[str, Callable], Dict[str, Callable]]:
                def deserialize(x):
                    return torch.tensor(x, dtype=torch.float)

                def serialize(x):
                    return x.tolist()

                return {"x": deserialize}, {"output": serialize}

            def serve_step(self, x: torch.Tensor) -> Dict[str, torch.Tensor]:
                return {"output": torch.tensor([0, 1])}

            def configure_response(self):
                return {"output": [0, 1]}


        serve_cb = ServableModuleValidator()
        trainer = Trainer(
            max_epochs=1,
            limit_train_batches=2,
            limit_val_batches=0,
            callbacks=[serve_cb],
        )
        trainer.fit(ServableBoringModel())
        assert serve_cb.resp.json() == {"output": [0, 1]}

    Úreturnc                 ó   — dS )z*Returns a request payload as a dictionary.N© ©Úselfs    úw/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/pytorch_lightning/serve/servable_module.pyÚconfigure_payloadz ServableModule.configure_payload:   ó   € € € ó    c                 ó   — dS )aÃ  Returns a tuple of dictionaries.

        The first dictionary contains the name of the ``serve_step`` input variables name as its keys
        and the associated de-serialization function (e.g function to convert a payload to tensors).

        The second dictionary contains the name of the ``serve_step`` output variables name as its keys
        and the associated serialization function (e.g function to convert a tensors into payload).

        Nr   r   s    r   Úconfigure_serializationz&ServableModule.configure_serialization>   r   r   ÚargsÚkwargsc                 ó   — dS )a(  Returns the predictions of your model as a dictionary.

        .. code-block:: python

            def serve_step(self, x: torch.Tensor) -> Dict[str, torch.Tensor]:
                return {"predictions": self(x)}

        Args:
            args: The output from de-serializer functions provided by the ``configure_serialization`` hook.
            kwargs: The keyword output of the de-serializer functions provided by the ``configure_serialization`` hook.

        Return:
            - ``dict`` - A dictionary with their associated tensors.

        Nr   )r   r   r   s      r   Ú
serve_stepzServableModule.serve_stepJ   r   r   c                 ó   — dS )z3Returns a response to validate the server response.Nr   r   s    r   Úconfigure_responsez!ServableModule.configure_response\   r   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚdictÚstrr   r   Útupler   r   r   r   r   r   r   r   r	   r	      s  € € € € € ð/ð /ðb ð9 4¨¨S¨¤>ð 9ð 9ð 9ñ „^ð9ð ð	¨¨t°C¸°MÔ/BÀDÈÈhÈÔDWÐ/WÔ)Xð 	ð 	ð 	ñ „^ð	ð ð ð °&ð ¸TÀ#ÀvÀ+Ô=Nð ð ð ñ „^ðð" ðB D¨¨c¨¤Nð Bð Bð Bñ „^ðBð Bð Br   r	   )Úabcr   r   Útypingr   r   Útorchr   ÚnnÚModuler	   r   r   r   ú<module>r'      sž   ðØ #Ð #Ð #Ð #Ð #Ð #Ð #Ð #Ø  Ð  Ð  Ð  Ð  Ð  Ð  Ð  à €€€Ø Ð Ð Ð Ð Ð ðVBð VBð VBð VBð VB�S˜%œ(œ/ñ VBô VBð VBð VBð VBr   