Package: sagemaker-tensorflow
This package contains SageMaker-specific extensions to TensorFlow, including thePipeModeDatasetclass, that allows SageMaker Pipe Mode channels to be read using TensorFlow Datasets.This package supports Python 3.9-3.10 and TensorFlow versions 1.7 and higher, including 2.0-2.14.0.
For TensorFlow 1.x support, see themaster branch.sagemaker-tensorflowreleases for all supported versions are available onPyPI.InstallYou can build SageMaker TensorFlow into a docker image with the following command:pip install sagemaker-tensorflowYou can also install sagemaker-tensorflow for a specific version of TensorFlow. The following command will install sagemaker-tensorflow for TensorFlow 1.7:pip install "sagemaker-tensorflow>=2.0,<2.1"Build and install from sourceThe SageMaker TensorFlow build depends on the following:cmaketensorflowcurl-devTo install these run:pip install cmake tensorflowOn Amazon Linux, curl-dev can be installed with:yum install curl-devOn Ubuntu, curl-dev can be installed with:apt-get install libcurl4-openssl-devTo build and install this package, run:pip install .in this directory.To build in a SageMaker docker image, you can use the following RUN command in your Dockerfile:RUN git clone https://github.com/aws/sagemaker-tensorflow-extensions.git && \
    cd sagemaker-tensorflow-extensions && \
    pip install . && \
    cd .. && \
    rm -rf sagemaker-tensorflow-extensionsBuilding for a specific TensorFlow versionRelease branching is used to track different versions of TensorFlow. To build for a specific release of TensorFlow, checkout the release branch prior to running a pip install. For example, to build for TensorFlow 1.7, you can run the following command in your Dockerfile:RUN git clone https://github.com/aws/sagemaker-tensorflow-extensions.git && \
    cd sagemaker-tensorflow-extensions && \
    git checkout 1.7 && \
    pip install . && \
    cd .. && \
    rm -rf sagemaker-tensorflow-extensionsRequirementsSageMaker TensorFlow extensions builds on Python 3.4-3.10 in Linux with a TensorFlow version >= 1.7. Older versions of TensorFlow are not supported. Please make sure to checkout the branch of sagemaker-tensorflow-extensions that matches your TensorFlow version.Please refer to below table for release support information:Sagemaker TensorFlow Extensions Release InformationSagemaker TensorFlow Extensions PyPI VersionSagemaker TensorFlow Extensions Release VersionTensorFlow Release VersionSagemaker TensorFlow Extentions Supported Python Versions2.14.0.1.20.xv1.20.x2.14.03.9, 3.102.13.0.1.19.xv1.19.x2.13.03.8, 3.9, 3.102.12.0.1.18.xv1.18.x2.12.03.8, 3.9, 3.102.11.0.1.17.xv1.17.x2.11.03.7, 3.8, 3.9, 3.102.10.0.1.16.xv1.16.x2.10.03.7, 3.8, 3.92.9.1.1.15.xv1.15.x2.9.13.7, 3.8, 3.92.8.0.1.14.xv1.14.x2.8.03.7, 3.8, 3.92.8.0.1.13.xv1.13.x2.8.03.7, 3.82.7.1.1.12.xv1.12.x2.7.13.7, 3.82.6.0.1.11.0v1.11.x2.6.03.6, 3.7, 3.82.5.0.1.9.0v1.9.x2.5.03.6, 3.72.4.1.1.8.0v1.8.x2.4.13.6, 3.72.3.0.1.6.1v1.6.x2.3.03.6, 3.72.2.0.1.0.0v1.5.02.22.7, 3.6, 3.72.1.0.1.0.0v1.4.02.12.7, 3.62.0.0.1.0.0v1.2.12.02.7, 3.61.15.0.1.0.0v0.2.01.152.7, 3.61.14.0.1.0.0v0.1.01.14, 1.132.7, 3.6SageMaker Pipe ModeSageMaker Pipe Mode is a mechanism for providing S3 data to a training job via Linux fifos. Training programs can read from the fifo and get high-throughput data transfer from S3, without managing the S3 access in the program itself.SageMaker Pipe Mode is enabled when a SageMaker training job is created. Multiple S3 datasets can be mapped to individual fifos, configured in the training request. Pipe Mode is covered in more detail in the SageMaker documentation:https://docs.aws.amazon.com/sagemaker/latest/dg/your-algorithms-training-algo.html#your-algorithms-training-algo-running-container-inputdataconfigUsing the PipeModeDatasetThePipeModeDatasetis a TensorFlowDatasetfor reading SageMaker Pipe Mode channels. After installing this package, thePipeModeDatasetcan be imported from a moduled namedsagemaker_tensorflow.To construct aPipeModeDatasetthat reads TFRecord encoded records from a “training” channel, do the following:fromsagemaker_tensorflowimportPipeModeDatasetds=PipeModeDataset(channel='training',record_format='TFRecord')APipeModeDatasetshould be created for a SageMaker Pipe Mode channel. Each channel corresponds to a single S3 dataset, configured when the training job is created. You can create multiplePipeModeDatasetinstances over different channels to read from multiple S3 datasets in the same training job.APipeModeDatasetcan read TFRecord, RecordIO, or text line records, by using therecord_formatconstructor argument.  Therecord_formatkeyword argument can be set to eitherRecordIO,TFRecord, orTextLineto differentiate between the three encodings.RecordIOis the default.APipeModeDatasetis a regular TensorFlowDatasetand as such can be used in TensorFlow input processing pipelines, and in TensorFlow Estimatorinput_fndefinitions. AllDatasetoperations are supported onPipeModeDataset. The following code snippet shows how to create a batching and parsingDatasetthat reads data from a SageMaker Pipe Mode channel:features={'data':tf.FixedLenFeature([],tf.string),'labels':tf.FixedLenFeature([],tf.int64),}defparse(record):parsed=tf.parse_single_example(record,features)return({'data':tf.decode_raw(parsed['data'],tf.float64)},parsed['labels'])ds=PipeModeDataset(channel='training',record_format='TFRecord')num_epochs=20ds=ds.repeat(num_epochs)ds=ds.prefetch(10)ds=ds.map(parse,num_parallel_calls=10)ds=ds.batch(64)Using the PipeModeDataset with the SageMaker Python SDKThesagemaker_tensorflowmodule is available for TensorFlow scripts to import when launched on SageMaker via the SageMaker Python SDK. If you are using the SageMaker Python SDKTensorFlowEstimator to launch TensorFlow training on SageMaker, note that the default channel name istrainingwhen just a single S3 URI is passed tofit.Using the PipeModeDataset with SageMaker Augmented Manifest FilesSageMaker Augmented Manifest Files provide a mechanism to associate metdata (such as labels) with binary data (like images) for training. An Augmented Manifest File is a single json-lines file, stored as an object in S3. During training, SageMaker reads the data from an Augmented Manifest File and passes the data to the running training job, through a SageMaker Pipe Mode channel.To learn more about preparing and using an Augmented Manifest File, please consult the SageMaker documentation on Augmented Manifest Fileshere.You can use the PipeModeDataset to read data from a Pipe Mode channel that is backed by an Augmented Manifest, by following these guidelines:First, use a Datasetbatchoperation to combine successive records into a single tuple. Each attribute in an Augmented Manifest File record is queued into the Pipe Mode’s fifo as a separate record. By batching, you can combine these successive per-attribute records into a single per-record tuple. In general, if your Augmented Manifest File contains n attributes, then you should issue a call tobatch(n)on your PipeModeDataset and then use a simple combining function applied with amapto combine each per-attribute record in the batch into a single tuple. For example, assume your Augmented Manifest File contains 3 attributes, the following code sample will read Augmented Manifest records into a 3-tuple of string Tensors when applied to a PipeModeDataset.ds=PipeModeDataset("my_channel")defcombine(records):return(records[0],records[1],records[2])ds=ds.batch(3)# Batch series of three attributes together.ds=ds.map(combine)# Convert each batch of three records into a single tuple with three Tensors.# Perform other operations on the Dataset - e.g. subsequent batching, decoding...Second, pass"RecordIO"as the value forRecordWrapperTypewhen you launch the SageMaker training job with an Augmented Manifest File. Doing this will cause SageMaker to wrap each per-attribute record in a RecordIO wrapper, enabling the PipeModeDataset to separate these records.Third, ensure your PipeModeDataset splits records using RecordIO decoding in your training script. You can do this by simply constructing the PipeModeDataset with norecord_formatargument, as RecordIO is the default record wrapping type for the PipeModeDataset.If you follow these steps then the PipeModeDataset will produce tuples of string Tensors that you can then decode or process further (for example, by doing a jpeg decode if your data are images).Release SageMaker TensorFlow ExtensionsTo release the package, please follow the below steps:Make your changes and run the test in CodeBuild docker container.If you are bumping TensorFlow version, please make sure you bump the versions increate_integ_test_docker_images.py,tox.iniandbuildspec-release.yml. Please drop the Python versions that the new TensorFlow version no longer supports.If you are adding new Python version, please make sure the new Python version is installed in the CodeBuild docker container. Add the new Python version to tox environment and update the tox commands inbuildspec.ymlandbuildspec-release.yml.If any Python versions are dropped or added, please make sure you update theclassifiersinsetup.py.Before starting the release process, you will need to manually bump the package version insetup.py.SupportWe’re here to help. Have a question? Please open aGitHub issue, we’d love to hear from you.LicenseSageMaker TensorFlow is licensed under the Apache 2.0 License. It is copyright 2018
Amazon.com, Inc. or its affiliates. All Rights Reserved. The license is available at:http://aws.amazon.com/apache2.0/