Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SageMaker and TensorFlow 2.0

What is the best way to run TensorFlow 2.0 with AWS Sagemeker?

As of today (Aug 7th, 2019) AWS does not provide TensorFlow 2.0 SageMaker containers, so my understanding is that I need to build my own.

What is the best Base image to use? Example Dockerfile?

like image 858
Anton Avatar asked Aug 07 '19 14:08

Anton


4 Answers

Here from the SageMaker team. To use SageMaker seamlessly, it's recommended that you try out Amazon SageMaker Studio. It's similar to a Jupyter Notebook instance but has a variety of SageMaker services already integrated within it. A huge plus point is that you can select from a variety of kernels and for TensorFlow 2.0 you can select any of these that already have all the required packages installed:

Python 3 (TensorFlow 2.1 Python 3.6 CPU Optimized)
Python 3 (TensorFlow 2.1 Python 3.6 GPU Optimized)
Python 3 (TensorFlow 2.3 Python 3.7 CPU Optimized)
Python 3 (TensorFlow 2.3 Python 3.7 GPU Optimized)

In Studio, you can select the Kernel drop-down located in top-right corner of your SageMaker Studio instance: enter image description here

Shown below is a screenshot of the UI interface in SageMaker Studio of the available kernels that are compatible with TensorFlow 2.0. Note that all kernels within SageMaker Studio are continuously tested and work seamlessly with all SageMaker Services. enter image description here

like image 180
Teodorico Levoff Avatar answered Oct 05 '22 08:10

Teodorico Levoff


EDIT: Amazon SageMaker does now support TF 2.0 and higher.

  • SageMaker + TensorFlow docs: https://sagemaker.readthedocs.io/en/stable/frameworks/tensorflow/using_tf.html
  • Supported Tensorflow versions (and Docker URIs): https://aws.amazon.com/releasenotes/available-deep-learning-containers-images

Original answer

Here is an example Dockerfile that uses the underlying SageMaker Containers library (this is what is used in the official pre-built Docker images):

FROM tensorflow/tensorflow:2.0.0b1

RUN pip install sagemaker-containers

# Copies the training code inside the container
COPY train.py /opt/ml/code/train.py

# Defines train.py as script entrypoint
ENV SAGEMAKER_PROGRAM train.py

For more information on this approach, see https://docs.aws.amazon.com/sagemaker/latest/dg/build-container-to-train-script-get-started.html

like image 10
lauren Avatar answered Oct 17 '22 12:10

lauren


Update on 10 nov 2019:

There is now a way to use Tensorflow 2 in SageMaker, event though there is no shortcut to start TF 2 directly from SageMaker console.

  1. Start a conda Python3 Kernel

  2. Make some updates (one in each code cell):

!pip install --upgrade pip         # pip 19.0 or higher is required for TF 2
!pip install --upgrade setuptools  # Otherwise you'll get annoying warnings about bad installs
  1. Install Tensorflow 2
!pip install --user --upgrade tensorflow

Given the doc, this will install in $HOME.

Nota:

If you are using a GPU based instance of SageMaker, replace tensorflow by tensorflow-gpu.

You now can use TF 2 in your instance. This only needs to be done once, as long as the instance remains up.

To test, just run in the next cell:

import tensorflow as tf
print(tf.__version__)

You should see 2.0.0 or higher.

like image 8
htaidirt Avatar answered Oct 17 '22 13:10

htaidirt


As of now, the best image that you can use to build Tensorflow 2.0 is 2.0.0b1, which is the latest version of Tensorflow 2.0(image) that is available now.Please find the link here. You also have an image 2.0.0b1-py3, which comes with Python3 (3.5 for Ubuntu 16-based images; 3.6 for Ubuntu 18-based images).

If you feel this answer is useful, kindly accept this answer and/or up vote it. Thanks.

like image 3
Tensorflow Support Avatar answered Oct 17 '22 13:10

Tensorflow Support