{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Upgrade Your SageMaker Python SDK Notebooks\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "This notebook's CI test result for us-west-2 is as follows. CI test results in other regions can be found at the end of the notebook. \n", "\n", "![This us-west-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/us-west-2/sagemaker-python-sdk|upgrade_to_v2|upgrade_to_v2.ipynb)\n", "\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "Versions 2.0 and higher of the SageMaker Python SDK introduced some changes that may require changes in your own code when upgrading. This notebook serves as a helper for upgrading your code.\n", "\n", "For more information, including what changes were made, see [the documentation](https://sagemaker.readthedocs.io/en/stable/v2.html)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Install the latest `sagemaker` version\n", "\n", "Make sure you select the kernel that you normally use before pip installing the latest version of `sagemaker`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!pip install --upgrade \"sagemaker>=2\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "***IMPORTANT***: Now restart your kernel so that it picks up the updated `sagemaker` version." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Use the migration tool\n", "\n", "Upgrading `sagemaker` also installs a CLI tool to aid with updating your code. \n", "\n", "There are limitations with what the tool can handle: https://sagemaker.readthedocs.io/en/stable/v2.html#limitations. In these cases, you need to manually update your code." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set the base path for where to look for notebooks. The code below points to the base Jupyter home directory on a SageMaker Notebook Instance. If you are using SageMaker Studio, uncomment the second line.\n", "\n", "Modify the path as necessary so that it points to your notebooks." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "path = \"/home/ec2-user/SageMaker\"\n", "path = \"/root\"\n", "\n", "print(path)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a temporary directory for the upgraded files. This is just to err on the safe side - you can also overwrite your existing files directly." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "output_path = os.path.join(path, \"sagemaker-sdk-v2\")\n", "!mkdir {output_path}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now use the `sagemaker-upgrade-v2` tool to upgrade your notebooks. The following code runs it for all notebooks found in the given path." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import glob\n", "\n", "for file in glob.glob(\"**/*.ipynb\", recursive=True):\n", " !sagemaker-upgrade-v2 --in-file {file} --out-file {output_path}/{file}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "At this point, you may want to manually verify some notebooks and see what changes were made." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When you are satisfied, you can copy them back to the original path:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!cp -r {output_path}/* {path}/." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Cleanup\n", "\n", "Finally, remove the temporary directory created earlier." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!rm -r {output_path}" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Notebook CI Test Results\n", "\n", "This notebook was tested in multiple regions. The test results are as follows, except for us-west-2 which is shown at the top of the notebook.\n", "\n", "![This us-east-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/us-east-1/sagemaker-python-sdk|upgrade_to_v2|upgrade_to_v2.ipynb)\n", "\n", "![This us-east-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/us-east-2/sagemaker-python-sdk|upgrade_to_v2|upgrade_to_v2.ipynb)\n", "\n", "![This us-west-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/us-west-1/sagemaker-python-sdk|upgrade_to_v2|upgrade_to_v2.ipynb)\n", "\n", "![This ca-central-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/ca-central-1/sagemaker-python-sdk|upgrade_to_v2|upgrade_to_v2.ipynb)\n", "\n", "![This sa-east-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/sa-east-1/sagemaker-python-sdk|upgrade_to_v2|upgrade_to_v2.ipynb)\n", "\n", "![This eu-west-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/eu-west-1/sagemaker-python-sdk|upgrade_to_v2|upgrade_to_v2.ipynb)\n", "\n", "![This eu-west-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/eu-west-2/sagemaker-python-sdk|upgrade_to_v2|upgrade_to_v2.ipynb)\n", "\n", "![This eu-west-3 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/eu-west-3/sagemaker-python-sdk|upgrade_to_v2|upgrade_to_v2.ipynb)\n", "\n", "![This eu-central-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/eu-central-1/sagemaker-python-sdk|upgrade_to_v2|upgrade_to_v2.ipynb)\n", "\n", "![This eu-north-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/eu-north-1/sagemaker-python-sdk|upgrade_to_v2|upgrade_to_v2.ipynb)\n", "\n", "![This ap-southeast-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/ap-southeast-1/sagemaker-python-sdk|upgrade_to_v2|upgrade_to_v2.ipynb)\n", "\n", "![This ap-southeast-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/ap-southeast-2/sagemaker-python-sdk|upgrade_to_v2|upgrade_to_v2.ipynb)\n", "\n", "![This ap-northeast-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/ap-northeast-1/sagemaker-python-sdk|upgrade_to_v2|upgrade_to_v2.ipynb)\n", "\n", "![This ap-northeast-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/ap-northeast-2/sagemaker-python-sdk|upgrade_to_v2|upgrade_to_v2.ipynb)\n", "\n", "![This ap-south-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/ap-south-1/sagemaker-python-sdk|upgrade_to_v2|upgrade_to_v2.ipynb)\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (Data Science 3.0)", "language": "python", "name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-east-1:081325390199:image/sagemaker-data-science-310-v1" }, "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.6" }, "notice": "Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the \"License\"). You may not use this file except in compliance with the License. A copy of the License is located at http://aws.amazon.com/apache2.0/ or in the \"license\" file accompanying this file. This file is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License." }, "nbformat": 4, "nbformat_minor": 2 }