* feat(docs): add initial documentation structure and configuration for Kubeflow Trainer - Introduced .readthedocs.yaml for ReadTheDocs configuration. - Created Makefile for building and serving documentation. - Added Sphinx configuration in docs/conf.py. - Established index.rst as the main entry point for documentation. - Developed user guides for various frameworks including PyTorch, JAX, and DeepSpeed. - Implemented custom CSS for documentation styling. - Included a distributed data cache guide and a DeepSpeed integration guide. This commit sets up the foundational documentation for the Kubeflow Trainer, enhancing accessibility and usability for users. Signed-off-by: Sridhar1030 <[email protected]> * feat(docs): update user guides and restructure documentation for Kubeflow Trainer - Renamed and reorganized user guides to better serve different audiences: AI practitioners, cluster operators, and contributors. - Added new sections for documentation on the Kubeflow Training Operator v1 and legacy guides. - Enhanced descriptions to clarify the purpose and content of each guide, improving overall accessibility and usability. Signed-off-by: Sridhar1030 <[email protected]> * feat(docs): add comprehensive operator guides for Kubeflow Trainer Signed-off-by: Sridhar1030 <[email protected]> * feat(docs): enhance operator guides for Kubeflow Trainer Signed-off-by: Sridhar1030 <[email protected]> * fixed user-guides Signed-off-by: Sridhar1030 <[email protected]> * feat(docs): add initial API reference and contributor guides for Kubeflow Trainer - Introduced API reference documentation for Python SDK and Kubernetes CRD types, including TrainJob, TrainingRuntime, and ClusterTrainingRuntime. - Created contributor guides covering architecture, community, and contributing processes. - Added legacy v1 documentation structure with sections for installation and user guides for various frameworks. - Enhanced local execution documentation with updated examples. This commit establishes a comprehensive documentation framework to support users and contributors of the Kubeflow Trainer. Signed-off-by: Sridhar1030 <[email protected]> * feat(docs): update user guides for distributed training frameworks - Revised user guides for distributed training with Kubeflow Trainer, including JAX, PyTorch, MLX, DeepSpeed, and the data cache feature. - Enhanced clarity and structure of documentation to improve user experience and accessibility. - Added detailed instructions for using TrainJob with various frameworks, emphasizing configuration-driven training and runtime packages. - Removed outdated content and streamlined sections for better readability. This commit enhances the documentation framework, making it easier for users to implement distributed training solutions. Signed-off-by: Sridhar1030 <[email protected]> * refactor(docs): update index.rst and custom.css for improved documentation layout - Replaced the old container structure with HTML for doc cards in index.rst, enhancing the visual presentation of quick links. - Updated CSS styles for doc cards to improve interactivity and appearance, including hover effects and text decoration. - Added an API Reference section to the documentation layout for better accessibility to technical details. These changes aim to enhance the user experience and accessibility of the Kubeflow Trainer documentation. Signed-off-by: Sridhar1030 <[email protected]> * feat(docs): enhance documentation with new sidebar toggle and external link handling - Added JavaScript functionality for a collapsible sidebar to improve navigation on larger screens. - Implemented external link handling to open links in a new tab for better user experience. - Updated CSS to accommodate new sidebar features and reduce whitespace in the content area. - Included Sphinx documentation build artifacts in .gitignore for cleaner repository management. These changes aim to improve the usability and accessibility of the Kubeflow Trainer documentation. Signed-off-by: Sridhar1030 <[email protected]> * added leagcy training docs Signed-off-by: Sridhar1030 <[email protected]> * refactor(docs): remove API reference section and update documentation layout - Deleted the API reference section and related files to streamline the documentation. - Updated index.rst to remove references to the API documentation. - Enhanced CSS styles for doc cards to improve visual consistency and interactivity. These changes aim to simplify the documentation structure and improve user navigation within the Kubeflow Trainer documentation. Signed-off-by: Sridhar1030 <[email protected]> * refactor(docs): remove CRD API reference generation and update Sphinx configuration - Eliminated the CRD API reference generation from the Makefile and .readthedocs.yaml to simplify the build process. - Updated Sphinx configuration to disable fail_on_warning, allowing builds to proceed despite warnings. - Removed AutoAPI configuration from conf.py and related dependencies from requirements.txt to streamline documentation setup. These changes aim to enhance the documentation build process and reduce complexity in the project structure. Signed-off-by: Sridhar1030 <[email protected]> * feat(docs): expand JAX and MPI user guides with detailed instructions - Updated the JAX user guide to include comprehensive instructions for creating and monitoring JAX training jobs using the JAXJob custom resource. - Enhanced the MPI user guide with additional metrics and Docker image building instructions, improving clarity and usability. - Introduced a new section in the multi-cluster guide detailing the `MultiKueue` feature for efficient management of MPI jobs across clusters. These changes aim to provide users with clearer guidance and enhance the overall documentation for distributed training frameworks in Kubeflow. Signed-off-by: Sridhar1030 <[email protected]> * feat(docs): enhance user guides with grid layout and sidebar improvements - Introduced a grid layout for the BuiltinTrainer and local execution user guides, improving visual organization and accessibility. - Added new sections for overview and backend options in the local execution guide, detailing how to run TrainJobs with different backends. - Updated CSS to make the sidebar sticky during scrolling, enhancing navigation on larger screens. These changes aim to improve the overall user experience and clarity of the documentation for Kubeflow Trainer. Signed-off-by: Sridhar1030 <[email protected]> * fix\(docs\):\ update\ dataset\ download\ instructions\ and\ improve\ links\ in\ user\ guides$'\n'$'\n'-\ Clarified\ that\ each\ rank\ in\ a\ multi-node\ TrainJob\ must\ download\ the\ dataset\ independently.$'\n'-\ Updated\ links\ in\ the\ local\ execution\ and\ Podman\ user\ guides\ to\ point\ directly\ to\ the\ relevant\ sections\ in\ the\ overview.$'\n'-\ Corrected\ the\ path\ for\ accessing\ the\ fine-tuned\ model\ in\ the\ BuiltinTrainer\ guide.$'\n'$'\n'These\ changes\ enhance\ the\ clarity\ and\ usability\ of\ the\ documentation\ for\ Kubeflow\ Trainer. (resolved the copliot reviews) Signed-off-by: Sridhar1030 <[email protected]> * docs: update extension framework guide and remove pod template documentation - Added architecture diagrams to the Kubeflow Trainer Extension Framework guide for better visualization. - Updated terminology in the index to reflect the transition from Pod Templates to Runtime Patches. - Removed the outdated PodTemplate documentation to streamline the guides and focus on current practices. These changes aim to enhance clarity and usability in the documentation for the Kubeflow Trainer. Signed-off-by: Sridhar1030 <[email protected]> * docs: update overview and add diagrams Signed-off-by: Sridhar1030 <[email protected]> * docs: update Sphinx configuration and improve link references - Enabled fail_on_warning in Sphinx configuration to ensure builds fail on warnings, enhancing documentation quality. - Updated links in user guides to point to the correct paths, improving navigation and clarity for users. These changes aim to enhance the reliability and usability of the documentation for Kubeflow Trainer. Signed-off-by: Sridhar1030 <[email protected]> * fixed the MNIST link , updated local process backend to match the main documentation website Signed-off-by: Sridhar1030 <[email protected]> * fix(docs): add missing newline at end of file for pre-commit compliance Signed-off-by: Sridhar1030 <[email protected]> * fix(docs): remove trailing whitespace in podman guide Signed-off-by: Sridhar1030 <[email protected]> * fix(docs): format conf.py for black/flake8 compliance Signed-off-by: Sridhar1030 <[email protected]> Made-with: Cursor * docs: update theme configuration and enhance CSS for improved navigation - Updated the Furo theme options in `conf.py` to refine color variables for light and dark modes, enhancing visual consistency. - Introduced a top navigation bar in the CSS with links to examples, GitHub, Slack, and the blog, improving accessibility and user experience. - Expanded the CSS file to include a comprehensive color palette and responsive design adjustments for better usability across devices. These changes aim to enhance the overall look and feel of the Kubeflow Trainer documentation, making it more user-friendly and visually appealing. Signed-off-by: Sridhar1030 <[email protected]> * fix(docs): wrap long lines in conf.py to satisfy E501 lint Break announcement HTML string into concatenated short lines to keep all lines under the 100-character limit. Ref #3308 Signed-off-by: Sridhar1030 <[email protected]> * docs: enhance theme configuration and update local execution guides - Updated color variables in `conf.py` for improved light and dark mode support. - Refined CSS styles to utilize new color variables, enhancing visual consistency across the documentation. - Added architecture diagrams for Docker and Podman backends in their respective guides, clarifying the orchestration process. - Improved the structure and clarity of the local execution documentation, including error handling and configuration examples. These changes aim to enhance the overall user experience and visual appeal of the Kubeflow Trainer documentation. Signed-off-by: Sridhar1030 <[email protected]> * added homepage Signed-off-by: Sridhar1030 <[email protected]> * fixed routing Signed-off-by: Sridhar1030 <[email protected]> * Added remaining pages Signed-off-by: Sridhar1030 <[email protected]> * fix(docs): trim trailing whitespace for pre-commit Signed-off-by: Sridhar1030 <[email protected]> * fix(docs): add Kubeflow boilerplate header to conf.py Required by the code-quality verify-boilerplate check added upstream. Signed-off-by: Sridhar1030 <[email protected]> * fix(docs): address PR review feedback - Consolidate landing page: remove home.rst, migrate links to index.rst - Vendor overview and data-cache images into docs/images/ - Fix apiVersion v2alpha1 → v1alpha1 in runtime-patches and megatron - Add missing runtimes to supported-runtimes table - Expand overview ecosystem list, remove phantom SDK bullet and stray emoji - Replace hard-coded GitHub stats with ADOPTERS.md link - Delete kueue.md stub, use external toctree link - Fix torchtune overview link and wildcard import - Fix xgboost typos and add distributed training example - Replace vendored contributing/community with link-out stubs - Add data-cache architecture diagrams - Move top nav to Sphinx extension (docs/_ext/kubeflow_topnav/) - Fix brokeGitHub line anchors in legacy fine-tuning reference - Add missing import os in legacy getting-started Signed-off-by: Sridhar1030 <[email protected]> * docs(operator-guides): add torch envInjection section to ml-policy Add documentation for torch.envInjection.targets in MLPolicy, allowing PET_* env vars to be injected into init/sidecar containers. Ref: kubeflow/website#4399, kubeflow/trainer#3417 Signed-off-by: Sridhar1030 <[email protected]> --------- Signed-off-by: Sridhar1030 <[email protected]> Co-authored-by: Hanzo Dev <[email protected]>
9.1 KiB
Docker Backend
Overview
The Container Backend with Docker enables you to run distributed TrainJobs in isolated Docker containers on your local machine. This backend provides:
- Full Container Isolation: Each TrainJob runs in its own Docker container with isolated filesystem, network, and resources
- Multi-Node Support: Run distributed training across multiple containers with automatic networking
- Reproducibility: TrainJob runs in consistent containerized environments
- Flexible Configuration: Customize image pulling policies, resource allocation, and container settings
The Docker backend uses the adapter pattern to provide a unified interface, making it easy to switch between Docker and Podman without code changes.
Architecture
The Container Backend with Docker uses a local orchestration layer to manage TrainJobs within Docker containers. This ensures environment parity between your local machine and production Kubernetes clusters.
:::{mermaid} graph TD User([User Script]) -->|TrainerClient.train| SDK[Kubeflow SDK]
SDK -->|1. Pull| Image[Docker Image]
SDK -->|2. Net| Net[Bridge Network]
SDK -->|3. Run| Daemon[Docker Daemon]
subgraph DockerEnv [Local Docker Environment]
direction LR
Daemon -->|Spawn| C1[Node 0]
Daemon -->|Spawn| C2[Node 1]
C1 <-->|DDP| C2
end
C1 -->|4. Logs| Logs[Stream Logs]
C2 -->|4. Logs| Logs
SDK -.->|5. Cleanup| Remove[Remove Containers]
:::
Prerequisites
Required Software
- Docker: Install Docker Desktop (macOS/Windows) or Docker Engine (Linux)
- macOS/Windows: Download from docker.com
- Linux: Follow Docker Engine installation guide
- Python 3.9+
- Kubeflow SDK: Install with Docker support:
pip install "kubeflow[docker]"
Verify Installation
# Check Docker is running
docker version
# Test Docker daemon connectivity
docker ps
Basic Example
Here's a simple example using the Docker Container Backend:
from kubeflow.trainer import CustomTrainer, TrainerClient, ContainerBackendConfig
def train_model():
"""Simple training function."""
import torch
import os
rank = int(os.environ.get('RANK', '0'))
world_size = int(os.environ.get('WORLD_SIZE', '1'))
print(f"Training on rank {rank}/{world_size}")
# Your training code
model = torch.nn.Linear(10, 1)
optimizer = torch.optim.SGD(model.parameters(), lr=0.01)
for epoch in range(5):
loss = torch.nn.functional.mse_loss(
model(torch.randn(32, 10)),
torch.randn(32, 1)
)
optimizer.zero_grad()
loss.backward()
optimizer.step()
print(f"[Rank {rank}] Epoch {epoch + 1}/5, Loss: {loss.item():.4f}")
print(f"[Rank {rank}] Training completed!")
# Configure the Docker backend
backend_config = ContainerBackendConfig(
container_runtime="docker", # Explicitly use Docker
pull_policy="IfNotPresent", # Pull image if not cached locally
auto_remove=True # Clean up containers after completion
)
# Create the client
client = TrainerClient(backend_config=backend_config)
# Create a trainer with multi-node support
trainer = CustomTrainer(
func=train_model,
num_nodes=2 # Run distributed training across 2 containers
)
# Start the TrainJob
job_name = client.train(trainer=trainer)
print(f"TrainJob started: {job_name}")
# Wait for completion
job = client.wait_for_job_status(
job_name,
)
print(f"Job completed with status: {job.status}")
Configuration Options
ContainerBackendConfig
| Parameter | Type | Default | Description |
|---|---|---|---|
container_runtime |
str | None |
None |
Force specific runtime: "docker", "podman", or None (auto-detect). Use "docker" to ensure Docker is used. |
pull_policy |
str |
"IfNotPresent" |
Image pull policy: "IfNotPresent" (pull if missing), "Always" (always pull), "Never" (use cached only). |
auto_remove |
bool |
True |
Automatically remove containers and networks after job completion or deletion. Set to False for debugging. |
container_host |
str | None |
None |
Override Docker daemon connection URL (e.g., "unix:///var/run/docker.sock", "tcp://192.168.1.100:2375"). |
runtime_source |
TrainingRuntimeSource |
GitHub sources | Configuration for training runtime sources. See "Custom Runtime Sources" section below. |
Configuration Examples
Basic Configuration
backend_config = ContainerBackendConfig(
container_runtime="docker",
)
Always Pull Latest Image
backend_config = ContainerBackendConfig(
container_runtime="docker",
pull_policy="Always" # Always pull latest image
)
Keep Containers for Debugging
backend_config = ContainerBackendConfig(
container_runtime="docker",
auto_remove=False # Containers remain after job completion
)
Multi-Node Distributed Training
The Docker backend automatically sets up networking and environment variables for distributed training:
from kubeflow.trainer import CustomTrainer, TrainerClient, ContainerBackendConfig
def distributed_train():
"""PyTorch distributed training example."""
import os
import torch
import torch.distributed as dist
# Environment variables set by torchrun
rank = int(os.environ['RANK'])
world_size = int(os.environ['WORLD_SIZE'])
print(f"Initializing process group: rank={rank}, world_size={world_size}")
# Initialize distributed training
dist.init_process_group(
backend='gloo', # Use 'gloo' for CPU, 'nccl' for GPU
rank=rank,
world_size=world_size
)
# Your distributed training code
model = torch.nn.Linear(10, 1)
ddp_model = torch.nn.parallel.DistributedDataParallel(model)
# Training loop
for epoch in range(5):
# Your training code here
print(f"[Rank {rank}] Training epoch {epoch + 1}")
dist.destroy_process_group()
print(f"[Rank {rank}] Training complete")
backend_config = ContainerBackendConfig(
container_runtime="docker",
)
client = TrainerClient(backend_config=backend_config)
trainer = CustomTrainer(
func=distributed_train,
num_nodes=4 # Run across 4 containers
)
job_name = client.train(trainer=trainer)
Job Management
For common job management operations (listing jobs, viewing logs, deleting jobs), see the Job Management section in the overview.
Inspecting Containers
When auto_remove=False, you can inspect containers after job completion:
# List containers for a job
docker ps -a --filter "label=kubeflow.org/job-name=<job-name>"
# Inspect a specific container
docker inspect <job-name>-node-0
# View logs directly
docker logs <job-name>-node-0
# Execute commands in a stopped container
docker start <job-name>-node-0
docker exec -it <job-name>-node-0 /bin/bash
Working with Runtimes
For information about using runtimes and custom runtime sources, see the Working with Runtimes section in the overview.
Troubleshooting
Docker Daemon Not Running
Error: Error while fetching server API version: ('Connection aborted.', ConnectionRefusedError(61, 'Connection refused'))
Solution:
# macOS/Windows: Start Docker Desktop
# Linux: Start Docker daemon
sudo systemctl start docker
# Verify Docker is running
docker ps
Permission Denied
Error: Got permission denied while trying to connect to the Docker daemon socket
Solution (Linux):
# Add your user to docker group
sudo usermod -aG docker $USER
# Log out and back in, or run
newgrp docker
GPU Not Available in Container
Error: RuntimeError: No CUDA GPUs are available
Solution:
# 1. Verify NVIDIA drivers on host
nvidia-smi
# 2. Verify NVIDIA Container Toolkit
docker run --rm --gpus all nvidia/cuda:11.8.0-base-ubuntu22.04 nvidia-smi
# 3. Request GPU in your trainer
trainer = CustomTrainer(
func=train_model,
resources_per_node={"gpu": "1"}
)
Containers Not Removed
Problem: Containers remain after job completion
Solution:
# Ensure auto_remove is enabled
backend_config = ContainerBackendConfig(
container_runtime="docker",
auto_remove=True # Default
)
# Or manually clean up
client.delete_job(job_name)
Or use Docker CLI:
docker rm -f $(docker ps -aq --filter "label=kubeflow.org/job-name=<job-name>")
Network Conflicts
Error: network with name -net already exists
Solution:
# Remove conflicting network
docker network rm <job-name>-net
# Or delete the previous job
# client.delete_job(job_name)
Next Steps
- Try the MNIST example notebook for a complete end-to-end example
- Learn about the Container Backend with Podman for rootless containerized training
- Learn about the Local Process Backend for non-containerized local execution