Dataproc ML
Public Preview Disclaimer
Interfaces and functionality are subject to change. It is not recommended for production-critical applications without thorough testing and understanding of the potential risks.
Dataproc ML is a Python library that simplifies distributed ML inference on Google Cloud Dataproc. It provides high-level handlers to run PyTorch and Vertex AI Gemini models at scale using Apache Spark, without the complexity of manual model distribution and batch processing.
Installation
You can install the library using pip:
pip install dataproc-ml
Usage Examples
Here are a couple of examples demonstrating how to use the handlers for distributed inference on a Spark DataFrame.
Generative AI (Gemini) Model Inference
Note: Using the
GenAiModelHandlerinvolves making API calls to Vertex AI, which will incur costs. Please review the Vertex AI Generative AI pricing.
Use Google's Gemini models to perform generative tasks on your data. This example uses a prompt template to ask for the capital of countries listed in a Spark DataFrame.
from pyspark.sql import SparkSession
from google.cloud.dataproc_ml.inference import GenAiModelHandler
spark = SparkSession.builder.getOrCreate()
# Create a sample DataFrame
data = [("USA",), ("France",), ("Japan",)]
input_df = spark.createDataFrame(data, ["country"])
# The handler will automatically use the 'country' column
result_df = (
GenAiModelHandler()
.prompt("What is the capital of {country}?")
.output_col("capital_city")
.transform(input_df)
)
result_df.show()
# +-------+----------------+
# |country|capital_city |
# +-------+----------------+
# |USA |Washington, D.C.|
# |France |Paris |
# |Japan |Tokyo |
# +-------+----------------+
PyTorch Model Inference
Run distributed inference using a pre-trained PyTorch model stored in Google Cloud Storage.
This example assumes you have a Spark DataFrame input_df with a column named features containing image tensors or other numerical data.
from pyspark.sql import SparkSession
from google.cloud.dataproc_ml.inference import PyTorchModelHandler
spark = SparkSession.builder.getOrCreate()
data = [([0.1, 0.2, 0.3],), ([0.4, 0.5, 0.6],), ([0.7, 0.8, 0.9],)]
input_df = spark.createDataFrame(data, ["features"])
# Path to your saved PyTorch model in GCS
model_gcs_path = "gs://your-bucket/path/to/model.pt"
# Apply the model for inference
result_df = (
PyTorchModelHandler()
.model_path(model_gcs_path)
.input_cols("features")
.transform(input_df)
)
result_df.show()
# +------------------+--------------------+
# | features| predictions|
# +------------------+--------------------+
# |[0.1, 0.2, 0.3] |[0.543, 0.457] |
# |[0.4, 0.5, 0.6] |[0.621, 0.379] |
# |[0.7, 0.8, 0.9] |[0.789, 0.211] |
# +------------------+--------------------+
Documentation
For more detailed information on the available handlers and their configurations, please refer to our official documentation.
Contributing
Contributions are welcome! Please see contributing.md for details on how to set up your development environment, run linters/tests, etc.
License
This project is licensed under the Apache 2.0 License. See the LICENSE file for more details.
Metadata
Release files for dataproc-ml 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dataproc_ml-0.2.0.tar.gz | 19.0 kB | Without provenance | Details for dataproc_ml-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dataproc_ml-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for dataproc_ml-0.2.0-py3-none-any.whl |
Total release size: 43.9 kB
Release files / dataproc_ml-0.2.0.tar.gz
| Download URL | dataproc_ml-0.2.0.tar.gz |
|---|---|
| Size | 19.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2fc7c074436091498d388ca908d1e662980f2b005b3a6e67ad85d33ed94b31ce
|
|
BLAKE2b-256 checksum How to use checksums |
29c8f4dd30713ea56b5256e766c43a6c80210943990cd3a3212bdc0e388ff946
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.0
|
Release files / dataproc_ml-0.2.0-py3-none-any.whl
| Download URL | dataproc_ml-0.2.0-py3-none-any.whl |
|---|---|
| Size | 24.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1b1e993c835de9be959b3c7622700e90943d77a40ebda06881bf0520aeba9145
|
|
BLAKE2b-256 checksum How to use checksums |
3c517dc52b52df52f891e799eee8fe6d4705c63f92b20d342c45471276d8c9c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.0
|
Security for dataproc-ml 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.