Skip to content

Commit

Permalink
V2D-1268 Use smaller model in demo and reference larger (#5119)
Browse files Browse the repository at this point in the history
  • Loading branch information
vtaskow authored Sep 1, 2023
1 parent fe47d5e commit 24dd8a7
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 16 deletions.
19 changes: 6 additions & 13 deletions doc/source/servers/huggingface.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,22 @@ You can deploy a custom HuggingFace model by providing the location of the model
apiVersion: machinelearning.seldon.io/v1alpha2
kind: SeldonDeployment
metadata:
name: custom-gpt2-hf-model
name: custom-tiny-stories-model
spec:
protocol: v2
predictors:
- graph:
name: transformer
implementation: HUGGINGFACE_SERVER
modelUri: gs://seldon-models/v1.18.0-dev/huggingface/custom-text-generation
modelUri: gs://seldon-models/v1.18.0-dev/huggingface/text-gen-custom-tiny-stories
parameters:
- name: task
type: STRING
value: text-generation
componentSpecs:
- spec:
containers:
- name: transformer
resources:
limits:
cpu: 1
memory: 4Gi
requests:
cpu: 100m
memory: 3Gi
name: default
replicas: 1
```

````{note}
As a next step, why not try running a larger-scale model? You can find one in gs://seldon-models/v1.18.0-dev/huggingface/text-gen-custom-gpt2. However, you may need to request more memory!
````
4 changes: 3 additions & 1 deletion servers/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ sklearnserver-models:


huggingface-models:
make -C huggingface/models/text-generation
make -C huggingface/models/text-gen-gpt2
make -C huggingface/models/text-gen-tiny-stories

Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ train:
.env/bin/python train.py

upload:
gsutil cp -r text-generation-model-artefacts/* gs://seldon-models/v${VERSION}/huggingface/custom-text-generation/
gsutil cp -r text-generation-model-artefacts/* gs://seldon-models/v${VERSION}/huggingface/text-gen-custom-gpt2/
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ def main() -> None:


if __name__ == "__main__":
print("Building a custom HuggingFace model...")
print("Building a custom GPT2 HuggingFace model...")
main()
2 changes: 2 additions & 0 deletions servers/huggingface/models/text-gen-tiny-stories/.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-gen-tiny-stories/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/text-gen-custom-tiny-stories/
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
seldon_core
transformers >=4.30,<4.32
torch==2.0.0
19 changes: 19 additions & 0 deletions servers/huggingface/models/text-gen-tiny-stories/train.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from transformers import (
AutoModelForCausalLM,
AutoTokenizer,
pipeline,
)


def main() -> None:
tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-125M")
model = AutoModelForCausalLM.from_pretrained('roneneldan/TinyStories-1M')

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

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


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

0 comments on commit 24dd8a7

Please sign in to comment.