How to use tensorflow on a single node?
I want to use tensorflow on SDIL: what do I have to do?
Designs
- Show closed items
Activity
-
Newest first Oldest first
-
Show all activity Show comments only Show history only
- Till Riedel assigned to @ai5116
assigned to @ai5116
By till.riedel on 2022-05-18T10:47:56 (imported from GitLab)
- Author Owner
The first steps covers the creation of a new virtual environment. Please use the following lines:
python3 -m venv hpc_tensorflow_sn
source hpc_tensorflow_sn/bin/activate
The first lines creates a new virtual environment, the second activates it.
Now you can install Tensorflow via:
pip install --upgrade tensorflow
Let us install Matplotlib as well to run the example:
pip install matplotlib
Install now Jupyter in your virtual environment and add the virtual environment as Jupyter Kernel:
ipython kernel install --name "hpc_tensorflow_sn" --user
You can now run the following code (download: HPC_Tensorflow_SN.ipynb) in Jupyter
import tensorflow as tf image_data = tf.keras.datasets.fashion_mnist
(train_images,train_labels),(test_images,test_labels) = image_data.load_data()
import matplotlib.pyplot as plt plt.imshow(train_images[0]) train_labels[0]
train_images = train_images / 255.0 test_images = test_images / 255.0
model = tf.keras.Sequential([ tf.keras.layers.Flatten(input_shape=(28,28)), tf.keras.layers.Dense(128,activation="relu"), tf.keras.layers.Dense(10) ]) model.compile(optimizer="adam", loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True), metrics=["accuracy"] ) model.fit(train_images,train_labels,epochs=10)
model.predict(test_images)[0]
test_labels[0]
By using NBConvert you can use
jupyter nbconvert --to notebook --execute HPC_Tensorflow_SN.ipynb
to run your Jupyter Notebook on the commandline
Usually the login node doesn´t have a NVIDIA GPU, so you can´t run the notebook but you can gain some ressources for a single run on one node by using:
salloc -p sdil --time=01:00:00 --gres=gpu:1
You specify basically the SDIL partition, wall-time and that you want a GPU.
After granting access to a node you can use the command:
jupyter nbconvert --to notebook --execute HPC_Tensorflow_SN.ipynb
The Jupyter notebook will be executed. There will be a new notebook with executed cells which you can investigate. To run it on slurm see #51
By rainer.duda on 2022-06-01T16:22:13 (imported from GitLab)
Edited by Till Riedel - Till Riedel added answered label
added answered label
- Till Riedel changed the description
changed the description
By till.riedel on 2022-06-01T16:25:57 (imported from GitLab)
- Till Riedel added rookie woes label
added rookie woes label
- Till Riedel unassigned @till.riedel
unassigned @till.riedel