{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Train a model locally or remote" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "scrolled": true, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[33mWARNING: Skipping ezsmdeploy as it is not installed.\u001b[0m\u001b[33m\n", "\u001b[0mNote: you may need to restart the kernel to use updated packages.\n", "Looking in indexes: https://pypi.org/simple, https://pip.repos.neuron.amazonaws.com\n", "Obtaining file:///home/ec2-user/SageMaker/easy-amazon-sagemaker-deployments\n", " Preparing metadata (setup.py) ... \u001b[?25ldone\n", "\u001b[?25hCollecting sagemaker==2.173.0 (from ezsmdeploy==1.96.dev0)\n", " Using cached sagemaker-2.173.0.tar.gz (854 kB)\n", " Preparing metadata (setup.py) ... \u001b[?25ldone\n", "\u001b[?25hCollecting yaspin==0.16.0 (from ezsmdeploy==1.96.dev0)\n", " Using cached yaspin-0.16.0-py2.py3-none-any.whl (18 kB)\n", "Collecting shortuuid==1.0.1 (from ezsmdeploy==1.96.dev0)\n", " Using cached shortuuid-1.0.1-py3-none-any.whl (7.5 kB)\n", "Collecting sagemaker-studio-image-build==0.5.0 (from ezsmdeploy==1.96.dev0)\n", " Using cached sagemaker_studio_image_build-0.5.0.tar.gz (11 kB)\n", " Preparing metadata (setup.py) ... \u001b[?25ldone\n", "\u001b[?25hRequirement already satisfied: boto3>=1.14.12 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from ezsmdeploy==1.96.dev0) (1.26.157)\n", "Requirement already satisfied: attrs<24,>=23.1.0 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (23.1.0)\n", "Requirement already satisfied: cloudpickle==2.2.1 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (2.2.1)\n", "Requirement already satisfied: google-pasta in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (0.2.0)\n", "Requirement already satisfied: numpy<2.0,>=1.9.0 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (1.21.6)\n", "Requirement already satisfied: protobuf<5.0,>=3.12 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (3.20.3)\n", "Requirement already satisfied: smdebug_rulesconfig==1.0.1 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (1.0.1)\n", "Requirement already satisfied: importlib-metadata<7.0,>=1.4.0 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (4.11.4)\n", "Requirement already satisfied: packaging>=20.0 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (23.1)\n", "Requirement already satisfied: pandas in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (1.3.5)\n", "Requirement already satisfied: pathos in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (0.3.0)\n", "Requirement already satisfied: schema in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (0.7.5)\n", "Collecting PyYAML~=6.0 (from sagemaker==2.173.0->ezsmdeploy==1.96.dev0)\n", " Downloading PyYAML-6.0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (670 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m670.1/670.1 kB\u001b[0m \u001b[31m47.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hRequirement already satisfied: jsonschema in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (4.17.3)\n", "Requirement already satisfied: platformdirs in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (3.5.0)\n", "Requirement already satisfied: tblib==1.7.0 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (1.7.0)\n", "Requirement already satisfied: botocore<1.30.0,>=1.29.157 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from boto3>=1.14.12->ezsmdeploy==1.96.dev0) (1.29.157)\n", "Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from boto3>=1.14.12->ezsmdeploy==1.96.dev0) (1.0.1)\n", "Requirement already satisfied: s3transfer<0.7.0,>=0.6.0 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from boto3>=1.14.12->ezsmdeploy==1.96.dev0) (0.6.1)\n", "Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from botocore<1.30.0,>=1.29.157->boto3>=1.14.12->ezsmdeploy==1.96.dev0) (2.8.2)\n", "Requirement already satisfied: urllib3<1.27,>=1.25.4 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from botocore<1.30.0,>=1.29.157->boto3>=1.14.12->ezsmdeploy==1.96.dev0) (1.26.14)\n", "Requirement already satisfied: zipp>=0.5 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from importlib-metadata<7.0,>=1.4.0->sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (3.15.0)\n", "Requirement already satisfied: typing-extensions>=3.6.4 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from importlib-metadata<7.0,>=1.4.0->sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (4.5.0)\n", "Requirement already satisfied: six in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from google-pasta->sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (1.16.0)\n", "Requirement already satisfied: importlib-resources>=1.4.0 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from jsonschema->sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (5.12.0)\n", "Requirement already satisfied: pkgutil-resolve-name>=1.3.10 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from jsonschema->sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (1.3.10)\n", "Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from jsonschema->sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (0.18.1)\n", "Requirement already satisfied: pytz>=2017.3 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from pandas->sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (2023.3)\n", "Requirement already satisfied: ppft>=1.7.6.6 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from pathos->sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (1.7.6.6)\n", "Requirement already satisfied: dill>=0.3.6 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from pathos->sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (0.3.6)\n", "Requirement already satisfied: pox>=0.3.2 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from pathos->sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (0.3.2)\n", "Requirement already satisfied: multiprocess>=0.70.14 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from pathos->sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (0.70.14)\n", "Requirement already satisfied: contextlib2>=0.5.5 in /home/ec2-user/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages (from schema->sagemaker==2.173.0->ezsmdeploy==1.96.dev0) (21.6.0)\n", "Building wheels for collected packages: sagemaker, sagemaker-studio-image-build\n", " Building wheel for sagemaker (setup.py) ... \u001b[?25ldone\n", "\u001b[?25h Created wheel for sagemaker: filename=sagemaker-2.173.0-py2.py3-none-any.whl size=1163282 sha256=6a8f12d456205b144f2e8075259e0e78e994435dfb7d35749f4cb3f4f2fe34e2\n", " Stored in directory: /home/ec2-user/.cache/pip/wheels/60/36/51/bd95494827eef1c60ac3a0a49b0c95051fe45d5ebe9a7b5e5f\n", " Building wheel for sagemaker-studio-image-build (setup.py) ... \u001b[?25ldone\n", "\u001b[?25h Created wheel for sagemaker-studio-image-build: filename=sagemaker_studio_image_build-0.5.0-py3-none-any.whl size=11236 sha256=f0df7ea01740b4bd1b0f31daa25d29279c9d148d910d5ab58519fca35c42ebdf\n", " Stored in directory: /home/ec2-user/.cache/pip/wheels/f2/2f/aa/ce7cd76e48a21bd4cb1fc439c908189160140aa11ddf37f695\n", "Successfully built sagemaker sagemaker-studio-image-build\n", "Installing collected packages: yaspin, shortuuid, PyYAML, sagemaker, sagemaker-studio-image-build, ezsmdeploy\n", " Attempting uninstall: PyYAML\n", " Found existing installation: PyYAML 5.4.1\n", " Uninstalling PyYAML-5.4.1:\n", " Successfully uninstalled PyYAML-5.4.1\n", " Attempting uninstall: sagemaker\n", " Found existing installation: sagemaker 2.167.0\n", " Uninstalling sagemaker-2.167.0:\n", " Successfully uninstalled sagemaker-2.167.0\n", " Running setup.py develop for ezsmdeploy\n", "\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", "awscli 1.27.157 requires PyYAML<5.5,>=3.10, but you have pyyaml 6.0.1 which is incompatible.\u001b[0m\u001b[31m\n", "\u001b[0mSuccessfully installed PyYAML-6.0.1 ezsmdeploy-1.96.dev0 sagemaker-2.173.0 sagemaker-studio-image-build-0.5.0 shortuuid-1.0.1 yaspin-0.16.0\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "%pip uninstall -y ezsmdeploy --quiet\n", "# !pip install --upgrade pip\n", "%pip install ezsmdeploy==2.0.0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Note: you may need to restart the kernel to use updated packages." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Testing foundation model " ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "scrolled": true, "tags": [] }, "outputs": [], "source": [ "# %pip uninstall -y sagemaker\n", "# %pip install --upgrade sagemaker==2.148.0 --no-cache-dir" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "'2.148.0'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import sagemaker\n", "sagemaker.__version__" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Name: ezsmdeploy\n", "Version: 1.96.dev0\n", "Summary: SageMaker custom deployments made easy\n", "Home-page: https://pypi.python.org/pypi/ezsmdeploy\n", "Author: Shreyas Subramanian\n", "Author-email: subshrey@amazon.com\n", "License: MIT\n", "Location: /home/ec2-user/SageMaker/easy-amazon-sagemaker-deployments\n", "Editable project location: /home/ec2-user/SageMaker/easy-amazon-sagemaker-deployments\n", "Requires: boto3, sagemaker, sagemaker-studio-image-build, shortuuid, yaspin\n", "Required-by: \n" ] } ], "source": [ "!pip show ezsmdeploy" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "tags": [] }, "outputs": [], "source": [ "import ezsmdeploy" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "List of foundation models in Jumpstart: \n", "\n", "huggingface-text2text-bart4csc-base-chinese\n", "huggingface-text2text-bigscience-t0pp\n", "huggingface-text2text-bigscience-t0pp-bnb-int8\n", "huggingface-text2text-bigscience-t0pp-fp16\n", "huggingface-text2text-flan-t5-base\n", "huggingface-text2text-flan-t5-base-samsum\n", "huggingface-text2text-flan-t5-large\n", "huggingface-text2text-flan-t5-small\n", "huggingface-text2text-flan-t5-xl\n", "huggingface-text2text-flan-t5-xxl\n", "huggingface-text2text-flan-t5-xxl-bnb-int8\n", "huggingface-text2text-flan-t5-xxl-fp16\n", "huggingface-text2text-flan-ul2-bf16\n", "huggingface-text2text-pegasus-paraphrase\n", "huggingface-text2text-qcpg-sentences\n", "huggingface-text2text-t5-one-line-summary\n" ] } ], "source": [ "ezsmdeploy.utils().list_foundation_models()" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[K0:00:00.080592 | created model(s). Now deploying on ml.g5.12xlarge\n", "\u001b[K0:13:34.643305 | deployed model--------!\n", "\u001b[K\u001b[32m0:13:34.643388 | Done! ✔\u001b[0m \n" ] } ], "source": [ "ezonsm = ezsmdeploy.Deploy(model = \"huggingface-text2text-flan-t5-xxl-fp16\",\n", " foundation_model=True,\n", " instance_type='ml.g5.12xlarge')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Set serializer if needed" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "tags": [] }, "outputs": [], "source": [ "from sagemaker.serializers import JSONSerializer\n", "from sagemaker.deserializers import JSONDeserializer\n", "\n", "ezonsm.predictor.serializer = JSONSerializer()\n", "ezonsm.predictor.deserializer = JSONDeserializer()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Indvidual Utterance testing" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "{'generated_texts': ['Spread the mozzarella cheese on the pizza crust and sprinkle some Parmesan cheese, then add the other ingredients and cook for a few minutes in the oven. Serve']}" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "payload = {\n", " \"text_inputs\": \"Steps to make a pizza\\n\",\n", " \"max_length\": 100,\n", " \"max_time\": 10,\n", " \"top_k\": 50,\n", " \"top_p\": 0.95,\n", " \"do_sample\": True}\n", "\n", "response = ezonsm.predictor.predict(payload)\n", "\n", "response" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "ezonsm.predictor.delete_endpoint()" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "'ezsm-endpoint-aw96end9eknuiyga9dnnpp'" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ezonsm.endpoint_name" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "'aw96end9eknuiyga9dnnpp'" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ezonsm.name" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "'huggingface-text2text-flan-t5-xxl-fp16'" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ezonsm.model" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "conda_amazonei_pytorch_latest_p37", "language": "python", "name": "conda_amazonei_pytorch_latest_p37" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.10" } }, "nbformat": 4, "nbformat_minor": 4 }