/mlops-skills:ray-distributed-ml-orchestrationfrom mlops-skills
Guides using Ray (Core, Train, Tune, Serve) with KubeRay on Kubernetes for Python-native distributed ML training, hyperparameter search, and serving, as an alternative to graph-based orchestrators like Kubeflow Pipelines.
Ships in mlops-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
kubeflow-ml-pipeline-orchestration
models an ML workflow as a graph of containerized steps; Ray takes a
fundamentally different approach — it's a Python-native distributed
computing runtime where a cluster of workers executes ordinary Python
functions and classes (tasks and actors) as first-class distributed units,
with Ray Train, Ray Tune, and Ray Serve as ML-specific libraries built on
that same runtime for distributed training, hyperparameter search, and
model serving respectively. On Kubernetes, the KubeRay operator manages Ray
as RayCluster/RayJob/RayService custom resources. The operational
tradeoff this skill exists to navigate: Ray's programming model is far more
flexible than a static DAG (dynamic task graphs, actors with persistent
state, fine-grained fractional GPU allocation) but that flexibility moves
more failure modes into application code and Ray's own scheduler/object
store, rather than being visible as a static, inspectable pipeline graph the
way Kubeflow's compiled IR is.
RayCluster on Kubernetes via the KubeRay operator for
distributed PyTorch/TensorFlow training with Ray Train.helm install kuberay-operator kuberay/kuberay-operator), which manages
RayCluster, RayJob, and RayService CRDs.ray Python package installed in both the client environment
(wherever job submission originates) and baked into the cluster's worker
images, at the exact same version — Ray's wire protocol is not
guaranteed compatible across even minor version differences, and a
mismatch is a leading cause of cryptic connection failures (see Common
pitfalls).num_gpus=) sits on top of, and must agree
with, the Kubernetes-level nvidia.com/gpu/MIG resource requests on the
underlying worker pods.--object-store-memory /
object_store_memory on the head and workers) sized for the working set
of data actually held in Ray's distributed object store, not just the
training batch size.Install the KubeRay operator and define a RayCluster with separate
head and worker groups — the head runs the Ray scheduler, dashboard, and
GCS (global control store) and should not run heavy training work itself
at scale; worker groups carry the actual compute, including a
GPU-specific worker group:
apiVersion: ray.io/v1
kind: RayCluster
metadata:
name: fraud-training-cluster
spec:
rayVersion: "2.34.0"
headGroupSpec:
rayStartParams: {dashboard-host: "0.0.0.0"}
template:
spec:
containers:
- name: ray-head
image: registry.internal/ray-ml:2.34.0
resources:
requests: {cpu: "2", memory: 8Gi}
limits: {cpu: "2", memory: 8Gi}
workerGroupSpecs:
- groupName: gpu-workers
replicas: 4
minReplicas: 0
maxReplicas: 8
rayStartParams: {}
template:
spec:
nodeSelector: {gpu-pool: training}
tolerations:
- {key: workload, operator: Equal, value: training, effect: NoSchedule}
containers:
- name: ray-worker
image: registry.internal/ray-ml:2.34.0
resources:
requests: {cpu: "8", memory: 32Gi, nvidia.com/gpu: 1}
limits: {cpu: "8", memory: 32Gi, nvidia.com/gpu: 1}
Set minReplicas/maxReplicas on worker groups so Ray's own autoscaler
can scale the group between 0 and a ceiling — but see step 7 for how
this interacts with the Kubernetes-level node autoscaler.
Distribute training with Ray Train, which wraps PyTorch/TensorFlow
distributed training loops so the same script scales from a laptop to a
multi-node GPU cluster without hand-rolled torch.distributed setup:
from ray.train.torch import TorchTrainer
from ray.train import ScalingConfig, RunConfig, CheckpointConfig
def train_loop_per_worker(config):
import torch
model = build_model()
model = ray.train.torch.prepare_model(model)
for epoch in range(config["epochs"]):
train_one_epoch(model, ...)
ray.train.report({"epoch": epoch, "loss": current_loss})
trainer = TorchTrainer(
train_loop_per_worker=train_loop_per_worker,
train_loop_config={"epochs": 20},
scaling_config=ScalingConfig(num_workers=4, use_gpu=True, resources_per_worker={"GPU": 1}),
run_config=RunConfig(
storage_path="s3://ml-artifacts/ray-train-checkpoints/",
checkpoint_config=CheckpointConfig(num_to_keep=3),
),
)
result = trainer.fit()
use_gpu=True plus resources_per_worker={"GPU": 1} tells Ray's
scheduler to place each training worker on a node with an available GPU
— this is Ray's own resource accounting layered on top of, not a
replacement for, the Kubernetes-level GPU resource request on the
worker pod spec.
Run hyperparameter search with Ray Tune, which parallelizes trials across the cluster and supports early-stopping schedulers so underperforming trials are killed before consuming their full budget:
from ray import tune
from ray.tune.schedulers import ASHAScheduler
def trainable(config):
for step in range(config["epochs"]):
acc = train_step(config["lr"], config["batch_size"])
tune.report({"accuracy": acc})
tuner = tune.Tuner(
trainable,
param_space={"lr": tune.loguniform(1e-4, 1e-1), "batch_size": tune.choice([16, 32, 64]), "epochs": 10},
tune_config=tune.TuneConfig(
scheduler=ASHAScheduler(metric="accuracy", mode="max"),
num_samples=50,
),
)
results = tuner.fit()
best_result = results.get_best_result(metric="accuracy", mode="max")
Serve models with Ray Serve, which supports multiple models with independent scaling and request batching from a single Ray cluster — useful when serving several models of different sizes/traffic patterns without one Kubernetes Deployment per model:
from ray import serve
@serve.deployment(ray_actor_options={"num_gpus": 0.25}, autoscaling_config={"min_replicas": 1, "max_replicas": 10})
class FraudScorer:
def __init__(self):
self.model = load_model("s3://ml-models/fraud-scorer/v14/")
async def __call__(self, request):
payload = await request.json()
return {"score": self.model.predict(payload["features"])}
serve.run(FraudScorer.bind(), name="fraud-scorer")
num_gpus=0.25 requests a fractional GPU allocation from Ray — Ray
will pack up to 4 such replicas onto one physical GPU with Ray-level
accounting, distinct from Kubernetes-level MIG partitioning; this only
gives soft isolation (like time-slicing), not the hard memory isolation
MIG provides — see
gpu-accelerator-infrastructure-for-ml-training
for that distinction.
Submit and track work as a RayJob for one-shot training runs
rather than manually connecting a client to a long-lived cluster, so the
job's lifecycle (and the cluster's, if shutdownAfterJobFinishes is set)
is managed declaratively:
apiVersion: ray.io/v1
kind: RayJob
metadata:
name: fraud-training-run-2026-07-28
spec:
entrypoint: python train_fraud_model.py --epochs 20
shutdownAfterJobFinishes: true
rayClusterSpec:
rayVersion: "2.34.0"
# ... headGroupSpec / workerGroupSpecs as in step 1 ...
For long-lived serving, use RayService instead, which KubeRay
health-checks and can zero-downtime-upgrade in place when the Serve
application config changes.
Size the object store deliberately and monitor for spilling — Ray spills objects to disk when the in-memory object store fills up, which is a correctness-preserving but severe performance cliff, not a crash:
ray status # from a pod with ray CLI access, shows object store usage and spill stats
If spilling is frequent, either increase
--object-store-memory on workers or restructure the job to avoid
holding large intermediate objects (e.g. process data in smaller shards)
rather than treating spilling as background noise.
Decide how Ray's autoscaler and the Kubernetes node autoscaler
interact before enabling both — Ray's autoscaler requests more worker
pods (up to maxReplicas) based on pending Ray tasks/actors, and the
Kubernetes-level node autoscaler (cluster-autoscaler/Karpenter) then has
to provision nodes for those pending pods. If both are misconfigured
(e.g. Ray's maxReplicas far exceeds real node-pool capacity, or the
node autoscaler's scale-up is slower than Ray's scheduler's patience),
the result is pods stuck Pending while Ray's own scheduler reports
tasks as "waiting for resources" with no clear top-level error. See
karpenter-cluster-autoscaling
for tuning the node-level side of this interaction.
rayVersion in the
RayCluster spec and the ray pip package used to submit jobs) —
version drift is the single most common source of opaque Ray connection
errors.num_gpus=0.25 etc.) only for workloads
that tolerate soft, memory-unisolated sharing (e.g. several low-traffic
Ray Serve replicas); for training or any workload needing memory
isolation, request whole GPUs or align Ray's request with a Kubernetes
MIG-partitioned worker group instead.shutdownAfterJobFinishes: true on RayJob for one-shot training
runs so idle Ray clusters don't linger (and keep billing) after the job
completes — this mirrors the "don't leave idle GPU capacity running"
guidance in
gpu-accelerator-infrastructure-for-ml-training.RunConfig(storage_path=...)
pointing at S3/GCS, not local worker disk) so a worker pod eviction
during a long Ray Train run doesn't lose progress.ray status / the Ray dashboard's cluster resource view
alongside Kubernetes-level pod status — a Ray-level "task pending on
resources" state looks identical to a healthy busy cluster unless you
check whether the underlying worker pods actually exist and are Running.Symptom: A client fails to connect to a Ray cluster with an opaque
version-mismatch error, or worse, connects but tasks behave
unpredictably (silent serialization failures, actors that appear to
hang).
Fix: Verify the ray package version installed wherever the job is
submitted from exactly matches rayVersion in the RayCluster spec and
the version baked into the worker/head images — Ray does not guarantee
cross-version wire compatibility, and this is the first thing to check
before debugging application code.
Symptom: A long-running Ray Train job slows down dramatically partway
through with no error, and ray status shows heavy object spilling to
disk.
Fix: Increase object-store-memory on worker pods or restructure the
training loop to hold smaller intermediate objects (process in shards,
release references promptly) — spilling is a severe performance
degradation masquerading as "the job just got slow," not an error you'll
see surfaced anywhere by default.
Symptom: The Ray head pod is repeatedly OOM-killed or becomes
unresponsive under a workload with many concurrent actors/tasks, taking
the whole cluster down with it (all workers lose their GCS connection).
Fix: The head is a single point of failure for cluster-wide
scheduling state — give it adequate memory headroom independent of
worker sizing, and never schedule application training/serving
containers onto the head node group; keep headGroupSpec resources
sized for coordination overhead only.
Symptom: Ray's autoscaler requests worker pods up to
maxReplicas, but they sit Pending indefinitely because the
Kubernetes node-pool has no room and the cluster autoscaler either isn't
configured for this node pool or is slower than Ray's scheduling
patience, and Ray Tune trials appear to "hang" with no clear error.
Fix: Check kubectl get pods for Pending Ray worker pods and
kubectl describe them for scheduling failure reasons independent of
the Ray dashboard, which only shows Ray's view (pending resource
request) not the underlying Kubernetes scheduling failure reason; align
maxReplicas with actual node-pool capacity and verify the node
autoscaler is enabled for that pool.
Symptom: Ray Serve replicas configured with num_gpus=0.25 run fine
individually, but under concurrent load one replica's memory-heavy
request causes a CUDA OOM that crashes an unrelated model's replica
sharing the same physical GPU.
Fix: Fractional GPU allocation in Ray gives scheduling-level
accounting only, not memory isolation — this is the same tradeoff as
Kubernetes-level GPU time-slicing. For workloads needing hard isolation,
request whole GPUs per replica or move to Kubernetes MIG-partitioned
worker groups instead of Ray-level GPU fractions.
Scenario: A team distributes fine-tuning of a vision model across 4
GPU workers using Ray Train, submitted as a one-shot RayJob, then serves
the resulting model with Ray Serve using fractional GPU allocation for
cost efficiency.
RayJob for training:
apiVersion: ray.io/v1
kind: RayJob
metadata:
name: vision-finetune-2026-07-28
spec:
entrypoint: python finetune_vision_model.py --epochs 15 --checkpoint-uri s3://ml-artifacts/vision-model/run-214/
shutdownAfterJobFinishes: true
ttlSecondsAfterFinished: 600
rayClusterSpec:
rayVersion: "2.34.0"
headGroupSpec:
rayStartParams: {}
template:
spec:
containers:
- name: ray-head
image: registry.internal/ray-ml:2.34.0
resources: {requests: {cpu: "2", memory: 8Gi}, limits: {cpu: "2", memory: 8Gi}}
workerGroupSpecs:
- groupName: gpu-workers
replicas: 4
template:
spec:
nodeSelector: {gpu-pool: training}
tolerations:
- {key: workload, operator: Equal, value: training, effect: NoSchedule}
containers:
- name: ray-worker
image: registry.internal/ray-ml:2.34.0
resources:
requests: {cpu: "8", memory: 32Gi, nvidia.com/gpu: 1}
limits: {cpu: "8", memory: 32Gi, nvidia.com/gpu: 1}
finetune_vision_model.py (abbreviated):
from ray.train.torch import TorchTrainer
from ray.train import ScalingConfig, RunConfig
trainer = TorchTrainer(
train_loop_per_worker=train_loop_per_worker,
train_loop_config={"epochs": 15},
scaling_config=ScalingConfig(num_workers=4, use_gpu=True, resources_per_worker={"GPU": 1}),
run_config=RunConfig(storage_path="s3://ml-artifacts/vision-model/run-214/"),
)
result = trainer.fit()
Once the RayJob completes and the cluster shuts down, serve the
checkpoint with Ray Serve on a separate, long-lived serving RayCluster
using fractional GPUs:
@serve.deployment(ray_actor_options={"num_gpus": 0.5}, autoscaling_config={"min_replicas": 2, "max_replicas": 6})
class VisionClassifier:
def __init__(self):
self.model = load_checkpoint("s3://ml-artifacts/vision-model/run-214/")
async def __call__(self, request):
image = await request.body()
return {"label": self.model.predict(image)}
serve.run(VisionClassifier.bind(), name="vision-classifier")
Two VisionClassifier replicas fit per physical GPU at num_gpus=0.5,
doubling served throughput per GPU versus one replica per GPU, at the cost
of no hard memory isolation between them.
num_gpus) sit on top of.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
ray, kuberay, distributed-training, hyperparameter-tuning, model-serving, mlops
npx claudepluginhub selvarajmurugesan90/ops-engineering-skills --plugin mlops-skills22 skills in this plugin
/complete-mlops-platform-deployment-on-aws-from-scratchSequences a complete, end-to-end MLOps platform deployment on AWS from a bare AWS Organization to a production-ready platform serving a first retrained model — AWS landing zone, the SageMaker-vs-EKS+Kubeflow platform decision (EKS+Kubeflow is the worked path here), GPU node pools via the NVIDIA GPU Operator, MLflow experiment tracking on S3, a Kubeflow Pipelines retraining DAG, model registry/packaging with gated promotion, KServe canary/shadow serving, and drift monitoring. This is an integration/orchestration skill that sequences several existing tool-specific skills in the correct order and flags the handoff points between them — it does not restate their internals. Use when a user asks to "stand up an MLOps platform on AWS from scratch," "build the full ML training-to-serving pipeline on EKS/SageMaker," "give me the end-to-end sequence from AWS account to a retrained, monitored production model," or "decide between SageMaker and EKS+Kubeflow for our ML platform."
/complete-mlops-platform-deployment-on-azure-from-scratchSequences a complete, end-to-end MLOps platform deployment on Azure from a bare tenant to a production-ready platform serving a first retrained model — Azure landing zone, the Azure-ML-vs-AKS+Kubeflow platform decision (Azure ML is the worked path), GPU compute clusters/quota, MLflow-compatible experiment tracking, an Azure ML pipeline retraining DAG, Model Registry with gated promotion, managed online endpoints with traffic-split canary rollout, and data-drift monitoring. An integration/ orchestration skill that sequences existing tool-specific skills in the right order and flags handoff points — it does not restate their internals. Use when a user asks to "stand up an MLOps platform on Azure from scratch," "build the full ML training-to-serving pipeline on Azure ML/AKS," "give me the end-to-end sequence from Azure tenant to a retrained, monitored production model," or "decide between Azure ML and AKS+Kubeflow for our ML platform."
Other plugins' skills for the same job