Dataflow ML mendukung pipeline batch dan streaming.
API RunInference didukung di Apache Beam 2.40.0 dan versi yang lebih baru.
API MLTransform didukung di Apache Beam 2.53.0 dan versi yang lebih baru.
Pengendali model tersedia untuk PyTorch, scikit-learn, TensorFlow,
ONNX, dan TensorRT.
Untuk framework yang tidak didukung, Anda dapat menggunakan pengendali model kustom.
Dataflow ML menggabungkan kecanggihan Dataflow dengan RunInference API Apache Beam.
Dengan RunInference API, Anda menentukan karakteristik dan properti model
dan meneruskan konfigurasi tersebut ke transformasi RunInference. Fitur ini
memungkinkan pengguna menjalankan model dalam
pipeline Dataflow tanpa perlu mengetahui
detail implementasi model. Anda dapat memilih framework yang paling sesuai dengan data Anda, seperti TensorFlow dan PyTorch.
Menjalankan beberapa model dalam pipeline
Gunakan transformasi RunInference untuk menambahkan beberapa model inferensi ke
pipeline Dataflow Anda. Untuk mengetahui informasi selengkapnya, termasuk detail kode,
lihat Pipeline multi-model
dalam dokumentasi Apache Beam.
Membuat pipeline lintas bahasa
Untuk menggunakan RunInference dengan pipeline Java,
buat transformasi Python lintas bahasa. Pipeline memanggil
transformasi, yang melakukan prapemrosesan, pascapemrosesan, dan inferensi.
Untuk pipeline batch atau streaming yang memerlukan penggunaan akselerator, Anda dapat
menjalankan pipeline Dataflow di perangkat GPU NVIDIA. Untuk informasi selengkapnya, lihat
Menjalankan pipeline Dataflow dengan GPU.
Memecahkan masalah Dataflow ML
Bagian ini memberikan strategi pemecahan masalah dan link yang mungkin berguna bagi Anda saat menggunakan Dataflow ML.
Stack mengharapkan setiap tensor memiliki ukuran yang sama
Jika Anda memberikan gambar dengan ukuran yang berbeda atau penyematan kata dengan panjang yang berbeda
saat menggunakan RunInference API, error berikut mungkin terjadi:
File "/beam/sdks/python/apache_beam/ml/inference/pytorch_inference.py", line 232, in run_inference batched_tensors = torch.stack(key_to_tensor_list[key]) RuntimeError: stack expects each tensor to be equal size, but got [12] at entry 0 and [10] at entry 1 [while running 'PyTorchRunInference/ParDo(_RunInferenceDoFn)']
Error ini terjadi karena RunInference API tidak dapat mengelompokkan elemen tensor dengan
ukuran yang berbeda. Untuk solusinya, lihat
Tidak dapat mengelompokkan elemen tensor
dalam dokumentasi Apache Beam.
Menghindari error kehabisan memori dengan model besar
Saat Anda memuat model ML berukuran sedang atau besar, mesin Anda mungkin kehabisan memori.
Dataflow menyediakan alat untuk membantu menghindari error kehabisan memori (OOM)
saat memuat model ML. Gunakan tabel berikut untuk menentukan pendekatan yang sesuai untuk skenario Anda.
Skenario
Solusi
Model ini cukup kecil untuk muat di memori.
Gunakan transformasi RunInference tanpa konfigurasi tambahan. Transformasi RunInference membagikan model di seluruh
thread. Jika Anda dapat menyesuaikan satu model per core CPU di komputer, pipeline Anda dapat menggunakan konfigurasi default.
Beberapa model yang dilatih secara berbeda melakukan tugas yang sama.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-18 UTC."],[[["\u003cp\u003eDataflow ML facilitates both prediction and inference pipelines, as well as data preparation for training ML models.\u003c/p\u003e\n"],["\u003cp\u003eDataflow ML supports both batch and streaming data pipelines, utilizing the \u003ccode\u003eRunInference\u003c/code\u003e API (from Apache Beam 2.40.0) and \u003ccode\u003eMLTransform\u003c/code\u003e API (from Apache Beam 2.53.0).\u003c/p\u003e\n"],["\u003cp\u003eThe system is compatible with model handlers for popular frameworks like PyTorch, scikit-learn, TensorFlow, ONNX, and TensorRT, with options for custom handlers for other frameworks.\u003c/p\u003e\n"],["\u003cp\u003eDataflow ML enables the use of multiple inference models within a single pipeline via the \u003ccode\u003eRunInference\u003c/code\u003e transform and supports the use of GPUs for pipelines that need them.\u003c/p\u003e\n"],["\u003cp\u003eDataflow ML also provides troubleshooting guidance for common issues, including tensor size mismatch errors and out-of-memory errors when dealing with large models.\u003c/p\u003e\n"]]],[],null,["# About Dataflow ML\n\nYou can use Dataflow ML's scale data processing abilities for\n[prediction and inference pipelines](#prediction) and for\n[data preparation for training](#data-prep).\n\n**Figure 1.** The complete Dataflow ML workflow.\n\nRequirements and limitations\n----------------------------\n\n- Dataflow ML supports batch and streaming pipelines.\n- The `RunInference` API is supported in Apache Beam 2.40.0 and later versions.\n- The `MLTransform` API is supported in Apache Beam 2.53.0 and later versions.\n- Model handlers are available for PyTorch, scikit-learn, TensorFlow, ONNX, and TensorRT. For unsupported frameworks, you can use a custom model handler.\n\nData preparation for training\n-----------------------------\n\n- Use the `MLTransform` feature to prepare your data for training ML models. For\n more information, see\n [Preprocess data with `MLTransform`](/dataflow/docs/machine-learning/ml-preprocess-data).\n\n- Use Dataflow with ML-OPS frameworks, such as\n [Kubeflow Pipelines](https://www.kubeflow.org/docs/components/pipelines/v1/introduction/)\n (KFP) or [TensorFlow Extended](https://www.tensorflow.org/tfx) (TFX).\n To learn more, see [Dataflow ML in ML workflows](/dataflow/docs/machine-learning/ml-data).\n\nPrediction and inference pipelines\n----------------------------------\n\nDataflow ML combines the power of Dataflow with\nApache Beam's\n[`RunInference` API](https://beam.apache.org/documentation/ml/about-ml/).\nWith the `RunInference` API, you define the model's characteristics and properties\nand pass that configuration to the `RunInference` transform. This feature\nallows users to run the model within their\nDataflow pipelines without needing to know\nthe model's implementation details. You can choose the framework that best\nsuits your data, such as TensorFlow and PyTorch.\n\nRun multiple models in a pipeline\n---------------------------------\n\nUse the `RunInference` transform to add multiple inference models to\nyour Dataflow pipeline. For more information, including code details,\nsee [Multi-model pipelines](https://beam.apache.org/documentation/ml/about-ml/#multi-model-pipelines)\nin the Apache Beam documentation.\n\nBuild a cross-language pipeline\n-------------------------------\n\nTo use RunInference with a Java pipeline,\n[create a cross-language Python transform](https://beam.apache.org/documentation/programming-guide/#1312-creating-cross-language-python-transforms). The pipeline calls the\ntransform, which does the preprocessing, postprocessing, and inference.\n\nFor detailed instructions and a sample pipeline, see\n[Using RunInference from the Java SDK](https://beam.apache.org/documentation/ml/multi-language-inference/).\n\nUse GPUs with Dataflow\n----------------------\n\nFor batch or streaming pipelines that require the use of accelerators, you can\nrun Dataflow pipelines on NVIDIA GPU devices. For more information, see\n[Run a Dataflow pipeline with GPUs](/dataflow/docs/gpu/use-gpus).\n\nTroubleshoot Dataflow ML\n------------------------\n\nThis section provides troubleshooting strategies and links that you might find\nhelpful when using Dataflow ML.\n\n### Stack expects each tensor to be equal size\n\nIf you provide images of different sizes or word embeddings of different lengths\nwhen using the `RunInference` API, the following error might occur: \n\n File \"/beam/sdks/python/apache_beam/ml/inference/pytorch_inference.py\", line 232, in run_inference batched_tensors = torch.stack(key_to_tensor_list[key]) RuntimeError: stack expects each tensor to be equal size, but got [12] at entry 0 and [10] at entry 1 [while running 'PyTorchRunInference/ParDo(_RunInferenceDoFn)']\n\nThis error occurs because the `RunInference` API can't batch tensor elements of\ndifferent sizes. For workarounds, see\n[Unable to batch tensor elements](https://beam.apache.org/documentation/ml/about-ml/#unable-to-batch-tensor-elements)\nin the Apache Beam documentation.\n\n### Avoid out-of-memory errors with large models\n\nWhen you load a medium or large ML model, your machine might run out of memory.\nDataflow provides tools to help avoid out-of-memory (OOM) errors\nwhen loading ML models. Use the following table to determine the appropriate\napproach for your scenario.\n\nFor more information about memory management with Dataflow, see\n[Troubleshoot Dataflow out of memory errors](/dataflow/docs/guides/troubleshoot-oom).\n\nWhat's next\n-----------\n\n- Explore the [Dataflow ML notebooks](https://github.com/apache/beam/tree/master/examples/notebooks/beam-ml) in GitHub.\n- Get in-depth information about using ML with Apache Beam in Apache Beam's [AI/ML pipelines](https://beam.apache.org/documentation/ml/overview/) documentation.\n- Learn more about the [`RunInference` API](https://beam.apache.org/releases/pydoc/current/apache_beam.ml.inference.html#apache_beam.ml.inference.RunInference).\n- Learn about the [metrics](https://beam.apache.org/documentation/ml/runinference-metrics/) that you can use to monitor your `RunInference` transform."]]