-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Spark DL notebooks with PyTriton on Databricks/Dataproc #483
Merged
Merged
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1152443
Add notebooks with runs
rishic3 4efa8e4
Add image, update readme/requirements
rishic3 5f6268f
Add dataproc instructions
rishic3 7e0c1e3
Add databricks instructions
rishic3 b076e26
Combine init scripts for databricks
rishic3 916d05d
Move common PyTriton funcs to utils
rishic3 aeb3a36
Use https path to pyfile
rishic3 8088c58
cleanup
rishic3 b3e09e1
Carriage returns
rishic3 d6cebff
Move utils to local dir
rishic3 c138dd1
Add local imports
rishic3 259c955
Address comments
rishic3 ce7df83
merge changes
rishic3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
examples/ML+DL-Examples/Spark-DL/dl_inference/databricks/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Spark DL Inference on Databricks | ||
|
||
**Note**: fields in \<brackets\> require user inputs. | ||
|
||
## Setup | ||
|
||
1. Install the latest [databricks-cli](https://docs.databricks.com/en/dev-tools/cli/tutorial.html) and configure for your workspace. | ||
|
||
2. Specify the path to the notebook and init script, and the destination filepaths on Databricks. | ||
As an example for a PyTorch notebook: | ||
```shell | ||
export NOTEBOOK_SRC=</path/to/notebook_torch.ipynb> | ||
export NOTEBOOK_DEST=</Users/[email protected]/spark-dl/notebook_torch.ipynb> | ||
|
||
export INIT_SRC=$(pwd)/setup/init_spark_dl.sh | ||
export INIT_DEST=</Users/[email protected]/spark-dl/init_spark_dl.sh> | ||
``` | ||
3. Specify the framework to torch or tf, corresponding to the notebook you wish to run. Continuing with the PyTorch example: | ||
```shell | ||
export FRAMEWORK=torch | ||
``` | ||
This will tell the init script which libraries to install on the cluster. | ||
|
||
4. Copy the files to the Databricks Workspace: | ||
```shell | ||
databricks workspace import $INIT_DEST --format AUTO --file $INIT_SRC | ||
databricks workspace import $NOTEBOOK_DEST --format JUPYTER --file $NOTEBOOK_SRC | ||
``` | ||
|
||
5. Launch the cluster with the provided script (note that the script specifies **Azure instances** by default; change as needed): | ||
```shell | ||
export CLUSTER_NAME=spark-dl-inference-$FRAMEWORK | ||
cd setup | ||
chmod +x start_cluster.sh | ||
./start_cluster.sh | ||
``` | ||
|
||
OR, start the cluster from the Databricks UI: | ||
|
||
- Go to `Compute > Create compute` and set the desired cluster settings. | ||
- Integration with Triton inference server uses stage-level scheduling (Spark>=3.4.0). Make sure to: | ||
- use a cluster with GPU resources | ||
- set a value for `spark.executor.cores` | ||
- ensure that `spark.executor.resource.gpu.amount` = 1 | ||
- Under `Advanced Options > Init Scripts`, upload the init script from your workspace. | ||
- Under environment variables, set `FRAMEWORK=torch` or `FRAMEWORK=tf` based on the notebook used. | ||
- For Tensorflow notebooks, we recommend setting the environment variable `TF_GPU_ALLOCATOR=cuda_malloc_async` (especially for Huggingface LLM models), which enables the CUDA driver to implicity release unused memory from the pool. | ||
|
||
6. Navigate to the notebook in your workspace and attach it to the cluster. |
36 changes: 36 additions & 0 deletions
36
examples/ML+DL-Examples/Spark-DL/dl_inference/databricks/setup/init_spark_dl.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
# Copyright (c) 2025, NVIDIA CORPORATION. | ||
|
||
set -euxo pipefail | ||
|
||
# install requirements | ||
sudo /databricks/python3/bin/pip3 install --upgrade pip | ||
|
||
if [[ "${FRAMEWORK}" == "torch" ]]; then | ||
cat <<EOF > temp_requirements.txt | ||
datasets==3.* | ||
transformers | ||
urllib3<2 | ||
nvidia-pytriton | ||
torch | ||
torchvision --extra-index-url https://download.pytorch.org/whl/cu121 | ||
torch-tensorrt | ||
tensorrt --extra-index-url https://download.pytorch.org/whl/cu121 | ||
sentence_transformers | ||
sentencepiece | ||
nvidia-modelopt[all] --extra-index-url https://pypi.nvidia.com | ||
EOF | ||
elif [[ "${FRAMEWORK}" == "tf" ]]; then | ||
cat <<EOF > temp_requirements.txt | ||
datasets==3.* | ||
transformers | ||
urllib3<2 | ||
nvidia-pytriton | ||
EOF | ||
else | ||
echo "Please export FRAMEWORK as torch or tf per README" | ||
exit 1 | ||
fi | ||
|
||
sudo /databricks/python3/bin/pip3 install --upgrade --force-reinstall -r temp_requirements.txt | ||
rm temp_requirements.txt | ||
52 changes: 52 additions & 0 deletions
52
examples/ML+DL-Examples/Spark-DL/dl_inference/databricks/setup/start_cluster.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/bash | ||
# Copyright (c) 2025, NVIDIA CORPORATION. | ||
|
||
# configure arguments | ||
if [[ -z ${INIT_DEST} ]]; then | ||
echo "Please make sure INIT_DEST is exported per README.md" | ||
exit 1 | ||
fi | ||
|
||
if [[ -z ${CLUSTER_NAME} ]]; then | ||
echo "Please make sure CLUSTER_NAME is exported per README.md" | ||
exit 1 | ||
fi | ||
|
||
if [[ -z ${FRAMEWORK} ]]; then | ||
echo "Please make sure FRAMEWORK is exported to torch or tf per README.md" | ||
exit 1 | ||
fi | ||
|
||
json_config=$(cat <<EOF | ||
{ | ||
"cluster_name": "${CLUSTER_NAME}", | ||
"spark_version": "15.4.x-gpu-ml-scala2.12", | ||
"spark_conf": { | ||
"spark.executor.resource.gpu.amount": "1", | ||
"spark.python.worker.reuse": "true", | ||
"spark.task.resource.gpu.amount": "0.125", | ||
"spark.sql.execution.arrow.pyspark.enabled": "true", | ||
"spark.executor.cores": "8" | ||
}, | ||
"node_type_id": "Standard_NC8as_T4_v3", | ||
"driver_node_type_id": "Standard_NC8as_T4_v3", | ||
"spark_env_vars": { | ||
"TF_GPU_ALLOCATOR": "cuda_malloc_async", | ||
"FRAMEWORK": "${FRAMEWORK}" | ||
}, | ||
"autotermination_minutes": 60, | ||
"enable_elastic_disk": true, | ||
"init_scripts": [ | ||
{ | ||
"workspace": { | ||
"destination": "${INIT_DEST}" | ||
} | ||
} | ||
], | ||
"runtime_engine": "STANDARD", | ||
"num_workers": 4 | ||
} | ||
EOF | ||
) | ||
|
||
databricks clusters create --json "$json_config" |
65 changes: 65 additions & 0 deletions
65
examples/ML+DL-Examples/Spark-DL/dl_inference/dataproc/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Spark DL Inference on Dataproc | ||
|
||
## Setup | ||
|
||
**Note**: fields in \<brackets\> require user inputs. | ||
|
||
#### Setup GCloud CLI | ||
|
||
1. Install the latest [gcloud-cli](https://cloud.google.com/sdk/docs/install) and initialize with `gcloud init`. | ||
|
||
2. Configure the following settings: | ||
```shell | ||
export PROJECT=<your_project> | ||
export DATAPROC_REGION=<your_dataproc_region> | ||
export COMPUTE_REGION=<your_compute_region> | ||
export COMPUTE_ZONE=<your_compute_zone> | ||
|
||
gcloud config set project ${PROJECT} | ||
gcloud config set dataproc/region ${DATAPROC_REGION} | ||
gcloud config set compute/region ${COMPUTE_REGION} | ||
gcloud config set compute/zone ${COMPUTE_ZONE} | ||
``` | ||
|
||
#### Copy files to GCS | ||
|
||
3. Create a GCS bucket if you don't already have one: | ||
```shell | ||
export GCS_BUCKET=<your_gcs_bucket_name> | ||
|
||
gcloud storage buckets create gs://${GCS_BUCKET} | ||
``` | ||
|
||
4. Specify the local path to the notebook(s) and copy to the GCS bucket. | ||
As an example for a torch notebook: | ||
```shell | ||
export SPARK_DL_HOME=${GCS_BUCKET}/spark-dl | ||
|
||
gcloud storage cp </path/to/notebook_name_torch.ipynb> gs://${SPARK_DL_HOME}/notebooks/ | ||
``` | ||
Repeat this step for any notebooks you wish to run. All notebooks under `gs://${SPARK_DL_HOME}/notebooks/` will be copied to the master node during initialization. | ||
|
||
#### Start cluster and run | ||
|
||
5. Specify the framework to use (torch or tf), which will determine what libraries to install on the cluster. For example: | ||
```shell | ||
export FRAMEWORK=torch | ||
``` | ||
Run the cluster startup script. The script will also retrieve and use the [spark-rapids initialization script](https://github.com/GoogleCloudDataproc/initialization-actions/blob/master/spark-rapids/spark-rapids.sh) to setup GPU resources. | ||
```shell | ||
cd setup | ||
chmod +x start_cluster.sh | ||
./start_cluster.sh | ||
``` | ||
By default, the script creates a 4 node GPU cluster named `${USER}-spark-dl-inference-${FRAMEWORK}`. | ||
|
||
7. Browse to the Jupyter web UI: | ||
- Go to `Dataproc` > `Clusters` > `(Cluster Name)` > `Web Interfaces` > `Jupyter/Lab` | ||
|
||
Or, get the link by running this command (under httpPorts > Jupyter/Lab): | ||
```shell | ||
gcloud dataproc clusters describe ${CLUSTER_NAME} --region=${COMPUTE_REGION} | ||
``` | ||
|
||
8. Open and run the notebook interactively with the **Python 3 kernel**. | ||
The notebooks can be found under `Local Disk/spark-dl-notebooks` on the master node (folder icon on the top left > Local Disk). |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like carriage returns still needed at end of last lines in some files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done