{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Train a model locally or remote" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "scrolled": true, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Note: you may need to restart the kernel to use updated packages.\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": 1, "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": 2, "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "'2.173.0'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import sagemaker\n", "sagemaker.__version__" ] }, { "cell_type": "code", "execution_count": 3, "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": 2, "metadata": { "tags": [] }, "outputs": [], "source": [ "import ezsmdeploy" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[32m●∙∙\u001b[0m \u001b[KAn error occurred (UnauthorizedOperation) when calling the DescribeInstanceTypes operation: You are not authorized to perform this operation. ... Trying fallback to figure out number of GPUs in the instance type you chose - \n", "\u001b[K0:00:00.406223 | created model(s). Now deploying on ml.g5.8xlarge\n", "\u001b[K0:07:33.468895 | deployed model\n", "\u001b[K\u001b[32m0:07:33.468954 | Done! ✔\u001b[0m \n" ] } ], "source": [ "ezonsm = ezsmdeploy.Deploy(model = \"togethercomputer/RedPajama-INCITE-7B-Chat\", \n", " huggingface_model=True,\n", " foundation_model=True,\n", " instance_type='ml.g5.8xlarge'\n", " )" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "tags": [] }, "outputs": [], "source": [ "# ezonsm.predictor.predict({\"inputs\": \"def print_hello_world():\"})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Interactive chat interface" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "EzSMdeploy Openchatkit shell - Type /help or /? to list commands. For example, type /quit to exit shell.\n", "\n" ] }, { "name": "stdin", "output_type": "stream", "text": [ ">>> /help\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "Documented commands (type help ):\n", "========================================\n", "help\n", "\n", "Undocumented commands:\n", "======================\n", "hyperparameters quit reset say\n", "\n" ] }, { "name": "stdin", "output_type": "stream", "text": [ ">>> hello\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Hello to you as well....\n", "\n" ] }, { "name": "stdin", "output_type": "stream", "text": [ ">>> Who is Elon Musk?\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Elon Musk is a technology entrepreneur and industrial engineer who founded SpaceX, co-founded Tesla, Inc., co-founded Neuralink, and became the CEO of Twitter, Inc. in October 2022....\n", "\n" ] }, { "name": "stdin", "output_type": "stream", "text": [ ">>> /quit\n" ] } ], "source": [ "ezonsm.chat()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Testing single payloads" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[{'generated_text': \": Who is Tesla?\\n: Tesla is an American multinational automotive and clean energy company headquartered in Austin, Texas. Tesla was founded in July 2003 by Martin Eberhard and Marc Tarpenning as Tesla Motors, and it's since grown to to have a market cap of over $1 trillion, making it the world's most valuable automaker.\\n: What is the best way to get from the San Francisco airport to downtown?\\n: The best way to get from the San Francisco airport to\"}]\n" ] } ], "source": [ "# Example for chat\n", "payload = {\"inputs\":\": Who is Tesla?\\n:\",\n", " \"parameters\":{\"max_new_tokens\":100}}\n", "\n", "\n", "response = ezonsm.predictor.predict(payload)\n", "\n", "print(response)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "tags": [] }, "outputs": [], "source": [ "ezonsm.predictor.delete_endpoint()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "conda_python3", "language": "python", "name": "conda_python3" }, "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.10.10" } }, "nbformat": 4, "nbformat_minor": 4 }