* 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]>
11 KiB
Podman Backend
Overview
The Container Backend with Podman enables you to run distributed TrainJobs in isolated containers using Podman, a daemonless container engine. Podman offers several advantages over Docker:
- Daemonless Architecture: No background daemon required, reducing attack surface
- Rootless Containers: Run containers without root privileges for enhanced security
- Full Container Isolation: Each training process runs in its own container with isolated filesystem, network, and resources
- Multi-Node Support: Run distributed training across multiple containers with automatic DNS-enabled networking
- Docker Compatibility: Compatible with Docker images and Docker CLI syntax
- systemd Integration: Better integration with systemd for service management
The Podman backend uses the same adapter pattern as Docker, providing a unified interface for container operations.
Prerequisites
Required Software & Initial Setup
- Podman 3.0+: Install Podman for your platform by following the podman installation instructions
- Kubeflow SDK: Install with Podman support:
pip install "kubeflow[podman]"
Verify Installation
podman version
podman ps
Custom Socket Location (Optional)
By default, Podman uses different socket locations than Docker. You can specify a custom socket:
# Start Podman with custom socket (macOS/Linux)
podman system service --time=0 unix:///tmp/podman.sock
# Or use systemd (Linux)
systemctl --user enable --now podman.socket
Basic Example
Here's a simple example using the Podman 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}")
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!")
backend_config = ContainerBackendConfig(
container_runtime="podman",
pull_policy="IfNotPresent",
auto_remove=True
)
client = TrainerClient(backend_config=backend_config)
trainer = CustomTrainer(
func=train_model,
num_nodes=2
)
job_name = client.train(trainer=trainer)
print(f"TrainJob started: {job_name}")
job = client.wait_for_job_status(job_name)
print(f"Job completed with status: {job.status}")
Configuration Options
ContainerBackendConfig for Podman
| Parameter | Type | Default | Description |
|---|---|---|---|
container_runtime |
str | None |
None |
Force specific runtime: "podman", "docker", or None (auto-detect). Use "podman" to ensure Podman 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 Podman socket URL (e.g., "unix:///tmp/podman.sock", "unix:///run/user/1000/podman/podman.sock"). |
runtime_source |
TrainingRuntimeSource |
GitHub sources | Configuration for training runtime sources. See "Custom Runtime Sources" section below. |
Configuration Examples
Basic Podman Configuration
backend_config = ContainerBackendConfig(
container_runtime="podman",
)
Custom Socket Location
# macOS with Podman machine
backend_config = ContainerBackendConfig(
container_runtime="podman",
container_host="unix:///tmp/podman.sock"
)
# Linux rootless (user-specific socket)
import os
uid = os.getuid()
backend_config = ContainerBackendConfig(
container_runtime="podman",
container_host=f"unix:///run/user/{uid}/podman/podman.sock"
)
Always Pull Latest Image
backend_config = ContainerBackendConfig(
container_runtime="podman",
pull_policy="Always"
)
Keep Containers for Debugging
backend_config = ContainerBackendConfig(
container_runtime="podman",
auto_remove=False
)
Architecture
The Container Backend with Podman uses a local orchestration layer to manage TrainJobs within Podman containers. This ensures environment parity between your local machine and production Kubernetes clusters.
:::{mermaid} graph LR User([User Script]) -->|TrainerClient.train| SDK[Kubeflow SDK]
SDK -->|1. Pull| Image[Podman Image]
SDK -->|2. Net| Net[DNS-Enabled Bridge Network]
SDK -->|3. Run| Podman[Podman Engine]
subgraph PodmanEnv [Local Podman Environment]
direction TB
Podman -->|Spawn| C1[Node 0]
Podman -->|Spawn| C2[Node 1]
C1 <-->|DDP| C2
end
C1 -->|4. Logs| Logs[Stream Logs]
C2 -->|4. Logs| Logs
SDK -.->|5. Cleanup| Remove[Remove Containers]
:::
Multi-Node Distributed Training
The Podman 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
rank = int(os.environ['RANK'])
world_size = int(os.environ['WORLD_SIZE'])
print(f"Initializing process group: rank={rank}, world_size={world_size}")
dist.init_process_group(
backend='gloo',
rank=rank,
world_size=world_size
)
model = torch.nn.Linear(10, 1)
ddp_model = torch.nn.parallel.DistributedDataParallel(model)
for epoch in range(5):
print(f"[Rank {rank}] Training epoch {epoch + 1}")
dist.destroy_process_group()
print(f"[Rank {rank}] Training complete")
backend_config = ContainerBackendConfig(
container_runtime="podman",
)
client = TrainerClient(backend_config=backend_config)
trainer = CustomTrainer(
func=distributed_train,
num_nodes=4
)
job_name = client.train(trainer=trainer)
Podman-Specific Networking
Podman creates networks with DNS enabled by default, allowing containers to resolve each other by hostname. The backend implementation uses IP addresses for the MASTER_ADDR environment variable to ensure reliable communication:
IP Address Resolution
The Podman backend automatically retrieves the IP address of the rank-0 container using podman inspect:
podman inspect --format '{{.NetworkSettings.Networks.<network-name>.IPAddress}}' <container-name>
This IP address is then set as MASTER_ADDR for all nodes in the job, ensuring that:
- Communication works even if DNS resolution has timing issues
- The master address is available immediately when containers start
- Distributed training frameworks (PyTorch, TensorFlow) can connect reliably
DNS Resolution
While DNS is enabled and containers can resolve each other by hostname, the backend uses IP addresses for reliability:
def test_networking():
import os
import socket
rank = int(os.environ['RANK'])
master_addr = os.environ['MASTER_ADDR']
print(f"Rank {rank}: My hostname is {socket.gethostname()}")
print(f"Rank {rank}: Master address (IP): {master_addr}")
if rank == 0:
container_name = os.environ.get('HOSTNAME')
print(f"Rank {rank}: My IP address: {socket.gethostbyname(container_name)}")
if rank != 0:
import subprocess
result = subprocess.run(['ping', '-c', '1', master_addr], capture_output=True)
print(f"Ping to master IP: {result.returncode == 0}")
Network Architecture
For a job with num_nodes=3, the Podman backend:
- Creates a dedicated network:
<job-name>-netwith DNS enabled - Launches rank-0 container and waits for it to be running
- Inspects rank-0 container to get its IP address
- Sets
MASTER_ADDRto this IP for all containers - Launches remaining containers (rank 1, 2, ...) connected to the same network
This approach combines the benefits of DNS (hostname resolution) with the reliability of IP addresses for critical communication paths.
Job Management
For common job management operations (listing jobs, viewing logs, deleting jobs), see the Job Management section in the overview.
Inspecting Containers with Podman CLI
When auto_remove=False, you can inspect containers:
podman ps -a --filter "label=kubeflow.org/job-name=<job-name>"
podman inspect <job-name>-node-0
podman logs <job-name>-node-0
podman exec -it <job-name>-node-0 /bin/bash
podman --url unix:///tmp/podman.sock logs <job-name>-node-0
Working with Runtimes
For information about using runtimes and custom runtime sources, see the Working with Runtimes section in the overview.
Troubleshooting
Podman Service Not Running (macOS)
Error: ConnectionRefusedError: [Errno 61] Connection refused
Solution:
podman machine list
podman machine start
podman machine stop
podman machine start --now
Socket Not Found (Linux)
Error: FileNotFoundError: [Errno 2] No such file or directory: '/run/user/1000/podman/podman.sock'
Solution:
systemctl --user start podman.socket
systemctl --user enable podman.socket
ls -la /run/user/$(id -u)/podman/podman.sock
Permission Denied (Rootless)
Error: Error: container_linux.go:380: starting container process caused...
Solution:
sudo sysctl -w user.max_user_namespaces=15000
echo "user.max_user_namespaces=15000" | sudo tee -a /etc/sysctl.conf
sudo usermod --add-subuids 100000-165535 --add-subgids 100000-165535 $USER
DNS Resolution Issues
Error: Containers cannot resolve each other's hostnames
Solution:
podman network inspect <job-name>-net | grep dns_enabled
Containers Not Removed
Problem: Containers remain after job completion
Solution:
backend_config = ContainerBackendConfig(
container_runtime="podman",
auto_remove=True
)
client.delete_job(job_name)
Or:
podman rm -f $(podman ps -aq --filter "label=kubeflow.org/job-name=<job-name>")
Next Steps
- Try the MNIST example notebook for a complete end-to-end example
- Learn about the Container Backend with Docker for Docker-specific features
- Learn about the Local Process Backend for non-containerized local execution