Skip to content

Commit

Permalink
feat(docs): [SCv1] Automatically create and upload a custom HF model …
Browse files Browse the repository at this point in the history
…to seldon-models in GCS on every version release (#5104)

* V2D-1258 Create and upload a custom HF model to seldon-models in GCS

* Remove left over link for kfserving storage initialiser

* Change GCS location to make it obvious it is a custom hf model
  • Loading branch information
vtaskow authored Aug 24, 2023
1 parent 6652d08 commit 7c2d4f1
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/upgrade-to-rclone/global-rclone-upgrade.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"In this documentation page we provide an example upgrade path from kfserving-based to rclone-based storage initializer. This is required due to the fact that secret format expected by these two storage initializers is different. \n",
"\n",
"Storage initializers are used by Seldon's pre-packaged model servers to download models binaries. \n",
"As it is explained in the [SC 1.8 upgrading notes](https://docs.seldon.io/projects/seldon-core/en/latest/reference/upgrading.html#upgrading-to-1-8) the [seldonio/rclone-storage-initializer](https://github.com/SeldonIO/seldon-core/tree/master/components/rclone-storage-initializer) became default storage initializer in v1.8.0. However, it is still possible to run with kfserving-based Storage Initializer as documented [here](https://docs.seldon.io/projects/seldon-core/en/latest/servers/kfserving-storage-initializer.html).\n",
"As it is explained in the [SC 1.8 upgrading notes](https://docs.seldon.io/projects/seldon-core/en/latest/reference/upgrading.html#upgrading-to-1-8) the [seldonio/rclone-storage-initializer](https://github.com/SeldonIO/seldon-core/tree/master/components/rclone-storage-initializer) became default storage initializer in v1.8.0.\n",
"\n",
"In this tutorial we aim to provide an intuition of the steps you will have to carry to migrate to the new rclone-based Storage Initializer with the context that every cluster configuration will be different, so you should be able to see this as something you can build from.\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/upgrade-to-rclone/rclone-upgrade.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"In this documentation page we provide an example upgrade path from kfserving-based to rclone-based storage initializer. This is required due to the fact that secret format expected by these two storage initializers is different. \n",
"\n",
"Storage initializers are used by Seldon's pre-packaged model servers to download models binaries. \n",
"As it is explained in the [SC 1.8 upgrading notes](https://docs.seldon.io/projects/seldon-core/en/latest/reference/upgrading.html#upgrading-to-1-8) the [seldonio/rclone-storage-initializer](https://github.com/SeldonIO/seldon-core/tree/master/components/rclone-storage-initializer) became default storage initializer in v1.8.0. However, it is still possible to run with kfserving-based Storage Initializer as documented [here](https://docs.seldon.io/projects/seldon-core/en/latest/servers/kfserving-storage-initializer.html).\n",
"As it is explained in the [SC 1.8 upgrading notes](https://docs.seldon.io/projects/seldon-core/en/latest/reference/upgrading.html#upgrading-to-1-8) the [seldonio/rclone-storage-initializer](https://github.com/SeldonIO/seldon-core/tree/master/components/rclone-storage-initializer) became default storage initializer in v1.8.0.\n",
"\n",
"In this tutorial we will show how to upgrade your configuration to new Storage Initializer with focus on getting the new format of a required secret right.\n",
"\n",
Expand Down
6 changes: 5 additions & 1 deletion servers/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
models: mlflowserver-models sklearnserver-models
models: mlflowserver-models sklearnserver-models huggingface-models


mlflowserver-models:
Expand All @@ -8,3 +8,7 @@ mlflowserver-models:
sklearnserver-models:
make -C sklearnserver/models/iris
make -C sklearnserver/models/moviesentiment


huggingface-models:
make -C huggingface/models/text-generation
2 changes: 2 additions & 0 deletions servers/huggingface/models/text-generation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env/
text-generation-model-artefacts/
16 changes: 16 additions & 0 deletions servers/huggingface/models/text-generation/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
VERSION := $(shell cat ../../../../version.txt)

all: env train upload

model: env train

env:
python3 -m venv .env
./.env/bin/pip install --upgrade pip setuptools
./.env/bin/pip install -r requirements.txt

train:
.env/bin/python train.py

upload:
gsutil cp -r text-generation-model-artefacts/* gs://seldon-models/v${VERSION}/huggingface/custom-text-generation/
3 changes: 3 additions & 0 deletions servers/huggingface/models/text-generation/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
seldon_core
transformers >=4.30,<4.32
tensorflow == 2.12.0
19 changes: 19 additions & 0 deletions servers/huggingface/models/text-generation/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()

0 comments on commit 7c2d4f1

Please sign in to comment.