How kubeflow/sdk works
Project Type and Purpose
• Type: Open-source Python SDK library.
• Purpose: Provide a unified Python API (TrainerClient/CustomTrainer) to submit and manage ML training jobs across multiple Kubeflow backends (local and Kubernetes), abstracting away infra complexity.
File Structure
• Top-level files: pyproject.toml, Makefile, CI configs in .github/workflows/, docs/, scripts/, kubeflow/ package.
• Core package kubeflow/trainer:
• api/: public client interface (trainer_client.py)
• backends/: pluggable executor implementations
– kubernetes/backend.py + types
– localprocess/backend.py + job launcher, utils
• types/: data models for Trainer, Runtime, Job specs
• constants/: shared constants
• utils/: helper functions (serialization, logging)
• Docs & Proposals: design discussions, local execution proposal.
• CI/CD: tests (unit, e2e), release workflows.
Key Insights from README
• Public API entry point: TrainerClient().train(...)
• Supports multiple “runtimes” (e.g., torch-distributed) via get_runtime
• Local development & Kubernetes supported
• Aim: unify interactions with various Kubeflow components (Trainer, Katib, Pipelines planned)
Components & Interactions
a. Main Components
1. Client Application (user’s Python script)
2. Kubeflow SDK
• API Layer: TrainerClient, CustomTrainer
• Core Models: types (JobSpec, RuntimeSpec)
• Backends:
– LocalProcess Backend: spawns OS processes
– Kubernetes Backend: calls Kubernetes API to create TrainingJob CRDs
• Utils & Constants
3. External Services
• Kubernetes Cluster (API server, control plane)
• Container Registry (for Docker images)
• Logging/Monitoring (e.g., Kubernetes logs)
b. Relationships & Data Flow
2. API → Core Models (builds JobSpec)
3. API → Backend Router (chooses local vs. k8s)
4. Local Backend → OS Processes → STDOUT/STDERR → SDK logs
5. Kubernetes Backend → kube-api server → create Job CRD → Worker Pods
6. Kubernetes Backend ← Pod status & logs ← SDK → Client app
c. Architectural Patterns / Principles
• Adapter/Strategy Pattern: pluggable backends implementing same interface (base.py)
• Facade Pattern: TrainerClient simplifies multiple subsystems
• Modular Design: clear separation into api, backends, types, utils
d. Key Technologies & Frameworks
• Python 3.8+ (PEP 621 via pyproject.toml)
• Kubernetes Python client
• PyPI packaging
• CI via GitHub Actions
• Local process management (multiprocessing, subprocess)
Detailed Breakdown to Capture
• api layer and its public methods
• Distinguish between two backend implementations under backends/
• Type/data flow through types/
• utils/ as a shared component feeding into both backends