Skip to Content
DocumentaçãoDesenvolvimentoIA local/ciência de dados

Ambiente local de IA/ciência de dados

Este artigo aborda como construir um ambiente local completo de desenvolvimento de IA e ciência de dados no Ubuntu 26.04.

NVIDIA CUDA Configuração do ambiente

A execução de modelos de IA acelerados por GPU requer a instalação dos drivers NVIDIA e do kit de ferramentas CUDA primeiro.

Instale os drivers 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 reboot

Verifique o driver:

nvidia-smi

Instale o kit de ferramentas CUDA

# Install via apt (Ubuntu repository version) sudo apt install cuda-toolkit -y # Verify nvcc --version

Para uma versão CUDA específica, instale a partir do repositório oficial NVIDIA (Ubuntu 26.04 usa 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 -y
Note

Ubuntu 26.04 agora envia o kit de ferramentas NVIDIA CUDA em seus repositórios oficiais, então sudo apt install cuda-toolkit funciona diretamente. O repositório NVIDIA do ubuntu2604 permanece útil quando você precisa de uma versão específica do CUDA.

Configure variáveis ​​de ambiente:

echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc source ~/.bashrc

Instale o cuDNN

sudo apt install libcudnn9-cuda-12 libcudnn9-dev-cuda-12 -y

Ollama: execute modelos de linguagem grandes localmente

Ollama permite executar facilmente grandes modelos de linguagem como Llama, Mistral e Gemma localmente.

Instale Ollama

curl -fsSL https://ollama.com/install.sh | sh

Uso Básico

# 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 ps

API Ollama

Ollama fornece uma API REST, executada por padrão em 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"} ] }'

Usar com Open WebUI

Open WebUI fornece uma interface web semelhante ao ChatGPT para 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:main

Acesse em http://localhost:3000.

Notebook/Laboratório Jupyter

Jupyter é o ambiente de desenvolvimento interativo mais popular em ciência de dados e aprendizado de máquina.

Instale o 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 jupyterlab

Inicie o JupyterLab

jupyter lab

Seu navegador abrirá automaticamente http://localhost:8888.

Instale kernels comuns

# 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)"

Extensões Jupyter recomendadas

# 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-git

PyTorch

PyTorch é atualmente a estrutura de aprendizagem profunda mais popular.

Instale 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 nvidia

Instale PyTorch (CPU)

pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu

Verifique o suporte da GPU 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

Instale TensorFlow

# GPU version (auto-detects CUDA) pip install tensorflow # Verify python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

Verificação de GPU 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)

Pacotes comuns de ciência de dados

# 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 frameworks

Exemplo completo de ambiente de desenvolvimento de IA

Aqui está um fluxo de trabalho de configuração de ambiente de projeto recomendado:

# 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 lab

Usando transformadores de abraços faciais

pip install transformers datasets accelerate
from 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)

Monitore o uso da 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 1

Com seu ambiente de IA local configurado, você está pronto para executar vários modelos de linguagem grandes e tarefas de aprendizado profundo no Ubuntu 26.04.