rszper commented on code in PR #22250:
URL: https://github.com/apache/beam/pull/22250#discussion_r919469200


##########
website/www/site/content/en/documentation/sdks/python.md:
##########
@@ -48,6 +48,11 @@ language-specific implementation guidance.
 
 ## Using Beam Python SDK in your ML pipelines
 
+To use the Beam Python SDK with your machine learning pipelines, you can 
either use the RunInference API or TensorFlow.

Review Comment:
   Updated, but I'm not sure if we'll need to update this again based on the 
email thread?



##########
website/www/site/content/en/documentation/sdks/python-machine-learning.md:
##########
@@ -0,0 +1,167 @@
+---
+type: languages
+title: "Apache Beam Python Machine Learning"
+---
+<!--
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+# Machine Learning
+
+You can use Apache Beam with the RunInference API to use machine learning (ML) 
models to do local and remote inference with batch and streaming pipelines. 
Starting with Apache Beam 2.40.0, PyTorch and Scikit-learn frameworks are 
supported. You can create multiple types of transforms using the RunInference 
API: the API takes multiple types of setup parameters from model handlers, and 
the parameter type determines the model implementation.
+
+## Why use the RunInference API?
+
+RunInference leverages existing Apache Beam concepts, such as the the 
`BatchElements` transform and the `Shared` class, and it allows you to build 
multi-model pipelines. In addition, the RunInference API allows you to find the 
input that determined the prediction without returning to the full input data.
+
+### BatchElements PTransform
+
+To take advantage of the optimizations of vectorized inference that many 
models implement, we added the `BatchElements` transform as an intermediate 
step before making the prediction for the model. This transform batches 
elements together. The resulting batch is used to make the appropriate 
transformation for the particular framework of RunInference. For example, for 
numpy `ndarrays`, we call `numpy.stack()`,  and for torch `Tensor` elements, we 
call `torch.stack()`.
+
+To customize the settings for `beam.BatchElements`, in `ModelHandler`, 
override the `batch_elements_kwargs` function. For example, use 
`min_batch_size` to set the lowest number of elements per batch or 
`max_batch_size` to set the highest number of elements per batch.
+
+For more information, see the [`BatchElements` transform 
documentation](https://beam.apache.org/releases/pydoc/current/apache_beam.transforms.util.html#apache_beam.transforms.util.BatchElements).
+
+### Shared helper class
+
+Instead of loading a model for each thread in a worker, we use the `Shared` 
class, which allows us to load one model that is shared across all threads of 
each worker in a DoFn. For more information, see the

Review Comment:
   Updated



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to