Package: sagemaker
SageMaker Python SDKSageMaker Python SDK is an open source library for training and deploying machine learning models on Amazon SageMaker.With the SDK, you can train and deploy models using popular deep learning frameworksApache MXNetandTensorFlow.
You can also train and deploy models withAmazon algorithms,
which are scalable implementations of core machine learning algorithms that are optimized for SageMaker and GPU training.
If you haveyour own algorithmsbuilt into SageMaker compatible Docker containers, you can train and host models using these as well.For detailed documentation, including the API reference, seeRead the Docs.Table of ContentsInstalling SageMaker Python SDKUsing the SageMaker Python SDKUsing MXNetUsing TensorFlowUsing ChainerUsing PyTorchUsing Scikit-learnUsing XGBoostSageMaker Reinforcement Learning EstimatorsSageMaker SparkML ServingAmazon SageMaker Built-in Algorithm EstimatorsUsing SageMaker AlgorithmEstimatorsConsuming SageMaker Model PackagesBYO Docker Containers with SageMaker EstimatorsSageMaker Automatic Model TuningSageMaker Batch TransformSecure Training and Inference with VPCBYO ModelInference PipelinesAmazon SageMaker Operators in Apache AirflowSageMaker AutopilotModel MonitoringSageMaker DebuggerSageMaker ProcessingInstalling the SageMaker Python SDKThe SageMaker Python SDK is built to PyPI and can be installed with pip as follows:pip install sagemakerYou can install from source by cloning this repository and running a pip install command in the root directory of the repository:git clone https://github.com/aws/sagemaker-python-sdk.git
cd sagemaker-python-sdk
pip install .Supported Operating SystemsSageMaker Python SDK supports Unix/Linux and Mac.Supported Python VersionsSageMaker Python SDK is tested on:Python 3.8Python 3.9Python 3.10AWS PermissionsAs a managed service, Amazon SageMaker performs operations on your behalf on the AWS hardware that is managed by Amazon SageMaker.
Amazon SageMaker can perform only operations that the user permits.
You can read more about which permissions are necessary in theAWS Documentation.The SageMaker Python SDK should not require any additional permissions aside from what is required for using SageMaker.
However, if you are using an IAM role with a path in it, you should grant permission foriam:GetRole.LicensingSageMaker Python SDK is licensed under the Apache 2.0 License. It is copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. The license is available at:http://aws.amazon.com/apache2.0/Running testsSageMaker Python SDK has unit tests and integration tests.You can install the libraries needed to run the tests by runningpip install --upgrade .[test]or, for Zsh users:pip install --upgrade .\[test\]Unit testsWe run unit tests with tox, which is a program that lets you run unit tests for multiple Python versions, and also make sure the
code fits our style guidelines. We run tox withall of our supported Python versions, so to run unit tests
with the same configuration we do, you need to have interpreters for those Python versions installed.To run the unit tests with tox, run:tox tests/unitIntegration testsTo run the integration tests, the following prerequisites must be metAWS account credentials are available in the environment for the boto3 client to use.The AWS account has an IAM role namedSageMakerRole.
It should have the AmazonSageMakerFullAccess policy attached as well as a policy withthe necessary permissions to use Elastic Inference.To run remote_function tests, dummy ecr repo should be created. It can be created by running -aws ecr create-repository --repository-name remote-function-dummy-containerWe recommend selectively running just those integration tests you’d like to run. You can filter by individual test function names with:tox -- -k 'test_i_care_about'You can also run all of the integration tests by running the following command, which runs them in sequence, which may take a while:tox -- tests/integYou can also run them in parallel:tox -- -n auto tests/integGit Hooksto enable all git hooks in the .githooks directory, run these commands in the repository directory:find .git/hooks -type l -exec rm {} \;
find .githooks -type f -exec ln -sf ../../{} .git/hooks/ \;To enable an individual git hook, simply move it from the .githooks/ directory to the .git/hooks/ directory.Building Sphinx docsSetup a Python environment, and install the dependencies listed indoc/requirements.txt:# conda
conda create -n sagemaker python=3.7
conda activate sagemaker
conda install sphinx=3.1.1 sphinx_rtd_theme=0.5.0

# pip
pip install -r doc/requirements.txtClone/fork the repo, and install your local version:pip install --upgrade .Thencdinto thesagemaker-python-sdk/docdirectory and run:make htmlYou can edit the templates for any of the pages in the docs by editing the .rst files in thedocdirectory and then runningmake htmlagain.Preview the site with a Python web server:cd _build/html
python -m http.server 8000View the website by visitinghttp://localhost:8000SageMaker SparkML ServingWith SageMaker SparkML Serving, you can now perform predictions against a SparkML Model in SageMaker.
In order to host a SparkML model in SageMaker, it should be serialized withMLeaplibrary.For more information on MLeap, seehttps://github.com/combust/mleap.Supported major version of Spark: 3.3 (MLeap version - 0.20.0)Here is an example on how to create an instance ofSparkMLModelclass and usedeploy()method to create an
endpoint which can be used to perform prediction against your trained SparkML Model.sparkml_model=SparkMLModel(model_data='s3://path/to/model.tar.gz',env={'SAGEMAKER_SPARKML_SCHEMA':schema})model_name='sparkml-model'endpoint_name='sparkml-endpoint'predictor=sparkml_model.deploy(initial_instance_count=1,instance_type='ml.c4.xlarge',endpoint_name=endpoint_name)Once the model is deployed, we can invoke the endpoint with aCSVpayload like this:payload='field_1,field_2,field_3,field_4,field_5'predictor.predict(payload)For more information about the differentcontent-typeandAcceptformats as well as the structure of theschemathat SageMaker SparkML Serving recognizes, please seeSageMaker SparkML Serving Container.