Ray Compatibility Guide
Use this skill when implementing, migrating, or reviewing Ray Core, Data, Train,
Tune, Serve, RLlib, or KubeRay code. Ray's components evolve independently, so
inspect the project's package, image, chart, and custom-resource versions before
applying guidance. Prefer the project's manifests, code, tests, and observed
runtime behavior when they disagree with general compatibility advice.
Reference index
| Reference |
Topics |
| Core tasks and actors |
Typed actor handles, cancellation, task events, GCS storage, topology scheduling, lifecycle, actor extensions |
| Data execution |
Streaming boundaries, batches, worker pools, ordering, placement groups, expressions, data sources, conversions, migrations |
| Train and API lifecycle |
Train V2, dataset sharding, labeled subclusters, checkpoint metadata, backpressure, logging, restore behavior, API stability, RLlib validation |
| Tune scheduling |
Result emission, open-ended sampling, scheduler constraints, changing resources, search integrations |
| Serve runtime and recovery |
Deployment-response pipelining, recovery, controller outages, REST management, custom routing, direct ingress, LLM routing |
| KubeRay jobs and services |
RayCluster bootstrap, RayJob modes, retries, deadlines, cleanup, RayService endpoints |
Compatibility hazards first
Migrate Train deliberately
- Train V2 is opt-in from Ray 2.43 with
RAY_TRAIN_V2_ENABLED=1; do not assume V1 imports or helpers have direct V2
equivalents.
- The separate V1 reference is deprecated, and V1
Predictor is removed in
newer Ray releases.
ray.train.report(checkpoint=...) accepts only in-band checkpoints, and
Result.from_path is read-only.
- A
DataParallelTrainer function may return data; use LoggingConfig for
controller and worker ray.train logging.
Update Ray Data migrations
- Ray 2.57 enables DataSource V2 by default for readers such as
read_parquet, changing listing and scanning to the V2 path.
- Expression filters use
compute=; concurrency= is deprecated.
- Deprecated surfaces include
ConcurrencyCapBackpressurePolicy,
DataIterator.to_torch, pandas UDF batches,
DataContext.scheduling_strategy, actor_locality_enabled,
exclude_resources, and local://.
read_tfrecords no longer supports tfx-bsl, and autoscaler v1 is removed.
read_numpy defaults to allow_pickle=False; write_lance(mode=CREATE)
now errors rather than overwriting.
Check Serve ingress compatibility
- Use
HTTPOptions.proxy_location instead of deprecated location.
- A nonzero
HTTPOptions.num_cpus is an error.
- Direct ingress rejects an ingress deployment that also uses a custom request
router or
serve.multiplexed.
- HAProxy ingress uses the separately distributed
ray-haproxy package as its
default binary in Ray 2.57.
- Full KV-cache-aware routing is deferred beyond Ray 2.57 even though
KVAwareRouter and KVRouterActor interfaces are present experimentally.
Validate strict integrations
OptunaSearch requires optuna>=3.0.0.
MultiRLModuleSpec.rl_module_specs must be a dictionary.
- KubeRay rules-based cleanup cannot be combined with
shutdownAfterJobFinishes or the global ttlSecondsAfterFinished; the older
onSuccess and onFailure cleanup style is deprecated.
Core tasks and actors
Preserve actor method types
Keep the implementation class undecorated, mark its remote methods with
@ray.method, wrap the class with ray.remote(), and annotate the wrapper and
handle as ActorClass[T] and ActorProxy[T]. A typed method returning R
then exposes .remote() as ObjectRef[R].
Cancel according to execution model
ray.cancel() is best-effort. Cancelling an unscheduled actor task causes
ray.get() to raise TaskCancelledError.
- Running regular and threaded actor methods are not interrupted; they must
poll
ray.get_runtime_context().is_canceled() and clean up cooperatively.
- Async actor methods receive
asyncio.Task cancellation at an await.
Calling is_canceled() inside one raises RuntimeError.
recursive=True also targets tracked child and actor tasks.
Control task-event visibility
Set enable_task_events=False on a remote function or actor to suppress
Dashboard and State API status and profiling events. Nested tasks do not inherit
the parent's setting. A method-level setting overrides its actor's setting.
Ray Data execution
Know the streaming boundary
Lazy non-shuffle operators can overlap as a streaming pipeline after
consumption begins. sort() and groupby() materialize their inputs, so
streaming stops until the shuffle completes.
Select batches and worker pools
map_batches(batch_size="auto") enables automatic sizing, but a GPU
transform needs an explicit integer. Reduce it on worker out-of-memory errors.
- Functions execute as tasks and can use
TaskPoolStrategy(size=n).
- Callable classes execute as actors, run
__init__ once per worker, and use
an autoscaling actor pool unless a fixed ActorPoolStrategy is supplied.
memory, num_cpus, and num_gpus are logical scheduling resources, not
enforced physical limits.
Preserve order only when required
Transforms do not preserve block order by default. Sorting or setting
DataContext.get_current().execution_options.preserve_order = True preserves
order but can reduce throughput when workers finish unevenly.
Treat advanced transform APIs carefully
- Give every class-based distributed-model replica its own placement group via
ray_remote_args_fn; enable child-task capture to keep internally launched
tasks and actors in that group.
- Async transforms must be callable classes with
async def __call__; function
transforms are unsupported, and the feature requires uvloop==0.21.0.
- Column expressions are alpha. Build them with
col(), lit(), and
with_column(); vectorized expression UDFs operate on PyArrow arrays and must
declare return_dtype.
Ray Train data flow
Choose which datasets to shard
Train normally calls Dataset.streaming_split() for every dataset. Set
DataConfig(datasets_to_split=[...]) to shard only selected datasets. Each
worker sees a full unlisted validation dataset; aggregate validation results
across workers when that dataset is split.
Pin construction and ingestion separately
To target a labeled subcluster, construct the Dataset under a copied
DataContext with execution_options.label_selector, then repeat the selector
in DataConfig.execution_options. Train replaces Dataset execution options for
ingestion, so the construction-time selector alone is insufficient.
Keep preprocessors with checkpoints
Fit preprocessing before constructing the Trainer. Serialize the fitted
preprocessor, encode the bytes for JSON-compatible Trainer metadata, and read
it through TrainContext.get_metadata() or checkpoint metadata when restoring.
Set per-Dataset ExecutionResources(object_store_memory=...) limits to apply
object-store backpressure when producers could outrun training consumers.
Tune trials and schedulers
Emit results correctly
A function trainable may call tune.report() for intermediate metrics, return
one final dictionary, or yield successive dictionaries. Do not call
tune.report() from a class-based Trainable.
For wall-clock-bounded open-ended sampling, combine num_samples=-1 with
time_budget_s; a finite sample count remains a hard trial cap.
Match scheduler requirements
| Scheduler |
Checkpointing |
Search algorithm compatibility |
| ASHA, Median Stopping |
Not required |
Compatible |
| HyperBand |
Required |
Compatible |
| BOHB |
Required |
TuneBOHB only |
| PBT, PB2 |
Required |
Incompatible |
Wrap another scheduler with ResourceChangingScheduler when trial resource
requirements must change during tuning.
Serve composition and recovery
Pass a DeploymentResponse directly into another deployment-handle call to
pipeline composed deployments without materializing intermediate values. Await
the response only where the local value is needed.
- Application exceptions return HTTP 500 with traceback information but do not
kill the replica.
- Serve replaces failed replicas, proxies, and the controller, restoring routing
and deployment state from the GCS. Transient connections and internal request
queues are not restored.
- HTTP, gRPC, and handle traffic can continue while the controller is down, but
autoscaling pauses and resumes without outage-period metrics.
- Entire-cluster recovery is a KubeRay concern.
KubeRay operations
- A
RayJob can embed rayClusterSpec or select an existing cluster with
clusterSelector; its entrypoint is submitted after readiness.
K8sJobMode is the default. HTTPMode, alpha InteractiveMode, and
SidecarMode have distinct submitter behavior and constraints.
- Top-level
backoffLimit retries with a new RayCluster; the separately scoped
submitterConfig.backoffLimit retries the submitter Job.
preRunningDeadlineSeconds bounds reaching Running;
activeDeadlineSeconds bounds reaching a terminal job state.
shutdownAfterJobFinishes defaults to false, and
ttlSecondsAfterFinished applies only when shutdown is enabled.
- A ready
RayService exposes Dashboard access through its head service on
port 8265 and Serve HTTP traffic through its Serve service on port 8000.
Use the linked references for exact examples, option interactions, lifecycle
semantics, and the remaining component-specific guidance.
1---2name: ray-knowledge-patch-23description: Ray4license: MIT5---678# Ray Compatibility Guide910Use this skill when implementing, migrating, or reviewing Ray Core, Data, Train,11Tune, Serve, RLlib, or KubeRay code. Ray's components evolve independently, so12inspect the project's package, image, chart, and custom-resource versions before13applying guidance. Prefer the project's manifests, code, tests, and observed14runtime behavior when they disagree with general compatibility advice.1516## Reference index1718| Reference | Topics |19| --- | --- |20| [Core tasks and actors](references/core-tasks-and-actors.md) | Typed actor handles, cancellation, task events, GCS storage, topology scheduling, lifecycle, actor extensions |21| [Data execution](references/data-execution.md) | Streaming boundaries, batches, worker pools, ordering, placement groups, expressions, data sources, conversions, migrations |22| [Train and API lifecycle](references/train-and-api-lifecycle.md) | Train V2, dataset sharding, labeled subclusters, checkpoint metadata, backpressure, logging, restore behavior, API stability, RLlib validation |23| [Tune scheduling](references/tune-scheduling.md) | Result emission, open-ended sampling, scheduler constraints, changing resources, search integrations |24| [Serve runtime and recovery](references/serve-runtime-and-recovery.md) | Deployment-response pipelining, recovery, controller outages, REST management, custom routing, direct ingress, LLM routing |25| [KubeRay jobs and services](references/kuberay-jobs-and-services.md) | RayCluster bootstrap, RayJob modes, retries, deadlines, cleanup, RayService endpoints |2627## Compatibility hazards first2829### Migrate Train deliberately3031- Train V2 is opt-in from Ray 2.43 with32 `RAY_TRAIN_V2_ENABLED=1`; do not assume V1 imports or helpers have direct V233 equivalents.34- The separate V1 reference is deprecated, and V1 `Predictor` is removed in35 newer Ray releases.36- `ray.train.report(checkpoint=...)` accepts only in-band checkpoints, and37 `Result.from_path` is read-only.38- A `DataParallelTrainer` function may return data; use `LoggingConfig` for39 controller and worker `ray.train` logging.4041### Update Ray Data migrations4243- Ray 2.57 enables DataSource V2 by default for readers such as44 `read_parquet`, changing listing and scanning to the V2 path.45- Expression filters use `compute=`; `concurrency=` is deprecated.46- Deprecated surfaces include `ConcurrencyCapBackpressurePolicy`,47 `DataIterator.to_torch`, pandas UDF batches,48 `DataContext.scheduling_strategy`, `actor_locality_enabled`,49 `exclude_resources`, and `local://`.50- `read_tfrecords` no longer supports `tfx-bsl`, and autoscaler v1 is removed.51- `read_numpy` defaults to `allow_pickle=False`; `write_lance(mode=CREATE)`52 now errors rather than overwriting.5354### Check Serve ingress compatibility5556- Use `HTTPOptions.proxy_location` instead of deprecated `location`.57- A nonzero `HTTPOptions.num_cpus` is an error.58- Direct ingress rejects an ingress deployment that also uses a custom request59 router or `serve.multiplexed`.60- HAProxy ingress uses the separately distributed `ray-haproxy` package as its61 default binary in Ray 2.57.62- Full KV-cache-aware routing is deferred beyond Ray 2.57 even though63 `KVAwareRouter` and `KVRouterActor` interfaces are present experimentally.6465### Validate strict integrations6667- `OptunaSearch` requires `optuna>=3.0.0`.68- `MultiRLModuleSpec.rl_module_specs` must be a dictionary.69- KubeRay rules-based cleanup cannot be combined with70 `shutdownAfterJobFinishes` or the global `ttlSecondsAfterFinished`; the older71 `onSuccess` and `onFailure` cleanup style is deprecated.7273## Core tasks and actors7475### Preserve actor method types7677Keep the implementation class undecorated, mark its remote methods with78`@ray.method`, wrap the class with `ray.remote()`, and annotate the wrapper and79handle as `ActorClass[T]` and `ActorProxy[T]`. A typed method returning `R`80then exposes `.remote()` as `ObjectRef[R]`.8182### Cancel according to execution model8384- `ray.cancel()` is best-effort. Cancelling an unscheduled actor task causes85 `ray.get()` to raise `TaskCancelledError`.86- Running regular and threaded actor methods are not interrupted; they must87 poll `ray.get_runtime_context().is_canceled()` and clean up cooperatively.88- Async actor methods receive `asyncio.Task` cancellation at an `await`.89 Calling `is_canceled()` inside one raises `RuntimeError`.90- `recursive=True` also targets tracked child and actor tasks.9192### Control task-event visibility9394Set `enable_task_events=False` on a remote function or actor to suppress95Dashboard and State API status and profiling events. Nested tasks do not inherit96the parent's setting. A method-level setting overrides its actor's setting.9798## Ray Data execution99100### Know the streaming boundary101102Lazy non-shuffle operators can overlap as a streaming pipeline after103consumption begins. `sort()` and `groupby()` materialize their inputs, so104streaming stops until the shuffle completes.105106### Select batches and worker pools107108- `map_batches(batch_size="auto")` enables automatic sizing, but a GPU109 transform needs an explicit integer. Reduce it on worker out-of-memory errors.110- Functions execute as tasks and can use `TaskPoolStrategy(size=n)`.111- Callable classes execute as actors, run `__init__` once per worker, and use112 an autoscaling actor pool unless a fixed `ActorPoolStrategy` is supplied.113- `memory`, `num_cpus`, and `num_gpus` are logical scheduling resources, not114 enforced physical limits.115116### Preserve order only when required117118Transforms do not preserve block order by default. Sorting or setting119`DataContext.get_current().execution_options.preserve_order = True` preserves120order but can reduce throughput when workers finish unevenly.121122### Treat advanced transform APIs carefully123124- Give every class-based distributed-model replica its own placement group via125 `ray_remote_args_fn`; enable child-task capture to keep internally launched126 tasks and actors in that group.127- Async transforms must be callable classes with `async def __call__`; function128 transforms are unsupported, and the feature requires `uvloop==0.21.0`.129- Column expressions are alpha. Build them with `col()`, `lit()`, and130 `with_column()`; vectorized expression UDFs operate on PyArrow arrays and must131 declare `return_dtype`.132133## Ray Train data flow134135### Choose which datasets to shard136137Train normally calls `Dataset.streaming_split()` for every dataset. Set138`DataConfig(datasets_to_split=[...])` to shard only selected datasets. Each139worker sees a full unlisted validation dataset; aggregate validation results140across workers when that dataset is split.141142### Pin construction and ingestion separately143144To target a labeled subcluster, construct the Dataset under a copied145`DataContext` with `execution_options.label_selector`, then repeat the selector146in `DataConfig.execution_options`. Train replaces Dataset execution options for147ingestion, so the construction-time selector alone is insufficient.148149### Keep preprocessors with checkpoints150151Fit preprocessing before constructing the Trainer. Serialize the fitted152preprocessor, encode the bytes for JSON-compatible Trainer `metadata`, and read153it through `TrainContext.get_metadata()` or checkpoint metadata when restoring.154155Set per-Dataset `ExecutionResources(object_store_memory=...)` limits to apply156object-store backpressure when producers could outrun training consumers.157158## Tune trials and schedulers159160### Emit results correctly161162A function trainable may call `tune.report()` for intermediate metrics, return163one final dictionary, or yield successive dictionaries. Do not call164`tune.report()` from a class-based `Trainable`.165166For wall-clock-bounded open-ended sampling, combine `num_samples=-1` with167`time_budget_s`; a finite sample count remains a hard trial cap.168169### Match scheduler requirements170171| Scheduler | Checkpointing | Search algorithm compatibility |172| --- | --- | --- |173| ASHA, Median Stopping | Not required | Compatible |174| HyperBand | Required | Compatible |175| BOHB | Required | `TuneBOHB` only |176| PBT, PB2 | Required | Incompatible |177178Wrap another scheduler with `ResourceChangingScheduler` when trial resource179requirements must change during tuning.180181## Serve composition and recovery182183Pass a `DeploymentResponse` directly into another deployment-handle call to184pipeline composed deployments without materializing intermediate values. Await185the response only where the local value is needed.186187- Application exceptions return HTTP 500 with traceback information but do not188 kill the replica.189- Serve replaces failed replicas, proxies, and the controller, restoring routing190 and deployment state from the GCS. Transient connections and internal request191 queues are not restored.192- HTTP, gRPC, and handle traffic can continue while the controller is down, but193 autoscaling pauses and resumes without outage-period metrics.194- Entire-cluster recovery is a KubeRay concern.195196## KubeRay operations197198- A `RayJob` can embed `rayClusterSpec` or select an existing cluster with199 `clusterSelector`; its entrypoint is submitted after readiness.200- `K8sJobMode` is the default. `HTTPMode`, alpha `InteractiveMode`, and201 `SidecarMode` have distinct submitter behavior and constraints.202- Top-level `backoffLimit` retries with a new RayCluster; the separately scoped203 `submitterConfig.backoffLimit` retries the submitter Job.204- `preRunningDeadlineSeconds` bounds reaching `Running`;205 `activeDeadlineSeconds` bounds reaching a terminal job state.206- `shutdownAfterJobFinishes` defaults to false, and207 `ttlSecondsAfterFinished` applies only when shutdown is enabled.208- A ready `RayService` exposes Dashboard access through its head service on209 port 8265 and Serve HTTP traffic through its Serve service on port 8000.210211Use the linked references for exact examples, option interactions, lifecycle212semantics, and the remaining component-specific guidance.