Skip to content

Commit 05c46bf

Browse files
authored
Jupyterhub setup (#2)
- jupyterhub helm instructions setup - fixed bug in timing notebook - add collaborators section
1 parent be2d8c2 commit 05c46bf

File tree

12 files changed

+461
-55
lines changed

12 files changed

+461
-55
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ __pycache__
99
*.zip
1010
notebooks/trainer_*/
1111
notebooks/wandb/
12-
.venv
12+
.venv
13+
workshop_infra/cert/*
14+
workshop_infra/config.yaml
15+
16+
!/**/.gitkeep

Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#FROM jupyter/scipy-notebook:python-3.10.5
2+
3+
FROM jupyter/scipy-notebook:python-3.8.8
4+
5+
6+
7+
USER root
8+
9+
10+
RUN apt-get update && apt-get --yes install apt-utils && \
11+
apt-get --yes install htop tmux graphviz openjdk-11-jre-headless curl && \
12+
apt-get clean;
13+
14+
15+
# set the user back to original setting
16+
USER $NB_UID
17+
18+
19+
20+
# Install from requirements.txt file
21+
COPY --chown=${NB_UID}:${NB_GID} requirements.txt /tmp/
22+
23+
RUN pip install --no-cache-dir --requirement /tmp/requirements.txt && \
24+
fix-permissions "${CONDA_DIR}" && \
25+
fix-permissions "/home/${NB_USER}"
26+
27+
28+
#COPY --chown=${NB_UID}:${NB_GID} docker-setup.sh /tmp/
29+
30+
COPY --chown=${NB_UID}:${NB_GID} setup.ipynb /tmp/
31+
32+
RUN papermill /tmp/setup.ipynb /tmp/setup__out.ipynb -k python3 --log-output --log-level INFO --progress-bar && \
33+
fix-permissions "${CONDA_DIR}" && \
34+
fix-permissions "/home/${NB_USER}"

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ Notebook that shows how to use TorchServe to serve models
5252

5353
[![Watch the video](assets/slides_cover.png)](https://www.slideshare.net/nidhinpattaniyil/serving-bert-models-in-production-with-torchserve)
5454

55+
## Video
5556

57+
[![PyData Video](https://img.youtube.com/vi/sDGxzkOvxqY/0.jpg)](https://www.youtube.com/watch?v=sDGxzkOvxqY&ab_channel=PyData)
5658

5759

5860
## References
@@ -72,4 +74,8 @@ For more reference, refer to this [paper](https://arxiv.org/abs/2110.06199)
7274

7375
## Contact
7476

75-
For help or feedback, please reach out to [Nidhin Pattaniyil](https://www.linkedin.com/in/nidhinpattaniyil/) or [Adway Dhillon](https://www.linkedin.com/in/adwaydhillon/)
77+
For help or feedback, please reach out to :
78+
79+
- [Nidhin Pattaniyil](https://www.linkedin.com/in/nidhinpattaniyil/)
80+
- [Adway Dhillon](https://www.linkedin.com/in/adwaydhillon/)
81+
- [Vishal Rathi](https://www.linkedin.com/in/vishalkumarrathi/)

notebooks/02_timing.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@
320320
],
321321
"source": [
322322
"%%timeit -r 3 -n 5\n",
323-
"if torch.cuda.is_available:\n",
323+
"if torch.cuda.is_available():\n",
324324
" model_cuda = model.cuda()\n",
325325
" model_cuda(res['input_ids'].cuda(),res['attention_mask'].cuda())"
326326
]
@@ -408,7 +408,7 @@
408408
],
409409
"source": [
410410
"%%timeit -r 3 -n 5\n",
411-
"if torch.cuda.is_available:\n",
411+
"if torch.cuda.is_available():\n",
412412
" model_cuda = model.cuda()\n",
413413
" model_cuda(res['input_ids'].cuda(),res['attention_mask'].cuda())"
414414
]
@@ -496,7 +496,7 @@
496496
],
497497
"source": [
498498
"%%timeit -r 3 -n 5\n",
499-
"if torch.cuda.is_available:\n",
499+
"if torch.cuda.is_available():\n",
500500
" model_cuda = model.cuda()\n",
501501
" model_cuda(res['input_ids'].cuda(),res['attention_mask'].cuda())"
502502
]

notebooks/04_packaging.ipynb

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -823,9 +823,9 @@
823823
"text": [
824824
" % Total % Received % Xferd Average Speed Time Time Time Current\n",
825825
" Dload Upload Total Spent Left Speed\n",
826-
"\r",
827-
" 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\r",
828-
"100 265 100 214 100 51 6154 1466 --:--:-- --:--:-- --:--:-- 7571\r",
826+
"\r\n",
827+
" 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\r\n",
828+
"100 265 100 214 100 51 6154 1466 --:--:-- --:--:-- --:--:-- 7571\r\n",
829829
"100 265 100 214 100 51 6140 1463 --:--:-- --:--:-- --:--:-- 7571\n"
830830
]
831831
}
@@ -845,7 +845,25 @@
845845
"id": "african-donna",
846846
"metadata": {},
847847
"outputs": [],
848-
"source": []
848+
"source": [
849+
"import requests"
850+
]
851+
},
852+
{
853+
"cell_type": "code",
854+
"execution_count": null,
855+
"id": "aa92e2d6",
856+
"metadata": {},
857+
"outputs": [],
858+
"source": [
859+
"payload = {\"text\":\"herbal tea\",\"request_id\":\"test_id\"}\n",
860+
"\n",
861+
"endpoint = \"http://localhost:9080/predictions/pt_classifier\"\n",
862+
"\n",
863+
"res = requests.post(endpoint, json = payload)\n",
864+
"\n",
865+
"res.json()"
866+
]
849867
}
850868
],
851869
"metadata": {

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ torchviz==0.0.2
99
scikit-learn==1.0
1010
plotly==5.8.*
1111
wandb==0.12.*
12+
papermill==2.3.*

requirements_new.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
torch==1.12.*
2+
torch-model-archiver==0.6.0
3+
torchmetrics==0.9.*
4+
torchserve==0.6.*
5+
torchvision==0.13.*
6+
datasets==2.3.*
7+
transformers==4.20.*
8+
torchviz==0.0.2
9+
scikit-learn==1.0.*
10+
plotly==5.9.*
11+
wandb==0.12.*
12+
papermill==2.3.*

colab_starter.ipynb renamed to setup.ipynb

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -24,42 +24,25 @@
2424
]
2525
},
2626
{
27-
"cell_type": "code",
28-
"execution_count": null,
29-
"id": "homeless-announcement",
27+
"cell_type": "markdown",
28+
"id": "acd07905",
3029
"metadata": {},
31-
"outputs": [],
3230
"source": [
33-
"%%bash\n",
34-
"git clone https://github.com/npatta01/pytorch-serving-workshop.git -b main --depth 1"
31+
"we are cloning to tmp for jupyterhub setup \n"
3532
]
3633
},
3734
{
3835
"cell_type": "code",
3936
"execution_count": null,
40-
"id": "spectacular-scott",
37+
"id": "homeless-announcement",
4138
"metadata": {},
4239
"outputs": [],
4340
"source": [
4441
"%%bash\n",
45-
"cd pytorch-serving-workshop\n",
46-
"mkdir -p artifacts/dataset_processed/amazon\n",
47-
"mkdir -p artifacts/dataset_processed/model\n",
48-
"\n",
49-
"\n",
50-
"cd artifacts\n",
51-
"\n",
5242
"\n",
53-
"# dataset\n",
54-
"echo \"downloading dataset\"\n",
55-
"wget https://github.com/npatta01/pytorch-serving-workshop/releases/download/v0.0.1/dataset_processed.zip\n",
56-
"unzip dataset_processed.zip\n",
57-
"\n",
58-
"\n",
59-
"# model trained on above dataset\n",
60-
"echo \"downloading model\"\n",
61-
"wget https://github.com/npatta01/pytorch-serving-workshop/releases/download/v0.0.1/model.zip \n",
62-
"unzip model.zip\n"
43+
"mkdir -p /tmp/workshop\n",
44+
"cd /tmp/workshop\n",
45+
"git clone https://github.com/npatta01/pytorch-serving-workshop.git -b main --depth 1"
6346
]
6447
},
6548
{
@@ -77,64 +60,94 @@
7760
"metadata": {},
7861
"outputs": [],
7962
"source": [
80-
"!pip install -r pytorch-serving-workshop/requirements.txt"
63+
"!pip install -r /tmp/workshop/pytorch-serving-workshop/requirements.txt"
8164
]
8265
},
8366
{
84-
"cell_type": "code",
85-
"execution_count": null,
86-
"id": "neither-shipping",
67+
"cell_type": "markdown",
68+
"id": "875c286c",
8769
"metadata": {},
88-
"outputs": [],
89-
"source": []
70+
"source": [
71+
"download processed dataset and model"
72+
]
9073
},
9174
{
9275
"cell_type": "code",
9376
"execution_count": null,
94-
"id": "checked-priest",
77+
"id": "spectacular-scott",
9578
"metadata": {},
9679
"outputs": [],
9780
"source": [
98-
"!sudo apt-get install htop tmux -y"
81+
"%%bash\n",
82+
"\n",
83+
"cd /tmp/workshop\n",
84+
"\n",
85+
"cd pytorch-serving-workshop\n",
86+
"mkdir -p artifacts/dataset_processed/amazon\n",
87+
"mkdir -p artifacts/dataset_processed/model\n",
88+
"\n",
89+
"\n",
90+
"cd artifacts\n",
91+
"\n",
92+
"\n",
93+
"# dataset\n",
94+
"echo \"downloading dataset\"\n",
95+
"wget https://github.com/npatta01/pytorch-serving-workshop/releases/download/v0.0.1/dataset_processed.zip\n",
96+
"unzip dataset_processed.zip\n",
97+
"\n",
98+
"\n",
99+
"# model trained on above dataset\n",
100+
"echo \"downloading model\"\n",
101+
"wget https://github.com/npatta01/pytorch-serving-workshop/releases/download/v0.0.1/model.zip \n",
102+
"unzip model.zip\n"
99103
]
100104
},
101105
{
102106
"cell_type": "markdown",
103-
"id": "immune-institution",
107+
"id": "0ce1ca35",
104108
"metadata": {},
105109
"source": [
106-
"## Colabcode\n",
107-
"Colab doesn't support multiple notebooks, so we use colabcode to setup vscode + ngrok"
110+
"Download transformer models"
108111
]
109112
},
110113
{
111114
"cell_type": "code",
112115
"execution_count": null,
113-
"id": "insured-navigator",
116+
"id": "9073adaa",
114117
"metadata": {},
115118
"outputs": [],
116119
"source": [
117-
"!pip install colabcode==0.3.0"
120+
"import transformers"
118121
]
119122
},
120123
{
121124
"cell_type": "code",
122125
"execution_count": null,
123-
"id": "capital-major",
126+
"id": "c66c5e14",
124127
"metadata": {},
125128
"outputs": [],
126129
"source": [
127-
"from colabcode import ColabCode\n"
130+
"for model_name in [\"bert-large-uncased\",\"bert-base-uncased\",\"distilbert-base-uncased\"]:\n",
131+
" model = transformers.AutoModelForSequenceClassification.from_pretrained(model_name)\n",
132+
"\n",
133+
" tokenizer = transformers.AutoTokenizer.from_pretrained(\n",
134+
" model_name\n",
135+
" )\n",
136+
"\n",
137+
" query = \"men shoes\"\n",
138+
" res = tokenizer.encode_plus(query, return_tensors=\"pt\", padding=\"max_length\", truncation=True)\n",
139+
"\n",
140+
" model_res = model(**res)\n"
128141
]
129142
},
130143
{
131144
"cell_type": "code",
132145
"execution_count": null,
133-
"id": "operational-spotlight",
146+
"id": "neither-shipping",
134147
"metadata": {},
135148
"outputs": [],
136149
"source": [
137-
"ColabCode(port=10000, mount_drive=False)"
150+
"!cp -r /tmp/workshop/ $HOME/workshop/"
138151
]
139152
}
140153
],
@@ -144,11 +157,6 @@
144157
"type": "gcloud",
145158
"uri": "gcr.io/deeplearning-platform-release/rapids-gpu.0-18:m65"
146159
},
147-
"kernelspec": {
148-
"display_name": "Python [conda env:pytorch]",
149-
"language": "python",
150-
"name": "conda-env-pytorch-py"
151-
},
152160
"language_info": {
153161
"codemirror_mode": {
154162
"name": "ipython",

workshop_infra/cert/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)