22from typing_extensions import Literal
33
44from clipped .compact .pydantic import Field
5- from clipped .types .ref_or_obj import RefField
5+ from clipped .types .ref_or_obj import BoolOrRef , RefField
66
77from polyaxon ._flow .run .base import BaseRun
88from polyaxon ._flow .run .enums import V1RunKind
9+ from polyaxon ._flow .run .ray .autoscaler import V1RayAutoscalerOptions
910from polyaxon ._flow .run .ray .replica import V1RayReplica
1011from polyaxon ._flow .run .resources import V1RunResources
1112from polyaxon ._flow .run .utils import DestinationImageMixin
@@ -27,6 +28,8 @@ class V1RayCluster(BaseRun, DestinationImageMixin):
2728 ray_version: str, optional
2829 head: [V1RayReplica](/docs/experimentation/distributed/ray-replica/), optional
2930 workers: Dict[str, [V1RayReplica](/docs/experimentation/distributed/ray-replica/)], optional
31+ enable_in_tree_autoscaling: bool, optional
32+ autoscaler_options: [V1RayAutoscalerOptions](/docs/experimentation/distributed/ray-autoscaler/), optional
3033
3134
3235 ## YAML usage
@@ -40,6 +43,8 @@ class V1RayCluster(BaseRun, DestinationImageMixin):
4043 >>> rayVersion:
4144 >>> head:
4245 >>> workers:
46+ >>> enableInTreeAutoscaling:
47+ >>> autoscalerOptions:
4348 ```
4449
4550 ## Python usage
@@ -52,6 +57,7 @@ class V1RayCluster(BaseRun, DestinationImageMixin):
5257 >>> ray_version="2.5.0",
5358 >>> head=V1RayReplica(...),
5459 >>> worker=V1RayReplica(...),
60+ >>> enable_in_tree_autoscaling=True,
5561 >>> )
5662 ```
5763
@@ -132,10 +138,42 @@ class V1RayCluster(BaseRun, DestinationImageMixin):
132138 >>> ...
133139 >>> ...
134140 ```
141+
142+ ### enableInTreeAutoscaling
143+
144+ Enable the KubeRay in-tree autoscaler for automatic worker scaling.
145+ When enabled, the Ray autoscaler will automatically scale workers based on workload demands.
146+
147+ > **Note**: The `idleTimeoutSeconds` for the autoscaler is derived from `termination.culling.timeout`.
148+
149+ ```yaml
150+ >>> run:
151+ >>> kind: raycluster
152+ >>> enableInTreeAutoscaling: true
153+ >>> workers:
154+ >>> gpu-workers:
155+ >>> minReplicas: 0
156+ >>> maxReplicas: 10
157+ >>> ...
158+ ```
159+
160+ ### autoscalerOptions
161+
162+ Optional configuration for the Ray autoscaler behavior.
163+
164+ ```yaml
165+ >>> run:
166+ >>> kind: raycluster
167+ >>> enableInTreeAutoscaling: true
168+ >>> autoscalerOptions:
169+ >>> upscalingMode: Default
170+ >>> imagePullPolicy: IfNotPresent
171+ >>> ...
172+ ```
135173 """
136174
137175 _IDENTIFIER = V1RunKind .RAYCLUSTER
138- _CUSTOM_DUMP_FIELDS = {"head" , "workers" }
176+ _CUSTOM_DUMP_FIELDS = {"head" , "workers" , "autoscaler_options" }
139177 _FIELDS_DICT_PATCH = ["workers" ]
140178
141179 kind : Literal [_IDENTIFIER ] = _IDENTIFIER
@@ -147,6 +185,12 @@ class V1RayCluster(BaseRun, DestinationImageMixin):
147185 ray_version : Optional [str ] = Field (alias = "rayVersion" , default = None )
148186 head : Optional [Union [V1RayReplica , RefField ]] = None
149187 workers : Optional [Dict [str , Union [V1RayReplica , RefField ]]] = Field (default = None )
188+ enable_in_tree_autoscaling : Optional [BoolOrRef ] = Field (
189+ alias = "enableInTreeAutoscaling" , default = None
190+ )
191+ autoscaler_options : Optional [Union [V1RayAutoscalerOptions , RefField ]] = Field (
192+ alias = "autoscalerOptions" , default = None
193+ )
150194
151195 def apply_image_destination (self , image : str ):
152196 if self .head :
0 commit comments