acoustic-carpenter-78188
11/06/2023, 12:09 AMimport typing
import ray
from flytekitplugins.ray import HeadNodeConfig, RayJobConfig, WorkerNodeConfig
from flytekit import Resources, task, workflow
@ray.remote
def f(x):
return x * x
ray_config = RayJobConfig(
head_node_config=HeadNodeConfig(ray_start_params={"log-color": "True"}),
# The behavior will be:
# 1. Create a head node and a worker node.
# 2. The worker node will be scaled to 2.
# 3. The worker node will be scaled to 0.
worker_node_config=[WorkerNodeConfig(group_name="ray-group", replicas=1, min_replicas=0, max_replicas=2)],
enable_in_tree_autoscaling=True,
)
@task(
task_config=ray_config,
requests=Resources(mem="1Gi", cpu="2"),
)
def ray_task() -> int:
import time
# Import placement group APIs.
from ray.util.placement_group import (
placement_group,
placement_group_table,
remove_placement_group,
)
from ray.util.scheduling_strategies import PlacementGroupSchedulingStrategy
# use the `placement_group` to trigger autoscaling.
# each node have two cpus, so this will create 2 workers when executing.
# Once the task is done, the two workers will be removed.
pg = placement_group([{"CPU": 2} for i in range(3)])
ray.get(pg.ready(), timeout=50)
return 1
@workflow
def ray_workflow() -> int:
return ray_task()
init(replicas=1):
(flytekit) ubuntu@ip-172-31-92-18:~/flytekit$ kubectl get pod -n flytesnacks-development
NAME READY STATUS RESTARTS AGE
f2067d40c9d134daaa6f-n0-0-raycluster-k4klf-head-vgq9z 2/2 Running 0 7s
d134daaa6f-n0-0-raycluster-k4klf-worker-ray-group-wdtqq 1/1 Running 0 7s
task executing(max_replicas=2):
(flytekit) ubuntu@ip-172-31-92-18:~/flytekit$ kubectl get pod -n flytesnacks-development
NAME READY STATUS RESTARTS AGE
f2067d40c9d134daaa6f-n0-0-raycluster-k4klf-head-vgq9z 2/2 Running 0 18s
d134daaa6f-n0-0-raycluster-k4klf-worker-ray-group-wdtqq 1/1 Running 0 18s
d134daaa6f-n0-0-raycluster-k4klf-worker-ray-group-tqg7n 0/1 PodInitializing 0 4s
after(min_replicas=0):
(flytekit) ubuntu@ip-172-31-92-18:~/flytekit$ kubectl get pod -n flytesnacks-development
NAME READY STATUS RESTARTS AGE
f2067d40c9d134daaa6f-n0-0-raycluster-k4klf-head-vgq9z 2/2 Running 0 2m57s
Type
☐ Bug Fix
☐ Feature
☐ Plugin
Are all requirements met?
☐ Code completed
☐ Smoke tested
☐ Unit tests added
☐ Code documentation added
☐ Any pending items have an associated Issue
Complete description
How did you fix the bug, make the feature etc. Link to any design docs etc
Tracking Issue
flyteorg/flyte#4187
Follow-up issue
NA
OR
https://github.com/flyteorg/flyte/issues/
flyteorg/flytekit
Codecov: 62.57% (-0.25%) compared to 63e6632
GitHub Actions: build-plugins (3.8, flytekit-snowflake)
✅ 28 other checks have passed
28/30 successful checks