Skip to content
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

NLP use-case template without Model Control Plane #1

Merged
merged 19 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .scripts/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh -e
set -x

SRC=${1:-"template tests .scripts"}

export ZENML_DEBUG=1
export ZENML_ANALYTICS_OPT_IN=false

# autoflake replacement: removes unused imports and variables
ruff $SRC --select F401,F841 --fix --exclude "__init__.py" --isolated

# sorts imports
ruff $SRC --select I --fix --ignore D
black $SRC
70 changes: 69 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,69 @@
# 💫 ZenML End-to-End Natural Language Processing Project Template
# 💫 ZenML End-to-End NLP Training and Deployment Project Template

This project template is designed to help you get started with training and deploying NLP models using the ZenML framework. It provides a comprehensive set of steps and pipelines to cover major use cases of NLP model development, including dataset loading, tokenization, model training, model registration, and deployment.

## 📃 Template Parameters

| Parameter | Description | Default |
|-----------|-------------|---------|
| Name | The name of the person/entity holding the copyright | ZenML GmbH |
| Email | The email of the person/entity holding the copyright | [email protected] |
| Project Name | Short name for your project | ZenML NLP project |
| Project Version | The version of your project | 0.0.1 |
| Project License | The license under which your project will be released | Apache Software License 2.0 |
| Technical product name | The technical name to prefix all tech assets (pipelines, models, etc.) | nlp_use_case |
| Target environment | The target environment for deployments/promotions | staging |
| Use metric-based promotion | Whether to compare metric of interest to make model version promotion | True |
| Notifications on failure | Whether to notify about pipeline failures | True |
| Notifications on success | Whether to notify about pipeline successes | False |
| ZenML Server URL | Optional URL of a remote ZenML server for support scripts | - |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we use this anywhere?


## 🚀 Generate a ZenML Project

To generate a project from this template, make sure you have ZenML and its `templates` extras installed:

```bash
pip install zenml[templates]
```

Then, run the following command to generate the project:

```bash
zenml init --template template-nlp
```

You will be prompted to provide values for the template parameters. If you want to use the default values, you can add the `--template-with-defaults` flag to the command.

## 🧰 How this template is implemented

This template provides a set of pipelines and steps to cover the end-to-end process of training and deploying NLP models. Here is an overview of the main components:

### Dataset Loading

The template includes a step for loading the dataset from the HuggingFace Datasets library. You can choose from three available datasets: financial_news, airline_reviews, and imdb_reviews.

### Tokenization

The tokenization step preprocesses the dataset by tokenizing the text data using the tokenizer provided by the HuggingFace Models library. You can choose from three available models: bert-base-uncased, roberta-base, and distilbert-base-cased.

### Model Training

The training pipeline consists of several steps, including model architecture search, hyperparameter tuning, model training, and model evaluation. The best model architecture and hyperparameters are selected based on the performance on the validation set. The trained model is then evaluated on the holdout set to assess its performance.

### Model Registration and Promotion

After training, the best model version is registered in the ZenML Model Registry. The template provides an option to promote the model version based on a specified metric of interest. If metric-based promotion is enabled, the template compares the metric value of the new model version with the metric value of the current production model version and promotes the new version if it performs better.

### Batch Inference

The template includes a batch inference pipeline that loads the inference dataset, preprocesses it using the same tokenizer as during training, and runs predictions using the deployed model version. The predictions are stored as an artifact for future use.

### Deployment Options

The template provides options to deploy the trained model locally or to the HuggingFace Hub. You can choose whether to deploy locally or to the HuggingFace Hub by setting the `deploy_locally` and `deploy_to_huggingface` parameters.

## Next Steps

Once you have generated the project using this template, you can explore the generated code and customize it to fit your specific NLP use case. The README.md file in the generated project provides further instructions on how to set up and run the project.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realised that there's also this (template/README.md) that is already merged on the repo etc. I am not sure if it needs revising or not. Seems like maybe it does? In any case, probably needs attention.


Happy coding with ZenML and NLP!
38 changes: 29 additions & 9 deletions copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ email:
when: "{{ open_source_license != 'none' }}"
product_name:
type: str
help: The technical name of the data product you are building
help: The technical name of the data product you are building. Make sure it's one word and all lowercase (e.g. nlp_use_case)
default: nlp_use_case
target_environment:
type: str
Expand All @@ -58,28 +58,52 @@ target_environment:
- production
- staging
default: staging
accelerator:
type: str
help: "The accelerator to use for training"
choices:
- gpu
- cpu
default: gpu
deploy_locally:
type: bool
help: "Whether to deploy locally"
default: True
deploy_to_huggingface:
type: bool
help: "Whether to deploy to HuggingFace Hub"
default: False
deploy_to_skypilot:
type: bool
help: "Whether to deploy to SkyPilot"
default: False
dataset:
type: str
help: "The name of the dataset to use from HuggingFace Datasets"
choices:
- financial_news
- airline_reviews
- imbd_reviews
default: financial_news
default: airline_reviews
model:
type: str
help: "The name of the model to use from HuggingFace Models"
choices:
- bert
- gpt2
default: bert
- bert-base-uncased
- roberta-base
- distilbert-base-cased
default: roberta-base
cloud_of_choice:
type: str
help: "Whether to use AWS cloud provider or GCP"
choices:
- aws
- gcp
default: aws
metric_compare_promotion:
type: bool
help: "Whether to promote model versions based on metrics. Otherwise, latest trained model will get promoted."
default: True
notify_on_failures:
type: bool
help: "Whether to notify on pipeline failures?"
Expand All @@ -92,10 +116,6 @@ zenml_server_url:
type: str
help: "The URL of the ZenML server [Optional]"
default: ""
custom_training:
type: bool
help: "Whether to use custom training or not"
default: False
# CONFIGURATION -------------------------
_templates_suffix: ""
_subdirectory: template
Expand Down
11 changes: 10 additions & 1 deletion template/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@ setup:
pip install -r requirements.txt
zenml integration install pytorch mlflow s3 gcp aws slack transformers -y

install-stack:
install-local-stack:
@echo "Specify stack name [$(stack_name)]: " && read input && [ -n "$$input" ] && stack_name="$$input" || stack_name="$(stack_name)" && \
zenml experiment-tracker register -f mlflow mlflow_local_$${stack_name} && \
zenml model-registry register -f mlflow mlflow_local_$${stack_name} && \
zenml model-deployer register -f mlflow mlflow_local_$${stack_name} && \
zenml stack register -a default -o default -r mlflow_local_$${stack_name} \
-d mlflow_local_$${stack_name} -e mlflow_local_$${stack_name} $${stack_name} && \
zenml stack set $${stack_name} && \
zenml stack up

89 changes: 0 additions & 89 deletions template/artifacts/materializer.py

This file was deleted.

62 changes: 0 additions & 62 deletions template/artifacts/model_metadata.py

This file was deleted.

Loading
Loading