AI/ML Engineer - Guía de Entorno¶
Guía completa para desarrollo de Inteligencia Artificial y Machine Learning con Claude Code.
Capacidades de Claude Code¶
| Capacidad | Herramientas |
|---|---|
| Entrenar modelos | Python, PyTorch, TensorFlow, JAX |
| Jupyter Notebooks | JupyterLab, VS Code Notebooks |
| MLOps | MLflow, Kubeflow, DVC |
| LLM Development | LangChain, LlamaIndex, Hugging Face |
| Computer Vision | OpenCV, YOLO, Detectron2 |
| NLP | spaCy, NLTK, Transformers |
| Data Processing | Pandas, Polars, Dask |
| GPU Computing | CUDA, cuDNN, ROCm |
Python ML Stack¶
Instalación Base¶
# Python 3.11+ (compatibilidad ML)
# Windows
winget install Python.Python.3.11
# macOS
brew install python@3.11
# Verificar
python --version
pip --version
Entornos Virtuales (Conda recomendado para ML)¶
# Miniconda (recomendado)
# Windows
winget install Anaconda.Miniconda3
# macOS
brew install miniconda
# Linux
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
# Crear entorno
conda create -n ml python=3.11
conda activate ml
# O con mamba (más rápido)
conda install mamba -c conda-forge
mamba create -n ml python=3.11
Frameworks de Deep Learning¶
# PyTorch (recomendado)
# CPU
pip install torch torchvision torchaudio
# CUDA 12.1 (NVIDIA GPU)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
# Apple Silicon (MPS)
pip install torch torchvision torchaudio # MPS incluido automáticamente
# TensorFlow
pip install tensorflow
# Con GPU
pip install tensorflow[and-cuda]
# JAX (Google)
pip install jax jaxlib
# Con GPU
pip install --upgrade "jax[cuda12_pip]" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html
Librerías Esenciales¶
# Data Science
pip install numpy pandas polars scikit-learn scipy matplotlib seaborn
# Deep Learning extras
pip install transformers datasets accelerate # Hugging Face
pip install lightning # PyTorch Lightning
pip install keras # High-level API
# Computer Vision
pip install opencv-python pillow albumentations
pip install ultralytics # YOLO
pip install detectron2 # Facebook
# NLP
pip install spacy nltk gensim
python -m spacy download es_core_news_lg
python -m spacy download en_core_web_lg
# LLM Development
pip install langchain langchain-community langchain-openai
pip install llama-index
pip install openai anthropic
# MLOps
pip install mlflow wandb tensorboard
pip install dvc # Data Version Control
pip install optuna # Hyperparameter tuning
# Notebooks
pip install jupyterlab notebook ipywidgets
GPU Setup¶
NVIDIA CUDA¶
# Windows
winget install Nvidia.CUDA
# Linux (Ubuntu)
# Seguir guía oficial: https://developer.nvidia.com/cuda-downloads
# Verificar instalación
nvidia-smi
nvcc --version
# Python - verificar GPU disponible
python -c "import torch; print(torch.cuda.is_available())"
python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
Apple Silicon (M1/M2/M3)¶
# MPS (Metal Performance Shaders) incluido en PyTorch
python -c "import torch; print(torch.backends.mps.is_available())"
# TensorFlow con Metal
pip install tensorflow-metal
AMD ROCm¶
# Linux only
# https://rocm.docs.amd.com/
# PyTorch con ROCm
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm5.6
Jupyter Environment¶
JupyterLab¶
# Instalar
pip install jupyterlab
# Extensiones útiles
pip install jupyterlab-git
pip install jupyterlab-lsp python-lsp-server
# Ejecutar
jupyter lab
# Con puerto específico
jupyter lab --port 8889 --no-browser
VS Code Notebooks¶
# Extensiones
code --install-extension ms-toolsai.jupyter
code --install-extension ms-toolsai.vscode-jupyter-cell-tags
code --install-extension ms-toolsai.vscode-jupyter-slideshow
code --install-extension ms-python.python
MLOps Tools¶
MLflow¶
pip install mlflow
# Servidor local
mlflow server --host 0.0.0.0 --port 5000
# UI: http://localhost:5000
# En código
import mlflow
mlflow.set_tracking_uri("http://localhost:5000")
mlflow.set_experiment("my-experiment")
with mlflow.start_run():
mlflow.log_param("learning_rate", 0.01)
mlflow.log_metric("accuracy", 0.95)
mlflow.pytorch.log_model(model, "model")
Weights & Biases¶
pip install wandb
# Login
wandb login
# En código
import wandb
wandb.init(project="my-project")
wandb.log({"loss": 0.5, "accuracy": 0.95})
DVC (Data Version Control)¶
pip install dvc dvc-s3 # o dvc-gdrive, dvc-azure
# Inicializar
dvc init
# Trackear datos
dvc add data/dataset.csv
# Remote storage
dvc remote add -d myremote s3://mybucket/dvc
dvc push
dvc pull
LLM Development¶
LangChain¶
pip install langchain langchain-openai langchain-anthropic langchain-community
# Ejemplo
from langchain_anthropic import ChatAnthropic
from langchain.prompts import ChatPromptTemplate
llm = ChatAnthropic(model="claude-3-sonnet-20240229")
prompt = ChatPromptTemplate.from_template("Explica {topic} en términos simples")
chain = prompt | llm
response = chain.invoke({"topic": "machine learning"})
Hugging Face¶
pip install transformers datasets accelerate
# Login para modelos privados
huggingface-cli login
# Descargar modelo
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-7b-hf")
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf")
Ollama (LLMs locales)¶
# Instalar
# Windows/macOS: https://ollama.ai/download
# Linux
curl -fsSL https://ollama.com/install.sh | sh
# Ejecutar modelo
ollama run llama2
ollama run codellama
ollama run mistral
# API local
curl http://localhost:11434/api/generate -d '{
"model": "llama2",
"prompt": "Hello"
}'
# Con LangChain
from langchain_community.llms import Ollama
llm = Ollama(model="llama2")
Docker para ML¶
Dockerfile¶
FROM pytorch/pytorch:2.1.0-cuda12.1-cudnn8-runtime
WORKDIR /app
# Dependencias del sistema
RUN apt-get update && apt-get install -y \
git \
&& rm -rf /var/lib/apt/lists/*
# Dependencias Python
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "train.py"]
Docker Compose con GPU¶
version: '3.8'
services:
training:
build: .
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
volumes:
- ./data:/app/data
- ./models:/app/models
environment:
- WANDB_API_KEY=${WANDB_API_KEY}
mlflow:
image: ghcr.io/mlflow/mlflow:latest
ports:
- "5000:5000"
command: mlflow server --host 0.0.0.0
volumes:
- mlflow_data:/mlflow
jupyter:
build: .
ports:
- "8888:8888"
command: jupyter lab --ip=0.0.0.0 --allow-root --no-browser
volumes:
- .:/app
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
volumes:
mlflow_data:
Comandos que Claude Code Ejecutará¶
# Entorno
conda create -n ml python=3.11
conda activate ml
pip install -r requirements.txt
# Jupyter
jupyter lab
jupyter nbconvert --to script notebook.ipynb
# Training
python train.py
python train.py --epochs 100 --lr 0.001
accelerate launch train.py # Multi-GPU
# MLflow
mlflow run . -P epochs=100
mlflow models serve -m runs:/<run_id>/model -p 5001
# DVC
dvc add data/
dvc push
dvc pull
# Hugging Face
huggingface-cli download meta-llama/Llama-2-7b-hf
python -m transformers.onnx --model=bert-base-uncased onnx/
# Ollama
ollama pull llama2
ollama run codellama "Write a Python function to sort a list"
# GPU
nvidia-smi
watch -n 1 nvidia-smi # Monitor en tiempo real
Verificación del Entorno¶
#!/bin/bash
echo "=== Verificación Entorno AI/ML ==="
echo -e "\n--- Python ---"
python --version
which python
echo -e "\n--- Conda ---"
conda --version 2>/dev/null || echo "Conda no instalado"
echo -e "\n--- PyTorch ---"
python -c "import torch; print(f'PyTorch: {torch.__version__}')" 2>/dev/null || echo "PyTorch no instalado"
python -c "import torch; print(f'CUDA available: {torch.cuda.is_available()}')" 2>/dev/null
python -c "import torch; print(f'MPS available: {torch.backends.mps.is_available()}')" 2>/dev/null
echo -e "\n--- TensorFlow ---"
python -c "import tensorflow as tf; print(f'TensorFlow: {tf.__version__}')" 2>/dev/null || echo "TensorFlow no instalado"
python -c "import tensorflow as tf; print(f'GPUs: {tf.config.list_physical_devices(\"GPU\")}')" 2>/dev/null
echo -e "\n--- GPU ---"
nvidia-smi 2>/dev/null || echo "nvidia-smi no disponible"
echo -e "\n--- MLOps ---"
mlflow --version 2>/dev/null || echo "MLflow no instalado"
dvc --version 2>/dev/null || echo "DVC no instalado"
echo -e "\n--- LLM Tools ---"
ollama --version 2>/dev/null || echo "Ollama no instalado"
echo -e "\n=== Verificación Completa ==="