diff --git a/v3-examples/inference-examples/huggingface-example.ipynb b/v3-examples/inference-examples/huggingface-example.ipynb index 869b93f759..0a10ec66b2 100644 --- a/v3-examples/inference-examples/huggingface-example.ipynb +++ b/v3-examples/inference-examples/huggingface-example.ipynb @@ -9,6 +9,14 @@ "This notebook demonstrates how to deploy HuggingFace models using SageMaker V3 ModelBuilder for text generation tasks." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Prerequisites\n", + "Note: Ensure you have sagemaker and ipywidgets installed in your environment. The ipywidgets package is required to monitor endpoint deployment progress in Jupyter notebooks." + ] + }, { "cell_type": "code", "execution_count": null, @@ -292,7 +300,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "venv-test", "language": "python", "name": "python3" }, @@ -306,9 +314,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.12.11" } }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/v3-examples/inference-examples/in-process-mode-example.ipynb b/v3-examples/inference-examples/in-process-mode-example.ipynb index e5ba8c0b79..ecf5c0c7e5 100644 --- a/v3-examples/inference-examples/in-process-mode-example.ipynb +++ b/v3-examples/inference-examples/in-process-mode-example.ipynb @@ -313,7 +313,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "venv-test", "language": "python", "name": "python3" }, @@ -327,9 +327,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.12.11" } }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/v3-examples/inference-examples/inference-spec-example.ipynb b/v3-examples/inference-examples/inference-spec-example.ipynb index d22cceaec1..9f2f583376 100644 --- a/v3-examples/inference-examples/inference-spec-example.ipynb +++ b/v3-examples/inference-examples/inference-spec-example.ipynb @@ -9,6 +9,14 @@ "This notebook demonstrates how to create and deploy custom models using InferenceSpec with SageMaker V3 ModelBuilder." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Prerequisites\n", + "Note: Ensure you have sagemaker and ipywidgets installed in your environment. The ipywidgets package is required to monitor endpoint deployment progress in Jupyter notebooks.\n" + ] + }, { "cell_type": "code", "execution_count": null, @@ -311,7 +319,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "venv-test", "language": "python", "name": "python3" }, @@ -325,9 +333,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.12.11" } }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/v3-examples/inference-examples/jumpstart-e2e-training-example.ipynb b/v3-examples/inference-examples/jumpstart-e2e-training-example.ipynb index 6877772e5f..dc5af25436 100644 --- a/v3-examples/inference-examples/jumpstart-e2e-training-example.ipynb +++ b/v3-examples/inference-examples/jumpstart-e2e-training-example.ipynb @@ -9,6 +9,14 @@ "This notebook demonstrates how to use SageMaker V3 to train a JumpStart model from scratch and deploy it for inference." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Prerequisites\n", + "Note: Ensure you have sagemaker and ipywidgets installed in your environment. The ipywidgets package is required to monitor endpoint deployment progress in Jupyter notebooks.\n" + ] + }, { "cell_type": "code", "execution_count": null, @@ -41,7 +49,7 @@ "outputs": [], "source": [ "# Configuration\n", - "MODEL_ID = \"huggingface-llm-falcon-7b-bf16\"\n", + "MODEL_ID = \"huggingface-spc-bert-base-cased\"\n", "MODEL_NAME_PREFIX = \"js-e2e-example-model\"\n", "ENDPOINT_NAME_PREFIX = \"js-e2e-example-endpoint\"\n", "\n", @@ -62,7 +70,7 @@ "source": [ "## Step 2: Train the Model\n", "\n", - "Use ModelTrainer to train the JumpStart model. This step will take significant time." + "Use ModelTrainer to train the JumpStart model. The training job may take 30+ minutes to complete." ] }, { @@ -75,11 +83,15 @@ "jumpstart_config = JumpStartConfig(model_id=MODEL_ID)\n", "\n", "# Initialize ModelTrainer from JumpStart config\n", - "model_trainer = ModelTrainer.from_jumpstart_config(jumpstart_config=jumpstart_config)\n", + "model_trainer = ModelTrainer.from_jumpstart_config(\n", + " jumpstart_config=jumpstart_config, \n", + " base_job_name=training_job_name, \n", + " hyperparameters={\"epochs\": 1}\n", + ")\n", "\n", "# Train the model\n", "print(\"Starting model training...\")\n", - "model_trainer.train(training_job_name=training_job_name)\n", + "model_trainer.train()\n", "print(f\"Training completed: {training_job_name}\")" ] }, @@ -99,9 +111,10 @@ "outputs": [], "source": [ "# Build ModelBuilder from trained model\n", - "print(\"Building model from training artifacts...\")\n", - "model_builder = model_trainer.build()\n", - "print(\"ModelBuilder created successfully from training artifacts!\")" + "model_builder = ModelBuilder(\n", + " model=model_trainer,\n", + " dependencies={\"auto\": False}\n", + ")" ] }, { @@ -150,7 +163,9 @@ "source": [ "## Step 6: Test the Endpoint\n", "\n", - "Send a test request to the deployed endpoint." + "This endpoint performs text entailment classification, determining the logical relationship between pairs of sentences. The returned scores indicate the model's confidence for different entailment categories (e.g., entailment, contradiction, neutral) - higher scores indicate stronger predictions for each relationship type. \n", + "\n", + "This sends a test request to the deployed endpoint." ] }, { @@ -160,16 +175,15 @@ "outputs": [], "source": [ "# Test with a sample query for the trained model\n", - "test_data = {\"inputs\": \"What are falcons?\", \"parameters\": {\"max_new_tokens\": 32}}\n", + "test_data = [\"The weather is sunny today\", \"It is not raining\"]\n", "\n", "result = core_endpoint.invoke(\n", " body=json.dumps(test_data),\n", - " content_type=\"application/json\"\n", + " content_type=\"application/list-text\"\n", ")\n", "\n", - "# Decode the output of the invocation and print the result\n", - "prediction = json.loads(result.body.read().decode('utf-8'))\n", - "print(f\"Result of invoking trained endpoint: {prediction}\")" + "entailment_scores = json.loads(result.body.read().decode('utf-8'))\n", + "print(f\"Result of invoking trained endpoint: {entailment_scores}\")\n" ] }, { @@ -218,7 +232,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "venv-test", "language": "python", "name": "python3" }, @@ -232,7 +246,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.12.11" } }, "nbformat": 4, diff --git a/v3-examples/inference-examples/jumpstart-example.ipynb b/v3-examples/inference-examples/jumpstart-example.ipynb index a5cfbbfd40..22f1d0df79 100644 --- a/v3-examples/inference-examples/jumpstart-example.ipynb +++ b/v3-examples/inference-examples/jumpstart-example.ipynb @@ -9,6 +9,14 @@ "This notebook demonstrates how to use SageMaker V3 ModelBuilder with JumpStart models for easy model deployment and inference." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Prerequisites\n", + "Note: Ensure you have sagemaker and ipywidgets installed in your environment. The ipywidgets package is required to monitor endpoint deployment progress in Jupyter notebooks." + ] + }, { "cell_type": "code", "execution_count": null, @@ -21,7 +29,8 @@ "\n", "from sagemaker.serve.model_builder import ModelBuilder\n", "from sagemaker.core.jumpstart.configs import JumpStartConfig\n", - "from sagemaker.core.resources import EndpointConfig" + "from sagemaker.core.resources import EndpointConfig\n", + "from sagemaker.train.configs import Compute" ] }, { @@ -69,8 +78,9 @@ "outputs": [], "source": [ "# Initialize model_builder object with JumpStart configuration\n", + "compute = Compute(instance_type=\"ml.g5.2xlarge\")\n", "jumpstart_config = JumpStartConfig(model_id=MODEL_ID)\n", - "model_builder = ModelBuilder.from_jumpstart_config(jumpstart_config=jumpstart_config)\n", + "model_builder = ModelBuilder.from_jumpstart_config(jumpstart_config=jumpstart_config, compute=compute)\n", "\n", "print(\"ModelBuilder created successfully from JumpStart config!\")" ] @@ -188,7 +198,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "venv-test", "language": "python", "name": "python3" }, @@ -202,7 +212,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.12.11" } }, "nbformat": 4, diff --git a/v3-examples/inference-examples/local-mode-example.ipynb b/v3-examples/inference-examples/local-mode-example.ipynb index d848ebad67..45f4de02e6 100644 --- a/v3-examples/inference-examples/local-mode-example.ipynb +++ b/v3-examples/inference-examples/local-mode-example.ipynb @@ -31,6 +31,19 @@ "from sagemaker.serve.mode.function_pointers import Mode" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# NOTE: Local mode requires Docker to be installed and running. \n", + "# If Docker is not in your system PATH, you may need to define the Docker path in one of the top cells.\n", + "# Here is an example:\n", + "import os\n", + "os.environ['PATH'] = '/usr/local/bin:/Applications/Docker.app/Contents/Resources/bin:' + os.environ['PATH']" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -217,7 +230,7 @@ "source": [ "## Step 6: Deploy in Local Container\n", "\n", - "Deploy the model in a local Docker container. This may take a few minutes to pull the container image." + "Deploy the model in a local Docker container. This may take a few minutes to pull the container image and ping the container until it is live. This is a normal part of the deployment process." ] }, { @@ -395,7 +408,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "venv-test", "language": "python", "name": "python3" }, @@ -409,9 +422,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.12.11" } }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/v3-examples/inference-examples/optimize-example.ipynb b/v3-examples/inference-examples/optimize-example.ipynb index 2ef1b0af1d..4ad4f3b513 100644 --- a/v3-examples/inference-examples/optimize-example.ipynb +++ b/v3-examples/inference-examples/optimize-example.ipynb @@ -9,6 +9,14 @@ "This notebook demonstrates how to use SageMaker V3 ModelBuilder to optimize a JumpStart model for improved inference performance." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Prerequisites\n", + "Note: Ensure you have sagemaker and ipywidgets installed in your environment. The ipywidgets package is required to monitor endpoint deployment progress in Jupyter notebooks." + ] + }, { "cell_type": "code", "execution_count": null, @@ -124,7 +132,6 @@ " model=MODEL_ID,\n", " schema_builder=schema_builder,\n", " sagemaker_session=sagemaker_session,\n", - " model_name=model_name,\n", ")\n", "print(\"ModelBuilder created successfully!\")" ] @@ -135,7 +142,7 @@ "source": [ "## Step 5: Optimize the Model\n", "\n", - "Optimize the model using AWQ quantization for improved inference performance." + "Optimize the model using AWQ quantization for improved inference performance. This step may take up to 30 minutes to complete!" ] }, { @@ -152,7 +159,8 @@ " output_path=f\"s3://sagemaker-us-east-2-593793038179/optimize-output/jumpstart-{unique_id}/\",\n", " quantization_config={\"OverrideEnvironment\": {\"OPTION_QUANTIZE\": \"awq\"}},\n", " accept_eula=True,\n", - " job_name=job_name\n", + " job_name=job_name,\n", + " model_name=model_name,\n", ")\n", "print(f\"Model Successfully Optimized: {optimized_model.model_name}\")" ] @@ -257,7 +265,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "venv-test", "language": "python", "name": "python3" }, @@ -271,7 +279,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.12.11" } }, "nbformat": 4, diff --git a/v3-examples/inference-examples/train-inference-e2e-example.ipynb b/v3-examples/inference-examples/train-inference-e2e-example.ipynb index 9959928df1..b0f62e8293 100644 --- a/v3-examples/inference-examples/train-inference-e2e-example.ipynb +++ b/v3-examples/inference-examples/train-inference-e2e-example.ipynb @@ -9,6 +9,14 @@ "This notebook demonstrates the complete end-to-end workflow from training a custom PyTorch model to deploying it for inference using SageMaker V3." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Prerequisites\n", + "Note: Ensure you have sagemaker and ipywidgets installed in your environment. The ipywidgets package is required to monitor endpoint deployment progress in Jupyter notebooks." + ] + }, { "cell_type": "code", "execution_count": null, @@ -382,7 +390,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "venv-test", "language": "python", "name": "python3" }, @@ -396,9 +404,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.12.11" } }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +}