-
Notifications
You must be signed in to change notification settings - Fork 594
Integration: KAI Scheduler #3886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EkinKarabulut
wants to merge
10
commits into
ray-project:master
Choose a base branch
from
EkinKarabulut:kai-integration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+444
−5
Open
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
13dc672
[KAI integration] Adding integration and example yamls
EkinKarabulut e80c426
Adding logs that indicates that the queue label is missing
EkinKarabulut fcbd27b
Adding tests for KAI Scheduler
EkinKarabulut 6032771
Changing Error message with Warning message
EkinKarabulut dfea787
Dividing queues and workload examples into different files for ease o…
EkinKarabulut e6634bb
Updating the image tag
EkinKarabulut 1a63219
[KAI integration] Fixing tests
EkinKarabulut cfe36e6
KAI integration: fixed pre-commit
EkinKarabulut 3c5b2f8
[KAI Integration] Comment and merge yaml files, pull logger into main…
EkinKarabulut 28b592d
[KAI Integration] improve yaml comments
EkinKarabulut File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
ray-operator/config/samples/ray-cluster.kai-gpu-sharing.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# KAI Scheduler Example - GPU Sharing with RayCluster | ||
# KAI Scheduler uses a hierarchical queue system for resource management and fair sharing. | ||
# These queues must be created before any RayCluster can be scheduled by KAI. | ||
|
||
# NOTE: This is a DEMO configuration with unlimited quotas (-1) for easy testing. | ||
# In real-world deployments, you should set appropriate CPU/GPU/memory quotas and limits | ||
# based on your cluster's actual resources and organizational needs. | ||
|
||
# GPU Sharing Note: This example utilizes time slicing GPU sharing. | ||
# KAI Scheduler also supports MPS and other GPU sharing methods. | ||
# For more information, check the KAI Scheduler documentation. | ||
|
||
# Parent queue: Represents a department or high-level organizational unit | ||
apiVersion: scheduling.run.ai/v2 | ||
kind: Queue | ||
metadata: | ||
name: department-1 | ||
spec: | ||
# priority: 100 # Optional: Higher priority queues get surplus resources first | ||
resources: | ||
cpu: | ||
quota: -1 # Unlimited quota (demo setting) | ||
limit: -1 # Unlimited burst limit (demo setting) | ||
overQuotaWeight: 1 # Determines how leftover (surplus) CPU resources are distributed among | ||
# queues that have the same priority. Higher weights receive larger portion | ||
gpu: | ||
quota: -1 # Unlimited quota (demo setting) | ||
limit: -1 # Unlimited burst limit (demo setting) | ||
overQuotaWeight: 1 # Share of surplus resources among same-priority queues | ||
memory: | ||
quota: -1 # Unlimited quota (demo setting) | ||
limit: -1 # Unlimited burst limit (demo setting) | ||
overQuotaWeight: 1 # Share of surplus resources among same-priority queues | ||
--- | ||
# Child queue: Represents a team within the department-1 | ||
apiVersion: scheduling.run.ai/v2 | ||
kind: Queue | ||
metadata: | ||
name: team-a | ||
spec: | ||
parentQueue: department-1 # Inherits from parent queue | ||
# priority: 50 # Optional: Team priority within department | ||
resources: | ||
cpu: | ||
quota: -1 # Unlimited quota (demo setting) | ||
limit: -1 # Unlimited burst limit (demo setting) | ||
overQuotaWeight: 1 # Determines how leftover (surplus) CPU resources are distributed among | ||
# queues that have the same priority. Higher weights receive larger portion | ||
gpu: | ||
quota: -1 # Unlimited quota (demo setting) | ||
limit: -1 # Unlimited burst limit (demo setting) | ||
overQuotaWeight: 1 # Share of surplus resources among same-priority queues | ||
memory: | ||
quota: -1 # Unlimited quota (demo setting) | ||
limit: -1 # Unlimited burst limit (demo setting) | ||
overQuotaWeight: 1 # Share of surplus resources among same-priority queues | ||
--- | ||
# RayCluster with KAI Scheduler and GPU Sharing | ||
apiVersion: ray.io/v1 | ||
kind: RayCluster | ||
metadata: | ||
name: raycluster-half-gpu | ||
labels: | ||
kai.scheduler/queue: team-a # REQUIRED: Queue assignment for scheduling | ||
spec: | ||
headGroupSpec: | ||
template: | ||
spec: | ||
containers: | ||
- name: head | ||
image: rayproject/ray:2.46.0 | ||
resources: | ||
limits: | ||
cpu: "1" | ||
memory: "2Gi" | ||
# ---- Two workers share one GPU (0.5 each) ---- | ||
workerGroupSpecs: | ||
- groupName: shared-gpu | ||
replicas: 2 | ||
minReplicas: 2 | ||
template: | ||
metadata: | ||
annotations: | ||
gpu-fraction: "0.5" # Request 0.5 GPU per pod (two pods share one GPU) | ||
spec: | ||
containers: | ||
- name: worker | ||
image: rayproject/ray:2.46.0 | ||
resources: | ||
limits: | ||
cpu: "1" | ||
memory: "2Gi" |
84 changes: 84 additions & 0 deletions
84
ray-operator/config/samples/ray-cluster.kai-scheduler.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# KAI Scheduler Example - Basic RayCluster | ||
# KAI Scheduler uses a hierarchical queue system for resource management and fair sharing. | ||
# These queues must be created before any RayCluster can be scheduled by KAI. | ||
|
||
# NOTE: This is a DEMO configuration with unlimited quotas (-1) for easy testing. | ||
# In real-world deployments, you should set appropriate CPU/GPU/memory quotas and limits | ||
# based on your cluster's actual resources and organizational needs. | ||
|
||
# Parent queue: Represents a department or high-level organizational unit | ||
apiVersion: scheduling.run.ai/v2 | ||
kind: Queue | ||
metadata: | ||
name: department-1 | ||
spec: | ||
# priority: 100 # Optional: Higher priority queues get surplus resources first | ||
resources: | ||
cpu: | ||
quota: -1 # Unlimited quota (demo setting) | ||
limit: -1 # Unlimited burst limit (demo setting) | ||
overQuotaWeight: 1 # Determines how leftover (surplus) CPU resources are distributed among | ||
# queues that have the same priority. Higher weights receive larger portion | ||
gpu: | ||
quota: -1 # Unlimited quota (demo setting) | ||
limit: -1 # Unlimited burst limit (demo setting) | ||
overQuotaWeight: 1 # Share of surplus resources among same-priority queues | ||
memory: | ||
quota: -1 # Unlimited quota (demo setting) | ||
limit: -1 # Unlimited burst limit (demo setting) | ||
overQuotaWeight: 1 # Share of surplus resources among same-priority queues | ||
--- | ||
# Child queue: Represents a team within the department-1 | ||
apiVersion: scheduling.run.ai/v2 | ||
kind: Queue | ||
metadata: | ||
name: team-a | ||
spec: | ||
parentQueue: department-1 # Inherits from parent queue | ||
# priority: 50 # Optional: Team priority within department | ||
resources: | ||
cpu: | ||
quota: -1 # Unlimited quota (demo setting) | ||
limit: -1 # Unlimited burst limit (demo setting) | ||
overQuotaWeight: 1 # Determines how leftover (surplus) CPU resources are distributed among | ||
# queues that have the same priority. Higher weights receive larger portion | ||
gpu: | ||
quota: -1 # Unlimited quota (demo setting) | ||
limit: -1 # Unlimited burst limit (demo setting) | ||
overQuotaWeight: 1 # Share of surplus resources among same-priority teams | ||
memory: | ||
quota: -1 # Unlimited quota (demo setting) | ||
limit: -1 # Unlimited burst limit (demo setting) | ||
overQuotaWeight: 1 # Share of surplus resources among same-priority teams | ||
--- | ||
# RayCluster with KAI Scheduler | ||
apiVersion: ray.io/v1 | ||
kind: RayCluster | ||
metadata: | ||
name: raycluster-sample | ||
labels: | ||
kai.scheduler/queue: team-a # REQUIRED: Queue assignment for scheduling | ||
spec: | ||
headGroupSpec: | ||
template: | ||
spec: | ||
containers: | ||
- name: ray-head | ||
image: rayproject/ray:2.46.0 | ||
resources: | ||
requests: | ||
cpu: "1" | ||
memory: "2Gi" | ||
workerGroupSpecs: | ||
- groupName: worker | ||
replicas: 2 | ||
minReplicas: 2 | ||
template: | ||
spec: | ||
containers: | ||
- name: ray-worker | ||
image: rayproject/ray:2.46.0 | ||
resources: | ||
requests: | ||
cpu: "1" | ||
memory: "1Gi" |
70 changes: 70 additions & 0 deletions
70
ray-operator/controllers/ray/batchscheduler/kai-scheduler/kai_scheduler.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package kaischeduler | ||
|
||
// This KAI plugin relies on KAI-Scheduler's | ||
EkinKarabulut marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// built-in PodGrouper to create PodGroups at | ||
// runtime, so the plugin itself only needs to: | ||
// 1. expose the scheduler name, | ||
// 2. stamp pods with schedulerName + queue label. | ||
// No PodGroup create/patch logic is included. | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/go-logr/logr" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/client-go/rest" | ||
"sigs.k8s.io/controller-runtime/pkg/builder" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
|
||
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1" | ||
schedulerinterface "github.com/ray-project/kuberay/ray-operator/controllers/ray/batchscheduler/interface" | ||
) | ||
|
||
const ( | ||
QueueLabelName = "kai.scheduler/queue" | ||
) | ||
|
||
type KaiScheduler struct { | ||
log logr.Logger | ||
} | ||
|
||
type KaiSchedulerFactory struct{} | ||
|
||
func GetPluginName() string { return "kai-scheduler" } | ||
|
||
func (k *KaiScheduler) Name() string { return GetPluginName() } | ||
|
||
func (k *KaiScheduler) DoBatchSchedulingOnSubmission(_ context.Context, _ *rayv1.RayCluster) error { | ||
return nil | ||
} | ||
|
||
func (k *KaiScheduler) AddMetadataToPod(_ context.Context, app *rayv1.RayCluster, _ string, pod *corev1.Pod) { | ||
pod.Spec.SchedulerName = k.Name() | ||
|
||
queue, ok := app.Labels[QueueLabelName] | ||
if !ok || queue == "" { | ||
k.log.Info("Queue label missing from RayCluster; pods will remain pending", | ||
"requiredLabel", QueueLabelName, | ||
"rayCluster", app.Name) | ||
return | ||
} | ||
if pod.Labels == nil { | ||
pod.Labels = make(map[string]string) | ||
} | ||
pod.Labels[QueueLabelName] = queue | ||
} | ||
|
||
func (kf *KaiSchedulerFactory) New(_ context.Context, _ *rest.Config, _ client.Client) (schedulerinterface.BatchScheduler, error) { | ||
EkinKarabulut marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return &KaiScheduler{ | ||
log: logf.Log.WithName("kai-scheduler"), | ||
}, nil | ||
} | ||
|
||
func (kf *KaiSchedulerFactory) AddToScheme(_ *runtime.Scheme) { | ||
} | ||
|
||
func (kf *KaiSchedulerFactory) ConfigureReconciler(b *builder.Builder) *builder.Builder { | ||
return b | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you share what the Pod looks like after it's created, using
kubectl describe pod ...
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we go: