-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rename nlp case * rename to e2e_nlp * Add HuggingFace and Skypilot deployment steps
- Loading branch information
Showing
41 changed files
with
150 additions
and
27 deletions.
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
File renamed without changes
8 changes: 4 additions & 4 deletions
8
examples/nlp-case/.copier-answers.yml → examples/e2e_nlp/.copier-answers.yml
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
|
@@ -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.
File renamed without changes.
File renamed without changes.
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
63 changes: 63 additions & 0 deletions
63
examples/e2e_nlp/steps/deploying/huggingface_deployment.py
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,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 ### |
File renamed without changes.
File renamed without changes.
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,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.
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.
File renamed without changes.
File renamed without changes.