You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/06/15 15:50:53 UTC

[GitHub] [beam] TheNeuralBit commented on a diff in pull request #21868: Updated documentation for ml.inference docs.

TheNeuralBit commented on code in PR #21868:
URL: https://github.com/apache/beam/pull/21868#discussion_r898151499


##########
sdks/python/apache_beam/ml/inference/pytorch_inference.py:
##########
@@ -55,21 +55,24 @@ def _convert_to_device(examples: torch.Tensor, device) -> torch.Tensor:
 class PytorchModelHandlerTensor(ModelHandler[torch.Tensor,
                                              PredictionResult,
                                              torch.nn.Module]):
-  """ Implementation of the ModelHandler interface for PyTorch."""
   def __init__(
       self,
       state_dict_path: str,
       model_class: Callable[..., torch.nn.Module],
       model_params: Dict[str, Any],
       device: str = 'CPU'):
-    """
-    Initializes a PytorchModelHandlerTensor
-    :param state_dict_path: path to the saved dictionary of the model state.
-    :param model_class: class of the Pytorch model that defines the model
-    structure.
-    :param device: the device on which you wish to run the model. If
-    ``device = GPU`` then a GPU device will be used if it is available.
-    Otherwise, it will be CPU.
+    """Implementation of the ModelHandler interface for PyTorch.
+
+    Example Usage:
+      pcoll | RunInference(PytorchModelHandlerTensor(state_dict_path="my_uri"))

Review Comment:
   (similarly for other examples)



##########
sdks/python/apache_beam/ml/inference/pytorch_inference.py:
##########
@@ -55,21 +55,24 @@ def _convert_to_device(examples: torch.Tensor, device) -> torch.Tensor:
 class PytorchModelHandlerTensor(ModelHandler[torch.Tensor,
                                              PredictionResult,
                                              torch.nn.Module]):
-  """ Implementation of the ModelHandler interface for PyTorch."""
   def __init__(
       self,
       state_dict_path: str,
       model_class: Callable[..., torch.nn.Module],
       model_params: Dict[str, Any],
       device: str = 'CPU'):
-    """
-    Initializes a PytorchModelHandlerTensor
-    :param state_dict_path: path to the saved dictionary of the model state.
-    :param model_class: class of the Pytorch model that defines the model
-    structure.
-    :param device: the device on which you wish to run the model. If
-    ``device = GPU`` then a GPU device will be used if it is available.
-    Otherwise, it will be CPU.
+    """Implementation of the ModelHandler interface for PyTorch.
+
+    Example Usage:
+      pcoll | RunInference(PytorchModelHandlerTensor(state_dict_path="my_uri"))

Review Comment:
   nit: I think this needs a newline and an extra colon to render as a code block, see for example https://github.com/apache/beam/blob/master/sdks/python/apache_beam/dataframe/convert.py#L50-L55
   
   ```suggestion
       Example Usage::
       
         pcoll | RunInference(PytorchModelHandlerTensor(state_dict_path="my_uri"))
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org