Skip to content

Commit

Permalink
Rename nlp example (#2221)
Browse files Browse the repository at this point in the history
* rename nlp case

* rename to e2e_nlp

* Add HuggingFace and Skypilot deployment steps
  • Loading branch information
safoinme authored Jan 11, 2024
1 parent f3a9838 commit 250e65c
Show file tree
Hide file tree
Showing 41 changed files with 150 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/update-templates-to-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ jobs:
issue_number: ${{ github.event.pull_request.number }},
owner: context.repo.owner,
repo: context.repo.repo,
body: 'NLP template updates in `examples/nlp-case` have been pushed.'
body: 'NLP template updates in `examples/e2e_nlp` have been pushed.'
})
update-starter-template-to-examples:
name: update-starter-template-to-examples
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Changes here will be overwritten by Copier
_commit: 0.45.0
_src_path: gh:zenml-io/template-nlp
_commit: 0.45.0-17-gbd996ed
_src_path: template-nlp
accelerator: cpu
cloud_of_choice: aws
dataset: airline_reviews
deploy_locally: true
deploy_to_huggingface: false
deploy_to_skypilot: false
deploy_to_huggingface: true
deploy_to_skypilot: true
email: ''
full_name: ZenML GmbH
metric_compare_promotion: true
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 9 additions & 21 deletions examples/nlp-case/README.md → examples/e2e_nlp/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# ZenML NLP project

This is a comprehensive supervised ML project built with the
ZenML framework and its integration. The project trains one or more
scikit-learn classification models to make predictions on the tabular
classification datasets provided by the scikit-learn library. The project was
generated from the [NLP ZenML project template](https://github.com/zenml-io/template-nlp).
ZenML framework and its integration. The project will be
a comprehensive starting point for anyone looking to build
and deploy NLP models using the ZenML framework by streamlining
the process of training, promoting, and deploying NLP models
with a focus on reproducibility, scalability, and ease of use.
The project was generated from the [NLP ZenML project template](https://github.com/zenml-io/template-nlp).
with the following properties:

- Project name: ZenML NLP project
- Technical Name: nlp_use_case
- Version: `0.0.1`
Expand All @@ -16,6 +19,8 @@ Settings of your project are:
- Accelerator: `cpu`
- Trained model promotion to `staging` based on accuracy metric vs currently deployed model
- Local deployment enabled
- Deployment to HuggingFace Hub enabled
- Deployment to SkyPilot enabled
- Dataset: `airline_reviews`
- Model: `distilbert-base-uncased`
- Notifications about failures enabled
Expand Down Expand Up @@ -181,20 +186,3 @@ The project loosely follows [the recommended ZenML project structure](https://do
├── config.yaml # ZenML configuration file
└── run.py # CLI tool to run pipelines on ZenML Stack
```












integrations
├── README.md # this file
├── requirements.txt # extra Python dependencies
└── run.py # CLI tool to run pipelines on ZenML Stack
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

from steps import (
deploy_locally,
deploy_to_huggingface,
deploy_to_skypilot,
notify_on_failure,
notify_on_success,
save_model_to_deploy,
Expand Down Expand Up @@ -87,7 +89,16 @@ def nlp_use_case_deploy_pipeline(
tokenizer_name_or_path=tokenizer_name_or_path,
after=["save_model_to_deploy"],
)
last_step_name = "deploy_locally"
########## Deploy to HuggingFace ##########
deploy_to_huggingface(
repo_name=repo_name,
after=["save_model_to_deploy"],
)
########## Deploy to Skypilot ##########
deploy_to_skypilot(
after=["save_model_to_deploy"],
)
last_step_name = "deploy_to_skypilot"

notify_on_success(after=[last_step_name])
### YOUR CODE ENDS HERE ###
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@
from .deploying import (
save_model_to_deploy,
deploy_locally,
deploy_to_huggingface,
deploy_to_skypilot,
)
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@
from .save_model import save_model_to_deploy

from .local_deployment import deploy_locally


from .huggingface_deployment import deploy_to_huggingface


from .skypilot_deployment import deploy_to_skypilot
63 changes: 63 additions & 0 deletions examples/e2e_nlp/steps/deploying/huggingface_deployment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Apache Software License 2.0
#
# Copyright (c) ZenML GmbH 2024. All rights reserved.
#
# 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.
#

import os

from huggingface_hub import HfApi

from zenml import step
from zenml.client import Client
from zenml.logger import get_logger

# Initialize logger
logger = get_logger(__name__)


@step()
def deploy_to_huggingface(
repo_name: str,
):
"""
This step deploy the model to huggingface.
Args:
repo_name: The name of the repo to create/use on huggingface.
"""
### ADD YOUR OWN CODE HERE - THIS IS JUST AN EXAMPLE ###
secret = Client().get_secret("huggingface_creds")
assert secret, "No secret found with name 'huggingface_creds'. Please create one that includes your `username` and `token`."
token = secret.secret_values["token"]
api = HfApi(token=token)
hf_repo = api.create_repo(
repo_id=repo_name, repo_type="space", space_sdk="gradio", exist_ok=True
)
zenml_repo_root = Client().root
if not zenml_repo_root:
logger.warning(
"You're running the `deploy_to_huggingface` step outside of a ZenML repo. "
"Since the deployment step to huggingface is all about pushing the repo to huggingface, "
"this step will not work outside of a ZenML repo where the gradio folder is present."
)
raise
gradio_folder_path = os.path.join(zenml_repo_root, "gradio")
space = api.upload_folder(
folder_path=gradio_folder_path,
repo_id=hf_repo.repo_id,
repo_type="space",
)
logger.info(f"Space created: {space}")
### YOUR CODE ENDS HERE ###
53 changes: 53 additions & 0 deletions examples/e2e_nlp/steps/deploying/skypilot_deployment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Apache Software License 2.0
#
# Copyright (c) ZenML GmbH 2024. All rights reserved.
#
# 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.
#


import os
import re

import sky

from zenml import step
from zenml.client import Client
from zenml.logger import get_logger

# Initialize logger
logger = get_logger(__name__)


@step()
def deploy_to_skypilot():
"""
This step deploy the model to a VM using SkyPilot.
This step requires `skypilot` to be installed.
aswell as a configured cloud account locally (e.g. AWS, GCP, Azure).
"""
### ADD YOUR OWN CODE HERE - THIS IS JUST AN EXAMPLE ###
zenml_repo_root = Client().root
if not zenml_repo_root:
logger.warning(
"You're running the `deploy_to_huggingface` step outside of a ZenML repo. "
"Since the deployment step to huggingface is all about pushing the repo to huggingface, "
"this step will only work within a ZenML repo where the gradio folder is present."
)
raise
gradio_task_yaml = os.path.join(zenml_repo_root, "gradio", "serve.yaml")
task = sky.Task.from_yaml(gradio_task_yaml)
cluster_name = re.sub(r"[^a-zA-Z0-9]+", "-", "nlp_use_case-cluster")
sky.launch(task, cluster_name=cluster_name, detach_setup=True)
### YOUR CODE ENDS HERE ###
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 250e65c

Please sign in to comment.