From 70a7714012edbca795c79fb3c6eff4f40c34071d Mon Sep 17 00:00:00 2001 From: Viktor Taskov Date: Wed, 23 Aug 2023 11:33:32 +0100 Subject: [PATCH 1/3] V2D-1258 Create and upload a custom HF model to seldon-models in GCS --- servers/Makefile | 6 +++++- .../models/text-generation/.gitignore | 2 ++ .../models/text-generation/Makefile | 16 ++++++++++++++++ .../models/text-generation/requirements.txt | 3 +++ .../models/text-generation/train.py | 19 +++++++++++++++++++ 5 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 servers/huggingface/models/text-generation/.gitignore create mode 100644 servers/huggingface/models/text-generation/Makefile create mode 100644 servers/huggingface/models/text-generation/requirements.txt create mode 100644 servers/huggingface/models/text-generation/train.py diff --git a/servers/Makefile b/servers/Makefile index 7cd9dbfbda..8fece4eeea 100644 --- a/servers/Makefile +++ b/servers/Makefile @@ -1,4 +1,4 @@ -models: mlflowserver-models sklearnserver-models +models: mlflowserver-models sklearnserver-models huggingface-models mlflowserver-models: @@ -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 diff --git a/servers/huggingface/models/text-generation/.gitignore b/servers/huggingface/models/text-generation/.gitignore new file mode 100644 index 0000000000..deb19ba86d --- /dev/null +++ b/servers/huggingface/models/text-generation/.gitignore @@ -0,0 +1,2 @@ +.env/ +text-generation-model-artefacts/ \ No newline at end of file diff --git a/servers/huggingface/models/text-generation/Makefile b/servers/huggingface/models/text-generation/Makefile new file mode 100644 index 0000000000..b4398e514a --- /dev/null +++ b/servers/huggingface/models/text-generation/Makefile @@ -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/text-generation/ \ No newline at end of file diff --git a/servers/huggingface/models/text-generation/requirements.txt b/servers/huggingface/models/text-generation/requirements.txt new file mode 100644 index 0000000000..40acbb5e16 --- /dev/null +++ b/servers/huggingface/models/text-generation/requirements.txt @@ -0,0 +1,3 @@ +seldon_core +transformers >=4.30,<4.32 +tensorflow == 2.12.0 \ No newline at end of file diff --git a/servers/huggingface/models/text-generation/train.py b/servers/huggingface/models/text-generation/train.py new file mode 100644 index 0000000000..70a81f0660 --- /dev/null +++ b/servers/huggingface/models/text-generation/train.py @@ -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() From 72f2a22eaac648ac1e02c19a35e84b91de41f356 Mon Sep 17 00:00:00 2001 From: Viktor Taskov Date: Wed, 23 Aug 2023 14:00:54 +0100 Subject: [PATCH 2/3] Remove left over link for kfserving storage initialiser --- examples/upgrade-to-rclone/global-rclone-upgrade.ipynb | 2 +- examples/upgrade-to-rclone/rclone-upgrade.ipynb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/upgrade-to-rclone/global-rclone-upgrade.ipynb b/examples/upgrade-to-rclone/global-rclone-upgrade.ipynb index 0a5b1d9ade..83b2a2b1d4 100644 --- a/examples/upgrade-to-rclone/global-rclone-upgrade.ipynb +++ b/examples/upgrade-to-rclone/global-rclone-upgrade.ipynb @@ -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", diff --git a/examples/upgrade-to-rclone/rclone-upgrade.ipynb b/examples/upgrade-to-rclone/rclone-upgrade.ipynb index 2fb3771d7c..5e8e441d87 100644 --- a/examples/upgrade-to-rclone/rclone-upgrade.ipynb +++ b/examples/upgrade-to-rclone/rclone-upgrade.ipynb @@ -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", From 4f0907096fa1091ddcfd180fa91612c51668dc23 Mon Sep 17 00:00:00 2001 From: Viktor Taskov Date: Wed, 23 Aug 2023 14:17:51 +0100 Subject: [PATCH 3/3] Change GCS location to make it obvious it is a custom hf model --- servers/huggingface/models/text-generation/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/servers/huggingface/models/text-generation/Makefile b/servers/huggingface/models/text-generation/Makefile index b4398e514a..cf17693eb9 100644 --- a/servers/huggingface/models/text-generation/Makefile +++ b/servers/huggingface/models/text-generation/Makefile @@ -13,4 +13,4 @@ train: .env/bin/python train.py upload: - gsutil cp -r text-generation-model-artefacts/* gs://seldon-models/v${VERSION}/huggingface/text-generation/ \ No newline at end of file + gsutil cp -r text-generation-model-artefacts/* gs://seldon-models/v${VERSION}/huggingface/custom-text-generation/ \ No newline at end of file