The number of virtual CPUs and the storage have little effect on cost. However prices increase dramatically with GPUs
- n1-standard-8: 8 virtual CPUs and 30 GB of memory.
- count=4,2,1: # of GPUs
- boot-disk-size: 200GB
If creating from a snapshot you must first create the disk
gcloud compute disks create DISK_NAME --source-snapshot SNAPSHOT_NAME
and then add the --disk name option to the scripts below
--disk name=[DISK_NAME],boot=yes
Note you must also remove boot-disk-size since that is determined by snapshot. The CPU script below shows an example of creating from a snapshot.
gcloud beta compute instances create gpu-84 \
--machine-type n1-standard-8 --zone us-east1-d \
--accelerator type=nvidia-tesla-k80,count=4 \
--image-family ubuntu-1604-lts --image-project ubuntu-os-cloud \
--maintenance-policy TERMINATE --restart-on-failure \
--boot-disk-size 200GB
gcloud beta compute instances create gpu-82 \
--machine-type n1-standard-8 --zone us-east1-d \
--accelerator type=nvidia-tesla-k80,count=2 \
--image-family ubuntu-1604-lts --image-project ubuntu-os-cloud \
--maintenance-policy TERMINATE --restart-on-failure \
--boot-disk-size 200GB
gcloud beta compute instances create gpu-81 \
--machine-type n1-standard-8 --zone us-east1-d \
--accelerator type=nvidia-tesla-k80,count=1 \
--image-family ubuntu-1604-lts --image-project ubuntu-os-cloud \
--maintenance-policy TERMINATE --restart-on-failure \
--boot-disk-size 200GB
NOTE: This script boots from a GPU disk snapshot. Note that after creating the instance you'll then need to remove the gpu dependencies.
# create disk from gpu-84
gcloud compute disks create cpu8source --source-snapshot gpu-84-20170428
# create instance
gcloud compute instances create cpu-8 \
--machine-type n1-standard-8 --zone us-east1-d \
--disk name=cpu8source,boot=yes \
--image-family ubuntu-1604-lts --image-project ubuntu-os-cloud \
--maintenance-policy TERMINATE --restart-on-failure
# remove cuda
rm -rf ~/cuda
rm -rf NVIDIA_CUDA-8.0_Samples
sudo rm -rf /usr/local/cuda
conda uninstall cuda80
# tensorflow
TF=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.1.0-cp36-cp36m-linux_x86_64.whl
pip install --ignore-installed --upgrade $TF
# theano:
# - update .theanorc
# -- update [global]
device = cpu
# --remove [cuda]
# .bashrc -- remove from PATH
# export CUDA_HOME=/usr/local/cuda-8.0
# export LD_LIBRARY_PATH=$CUDA_HOME/lib64
# PATH=$CUDA_HOME/bin:$PATH
# export PATH
# copy files to instance
gcloud compute copy-files gpu-setup.sh gpu-84:~/
# INSTALL PIP
sudo apt-get install python-pip
# ssh into instance and execute < **anaconda install is interactive ** >
. gpu-setup.sh
Locally download cudnn https://developer.nvidia.com/rdp/cudnn-download. Then upload contents to instance. I first tried to upload the tar file but there was an error when unpackaging, so I uploaded the untarred directory:
# glcoud instance
cuda-install-samples-8.0.sh ~
mkdir ~/cuda
# local machine
gcloud compute copy-files ~/Downloads/cuda/* gpu-84:~/cuda
Now move the files to the appropriate /usr/local/cuda
locations:
sudo mv cuda/lib64/* /usr/local/cuda/lib64/
sudo mv cuda/include/* /usr/local/cuda/include/
# check cuda install
pushd NVIDIA_CUDA-8.0_Samples/1_Utilities/deviceQuery
make
./deviceQuery
popd
# check TF install
python -c "import tensorflow as tf;print(tf.Session().run(tf.constant('Hi TF')))"
- reserve a static ip GCloud-Console > Networking > External IP
- add a firewall rule GCloud-Console > Networking > Firewall Rules:
- (source ip-ranges) 0.0.0.0/0
- (protocols and ports) tcp:8800-8900
- do not delete disk when deleted
# set password *** copy sha output ***
from notebook.auth import passwd
passwd()
jupyter notebook --generate-config
vi ~/.jupyter/jupyter_notebook_config.py
# uncomment/update line
# c.NotebookApp.password = 'sha1...'
# full cmd
jupyter notebook --ip=0.0.0.0 --port=8888 --no-browser &
# alias in bashrc from gpu-setup.sh
jnb
git config --global credential.helper 'cache --timeout=43200'
https://github.com/brookisme/tmux-setup
...
conda create -y -n py2 python=2 anaconda
sa py2
python -c "print 'i am python 2'"
# tensorflow
TF=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.0.1-cp27-none-linux_x86_64.whl
pip install --ignore-installed --upgrade $TF
# keras 1 ( to be consistent with usf notebooks )
pip install 'keras<2'
# checks
python -c "import keras; import tensorflow as tf;print(tf.Session().run(tf.constant('Hi TF')))"
# other
conda install libgcc
pip install bcolz
NOTE: If you don't reserve a static-ip you are going to have to update the ip-address each time. With new ip's first log in through gcloud cli to accept private key.
# example sftp-config.json
{
"type": "sftp",
"sync_down_on_open": false,
"upload_on_save":true,
"host": "35.185.66.147",
"remote_path": "/home/brook/play/dvc1",
"user": "brook",
"port":22,
"ignore_regexes":[
"/data/","/.kaggle-cli/",
"\\.sublime-(project|workspace)", "sftp-config(-alt\\d?)?\\.json", "sftp-settings\\.json", "/venv/", "\\.svn", "\\.hg", "\\.git", "\\.bzr", "_darcs", "CVS", "\\.DS_Store", "Thumbs\\.db", "desktop\\.ini"],
"connect_timeout": 30,
"ssh_key_file": "~/.ssh/google_compute_engine"
}