- TensorFlow
- tensorflow-2.18.0 -> Ptython version 3.9-3.12 -> cuDNN 9.3-> CUDA 12.5
- install all of them with yay and that's it
- Details -> https://www.tensorflow.org/install/source#sample_session
- A python version manager https://github.com/pyenv/pyenv
- So you can install and manage multiple python versions like nvm or
sdkman
- ### Using Nvidia GPU on a jupyter lab
- Make sure you installed nvidia drivers, nvidia cuda toolkit, cuDNN
and a compatible version of python.
- Configure the necessary environment variables
collapsed:: true
-
```shell
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/opt/cuda/nvvm/lib64:$LD_LIBRARY_PATH
export XLA_FLAGS=--xla_gpu_cuda_data_dir=/opt/cuda
```
- in my case cuda was installed on `/opt/cuda`
- Using [pyenv](ttps://github.com/pyenv/pyenv) to make sure you're
using the [right version](https://www.tensorflow.org/install/source#sample_session)
for your cuda version
- in your root project dir execute `pyenv local 3.12`
- Now create a new python virtual environment with `python -m venv
my_notebook_env`
- Activate the virtual env with `source my_notebook_env/bin/activate`
- Optional upgrade pip version with `pip install --upgrade pip`
- Install the required libraries `pip install tensorflow jupyterlab `
- Run `jupyter lab`
- Sample code to test:
-
```python
import tensorflow as tf
# Check if TensorFlow can see the GPU
print("Num GPUs Available: ",
len(tf.config.experimental.list_physical_devices('GPU')))
# Create a simple model and check if it runs on the GPU
model = tf.keras.Sequential([
tf.keras.layers.Dense(10, activation='relu',
input_shape=(784,)),
tf.keras.layers.Dense(10)
])
model.compile(optimizer='adam',
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=['accuracy'])
# Generate dummy data
import numpy as np
data = np.random.random((1000, 784))
labels = np.random.randint(10, size=(1000,))
model.fit(data, labels, epochs=5)
```
-