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

feat(docs): [SCv2] Automatically create and upload a custom HF model to seldon-models in GCS on every new MLServer version #5103

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
19 changes: 17 additions & 2 deletions samples/scripts/models/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ TRITON_VERSION=$(shell grep 'nvidia/tritonserver' ../../../scheduler/Makefile |
TRITON_FOLDER=triton_${TRITON_VERSION}

.PHONY: train-all
train-all: iris moviesentiment income income-xgb income-lgb download-mnist-onnx download-cifar10-tensorflow wine-mlflow mnist-pytorch
train-all: iris text-generation-huggingface moviesentiment income income-xgb income-lgb download-mnist-onnx download-cifar10-tensorflow wine-mlflow mnist-pytorch

.PHONY: upload-all
upload-all: upload-iris upload-moviesentiment upload-income upload-income-xgb upload-income-lgb upload-mnist-onnx upload-cifar10-tensorflow upload-wine-mlflow upload-mnist-pytorch
upload-all: upload-iris upload-text-generation-huggingface upload-moviesentiment upload-income upload-income-xgb upload-income-lgb upload-mnist-onnx upload-cifar10-tensorflow upload-wine-mlflow upload-mnist-pytorch

.PHONY: env
env:
Expand All @@ -20,6 +20,7 @@ env:
mlserver-mlflow==${MLSERVER_VERSION} \
mlserver-lightgbm==${MLSERVER_VERSION} \
mlserver-alibi-explain==${MLSERVER_VERSION} \
mlserver-huggingface==${MLSERVER_VERSION} \
requests
wget https://raw.githubusercontent.com/pytorch/examples/main/mnist/requirements.txt -O mnist-pytorch/requirements.txt
.env/bin/pip install -r mnist-pytorch/requirements.txt
Expand All @@ -36,6 +37,20 @@ iris: env
upload-iris:
gsutil cp iris/model.joblib gs://seldon-models/scv2/samples/${MLSERVER_FOLDER}/iris-sklearn/model.joblib

#
# HuggingFace text-generation model
#

.PHONY: text-generation-huggingface
text-generation-huggingface: env
cd text-generation-huggingface && ../.env/bin/python3 train.py


.PHONY: upload-text-generation-huggingface
upload-text-generation-huggingface:
gsutil cp -r text-generation-huggingface/text-generation-model-artefacts/* gs://seldon-models/scv2/samples/${MLSERVER_FOLDER}/custom-text-generation-huggingface/
gsutil cp text-generation-huggingface/model-settings.json gs://seldon-models/scv2/samples/${MLSERVER_FOLDER}/custom-text-generation-huggingface/

#
# movie sentiment SKLearn model
#
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
text-generation-model-artefacts/
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "transformer",
"implementation": "mlserver_huggingface.HuggingFaceRuntime",
"parameters": {
"extra": {
"task": "text-generation"
}
}
}
19 changes: 19 additions & 0 deletions samples/scripts/models/text-generation-huggingface/train.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from transformers import (
GPT2Tokenizer,
TFGPT2LMHeadModel,
pipeline,
)


def main() -> None:
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
model = TFGPT2LMHeadModel.from_pretrained("gpt2")

p = pipeline(task="text-generation", model=model, tokenizer=tokenizer)

p.save_pretrained("text-generation-model-artefacts")


if __name__ == "__main__":
print("Building a custom HuggingFace model...")
main()
Loading