Environnement local d’IA et de science des données
Cet article explique comment mettre en place un environnement local complet de développement pour l’IA et la science des données sous Ubuntu 26.04.
Configuration de l’environnement NVIDIA CUDA
L’exécution de modèles d’IA accélérés par GPU nécessite au préalable l’installation des pilotes NVIDIA et de la boîte à outils CUDA.
Installer les pilotes NVIDIA
# Check the recommended driver version
ubuntu-drivers devices
# Install the recommended driver
sudo ubuntu-drivers autoinstall
# Or manually install the version reported by ubuntu-drivers devices
sudo apt install nvidia-driver-XXX -y
# Reboot
sudo rebootVérifiez le pilote :
nvidia-smiInstaller la boîte à outils CUDA
# Install via apt (Ubuntu repository version)
sudo apt install cuda-toolkit -y
# Verify
nvcc --versionPour une version spécifique de CUDA, installez depuis le dépôt officiel NVIDIA (Ubuntu 26.04 utilise ubuntu2604) :
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2604/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt update
# List available CUDA Toolkit versions in the repository
apt-cache search cuda-toolkit
# Install a specific version (replace XX-Y with an actual available version)
sudo apt install cuda-toolkit-XX-Y -yUbuntu 26.04 fournit désormais la boîte à outils NVIDIA CUDA dans ses dépôts officiels, donc sudo apt install cuda-toolkit fonctionne directement. Le dépôt ubuntu2604 de NVIDIA reste utile lorsque vous avez besoin d’une version spécifique de CUDA.
Configurez les variables d’environnement :
echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrcInstaller cuDNN
sudo apt install libcudnn9-cuda-12 libcudnn9-dev-cuda-12 -yOllama : exécuter de grands modèles de langage en local
Ollama vous permet d’exécuter facilement en local de grands modèles de langage comme Llama, Mistral et Gemma.
Installer Ollama
curl -fsSL https://ollama.com/install.sh | shUtilisation de base
# Run a model (downloads automatically on first use)
ollama run llama3.2
# Run other models
ollama run mistral
ollama run gemma2
ollama run qwen2.5
ollama run deepseek-r1
# List downloaded models
ollama list
# Delete a model
ollama rm llama3.2
# View running models
ollama psAPI d’Ollama
Ollama fournit une API REST, disponible par défaut à l’adresse http://localhost:11434 :
# Generate text
curl http://localhost:11434/api/generate -d '{
"model": "llama3.2",
"prompt": "Explain what machine learning is"
}'
# Chat conversation
curl http://localhost:11434/api/chat -d '{
"model": "llama3.2",
"messages": [
{"role": "user", "content": "Hello"}
]
}'Utiliser avec Open WebUI
Open WebUI fournit une interface web de type ChatGPT pour Ollama :
docker run -d -p 3000:8080 \
--add-host=host.docker.internal:host-gateway \
-v open-webui:/app/backend/data \
--name open-webui \
ghcr.io/open-webui/open-webui:mainAccédez-y à l’adresse http://localhost:3000.
Jupyter Notebook / Lab
Jupyter est l’environnement de développement interactif le plus populaire en science des données et en apprentissage automatique.
Installer JupyterLab
# Ubuntu 26.04 blocks system-wide pip installs (PEP 668)
# Method 1: install as a standalone app with pipx
sudo apt install -y pipx
pipx ensurepath
pipx install jupyterlab
# Method 2: install inside a virtual environment
python3 -m venv ~/jupyter-env
source ~/jupyter-env/bin/activate
pip install jupyterlab notebook
# Method 3: use conda
conda install -c conda-forge jupyterlabLancer JupyterLab
jupyter labVotre navigateur ouvrira automatiquement http://localhost:8888.
Installer les noyaux courants
# Install R kernel
sudo apt install r-base -y
R -e "install.packages('IRkernel'); IRkernel::installspec()"
# Install a kernel for a specific virtual environment
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"Extensions Jupyter recommandées
# Install in the same virtual environment as JupyterLab (or inject via pipx)
# pipx users can run: pipx inject jupyterlab jupyterlab-lsp python-lsp-server jupyterlab-git
pip install jupyterlab-lsp python-lsp-server
pip install jupyterlab-gitPyTorch
PyTorch est actuellement le framework d’apprentissage profond le plus populaire.
Installer PyTorch (GPU)
# Install inside a virtual environment (PEP 668)
python3 -m venv ~/torch-env
source ~/torch-env/bin/activate
# pip install torch installs the wheel for the current CUDA by default;
# older drivers can pin a lower CUDA, e.g. cu126
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
# Using conda
conda install pytorch torchvision torchaudio pytorch-cuda=12.6 -c pytorch -c nvidiaInstaller PyTorch (CPU)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpuVérifier la prise en charge du GPU par PyTorch
import torch
print(f"PyTorch version: {torch.__version__}")
print(f"CUDA available: {torch.cuda.is_available()}")
print(f"CUDA version: {torch.version.cuda}")
print(f"GPU device: {torch.cuda.get_device_name(0)}")
# Simple test
x = torch.rand(3, 3).cuda()
print(x)TensorFlow
Installer TensorFlow
# Create a venv first (PEP 668: system Python rejects pip installs)
python3 -m venv ~/tf-env && source ~/tf-env/bin/activate
# GPU version (auto-detects CUDA)
pip install tensorflow
# Verify
python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"Vérification du GPU pour TensorFlow
import tensorflow as tf
print(f"TensorFlow version: {tf.__version__}")
print(f"GPU devices: {tf.config.list_physical_devices('GPU')}")
# Simple test
with tf.device('/GPU:0'):
a = tf.constant([[1.0, 2.0], [3.0, 4.0]])
b = tf.constant([[5.0, 6.0], [7.0, 8.0]])
c = tf.matmul(a, b)
print(c)Paquets courants de science des données
# Activate a virtual environment first (PEP 668: no pip into the system Python)
python3 -m venv ~/ds-env && source ~/ds-env/bin/activate
pip install numpy pandas matplotlib seaborn scikit-learn scipy
pip install plotly bokeh altair
pip install polars # High-performance alternative to pandas
pip install xgboost lightgbm catboost # Gradient boosting frameworksExemple complet d’environnement de développement d’IA
Voici un flux de travail recommandé pour configurer l’environnement d’un projet :
# Create project directory
mkdir ~/ai-project && cd ~/ai-project
# Create conda environment (pip is safe inside a conda environment)
conda create -n ai python=3.13 -y
conda activate ai
# Install core libraries (current CUDA by default; older drivers can pin cu126)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
pip install transformers datasets accelerate
pip install jupyterlab
pip install numpy pandas matplotlib scikit-learn
# Launch Jupyter
jupyter labUtiliser Hugging Face Transformers
pip install transformers datasets acceleratefrom transformers import pipeline
# Text generation
generator = pipeline("text-generation", model="gpt2")
result = generator("The future of artificial intelligence is", max_length=50)
print(result)
# Sentiment analysis
classifier = pipeline("sentiment-analysis")
result = classifier("This product is amazing")
print(result)Surveiller l’utilisation du GPU
# Real-time monitoring
watch -n 1 nvidia-smi
# Use nvitop (more visually appealing) -- install as a standalone CLI with pipx
pipx install nvitop
nvitop
# Use gpustat
pipx install gpustat
gpustat -i 1Une fois votre environnement d’IA local en place, vous êtes prêt à exécuter divers grands modèles de langage et tâches d’apprentissage profond sous Ubuntu 26.04.