Tensorflow
To be able to use tensorflow you need to install it for your project. We recommend to use uv
for creating your tensorflow python project.
Setup your project
uv
will create and use a python virtual environment transparently so there is no need to create one seperatly. Use the storage on /scratch/userdata/$USER
for your project, this is on the local disk of the ada-Xs as not all have the same python versions so the virtual environment must be recreated for every ada-X.
Initialize the project
export UV_NO_CACHE=1
cd /scratch/userdata/$USER
uv init new-uv-project
Install tensorflow and cuda in the project
cd /scratch/userdata/$USER/new-uv-project
uv add tensorflow[and-cuda]
# if you didn't set UV_NO_CACHE your cache could be big.
uv cache clean
Run your python code
To run you need to use uv
you cannot simply use python as this will not load the virtual environment:
cd /scratch/userdata/$USER/new-uv-project
uv run main.py
- As over time the central clients will have different python versions you need to reinitialize the virtual environment on each client you want to work on.
uv
has the possibility to install the cuda libraries apart from the python code.- Some cuda or tensorflow versions are not compatible with all GPUs here you find the list of GPUs installed in the central clients: https://blogs.ethz.ch/isgdmath/central-clients/
How can I load tensorflow within a Jupyter notebook on ada using https://blogs.ethz.ch/isgdmath/jupyter-notebook-on-compute-clients-ada-x/ ?
Tensorflow has to be installed first.
You can do so with:
pip install --user tensorflow
After that, you can import ‘tensorflow’ in your Python scripts in Jupyter as well as outside of it.