Skip to content

Instantly share code, notes, and snippets.

@aaronpolhamus
Created April 11, 2019 13:47
Show Gist options
  • Save aaronpolhamus/ae13b4a0f5e9c6956cc2648b3f12a527 to your computer and use it in GitHub Desktop.
Save aaronpolhamus/ae13b4a0f5e9c6956cc2648b3f12a527 to your computer and use it in GitHub Desktop.
# [1] Docker installation: https://docs.docker.com/install/linux/docker-ce/fedora/
# [2] Docker compose: https://github.com/Yelp/docker-compose/blob/master/docs/install.md
# [3] NVIDIA docker installation: https://github.com/NVIDIA/nvidia-docker/issues/553#issuecomment-381075335
# [4] Tensorflow docker installation: https://www.tensorflow.org/install/docker
# [1] install dnf-plugins-core
sudo dnf -y install dnf-plugins-core
# [1] setup stable repository
sudo dnf config-manager \
--add-repo \
https://download.docker.com/linux/fedora/docker-ce.repo
# [1] install latest version of docker CE
sudo dnf install docker-ce
# [1] start docker
sudo systemctl start docker
# [2] get latest docker compose release and test
sudo curl -L https://github.com/docker/compose/releases/download/1.24.0-rc1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
# [3] Install NVIDIA docker and verify installation
sudo curl -s -L https://nvidia.github.io/nvidia-docker/centos7/nvidia-docker.repo | \
sudo tee /etc/yum.repos.d/nvidia-docker.repo
sudo dnf install nvidia-docker2
sudo pkill -SIGHUP dockerd
sudo docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi
# [4] Install GPU-enabled TensorFlow image
sudo docker run --runtime=nvidia -it --rm tensorflow/tensorflow:latest-gpu-py3 \
python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
# [4] Enter the bash shell of the image
sudo docker run --runtime=nvidia -it tensorflow/tensorflow:latest-gpu-py3 bash
# From within docker, run:
pip install jupyter
jupyter notebook --ip=0.0.0.0 --port=8888 --allow-root
# Check docker container name with
sudo docker ps
# Identify docker container IP address with
sudo docker inspect [docker container name] | grep "IPAddress"
# Paste in link to notebook from terminal with updated IP address, e.g.:
http://172.17.0.2:8888/?token=[TOKEN]
# Start a new notebook and paste in the MNIST test from https://www.tensorflow.org/tutorials
import tensorflow as tf
mnist = tf.keras.datasets.mnist
(x_train, y_train),(x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(512, activation=tf.nn.relu),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10, activation=tf.nn.softmax)
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test)
# Remember that you can follow GPU utilization with :
nvidia-smi -l 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment