class_docstr: 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 lightning.pytorch import Trainer
      from lightning.pytorch.demos.boring_classes import BoringModel
      from lightning.pytorch.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]}
class_docstr_tok: ["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","lightning.pytorch","import","Trainer","from","lightning.pytorch.demos.boring_classes","import","BoringModel","from","lightning.pytorch.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","]","}"]
docstr: 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).
docstr_tok: ["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",")","."]
code: def configure_serialization(
      self,
  ) -> Tuple[Dict[str, Callable], Dict[str, Callable]]:
      """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).
  
      """
  
file_path: pytorch-lightning/src/lightning/pytorch/serve/servable_module.py
imports: from abc import ABC, abstractmethod
  from typing import Any, Callable, Dict, Tuple
  import torch
  from torch import Tensor
label_desc: Use image node_id 2 for calling the ServableModule obj's underlying member method code with example usage: obj.configure_serialization() without return types