Skip to content

SubGroupPolicy enables optimized Kthena subgroup-based Gang Scheduling - #4785

Merged
volcano-sh-bot merged 6 commits into
volcano-sh:masterfrom
wangyang0616:feature_subgroup_update
Dec 15, 2025
Merged

SubGroupPolicy enables optimized Kthena subgroup-based Gang Scheduling #4785
volcano-sh-bot merged 6 commits into
volcano-sh:masterfrom
wangyang0616:feature_subgroup_update

Conversation

@wangyang0616

@wangyang0616 wangyang0616 commented Dec 8, 2025

Copy link
Copy Markdown
Member

Fixes #4781
Related Apis #202

  1. After optimizing SubGroupPolicy, update the grouping configuration and label configuration of Volcano Job during Pod creation to align with the policy;
  2. Optimize the PodGroup grouping logic to match the updated SubGroupPolicy rules.

@volcano-sh-bot volcano-sh-bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Dec 8, 2025
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @wangyang0616, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly advances Volcano's Gang Scheduling capabilities by introducing a more sophisticated SubGroupPolicy mechanism. It transitions from basic label matching to a powerful LabelSelector and MatchLabelKeys system, enabling users to define intricate pod grouping rules for optimized resource allocation and network topology management. The changes encompass updates to API definitions, internal data structures, and controller logic, ensuring robust and seamless operation of the new subgroup-based scheduling. Additionally, it enhances scheduling flexibility by introducing a configurable dequeue strategy for queues.

Highlights

  • Enhanced SubGroupPolicy API: The PodGroup Custom Resource Definition (CRD) has been updated to replace the simpler MatchPolicy with a more robust LabelSelector and MatchLabelKeys. This provides greater flexibility and power in defining how pods are grouped for subgroup-based Gang Scheduling.
  • Optimized Pod Grouping Logic: The internal logic responsible for grouping pods within a PodGroup has been refactored to align with the new SubGroupPolicy definition. This ensures that network topology and Gang scheduling rules are applied correctly and efficiently based on the enhanced grouping criteria.
  • Updated Pod Labeling for Partitions: Pods are now consistently labeled with volcano.sh/task-name and volcano.sh/task-partition-id based on the PartitionPolicy and PartitionSize. This replaces older, less flexible labeling schemes and improves clarity and consistency in identifying pod partitions.
  • New Queue Dequeue Strategy: A dequeueStrategy field has been introduced to the Queue CRD, allowing users to specify either fifo (First-In, First-Out) or traverse for queue management. The default strategy is traverse, offering more control over how jobs are processed from the queue.
  • API Dependency Update: The project's dependency on volcano.sh/apis has been updated to incorporate the new API definitions related to SubGroupPolicy and Queue dequeue strategies, ensuring compatibility with the latest features.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@wangyang0616 wangyang0616 changed the title SubGroupPolicy enables optimized Kthena subgroup-based Gang Scheduling [WIP]SubGroupPolicy enables optimized Kthena subgroup-based Gang Scheduling Dec 8, 2025
@volcano-sh-bot volcano-sh-bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 8, 2025

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request significantly improves the SubGroupPolicy API by aligning it with standard Kubernetes practices using LabelSelector, which is a great enhancement. The refactoring of the test suite is also a major improvement in code quality and maintainability.

I've identified a few issues that need attention:

  1. A critical issue with the go.mod file pointing to a personal fork, which must be addressed before merging.
  2. A potential bug in getSubJobMatchValues where it returns an empty slice instead of nil for non-matching pods, which could break existing logic.
  3. An inconsistency in the Clone method in job_info.go where Partitions are not correctly deep-copied.
  4. A minor issue with a misleading comment in a test case.

Overall, this is a valuable contribution. Addressing these points will make it even better.

Comment thread go.mod Outdated
Comment thread pkg/scheduler/api/sub_job_info.go
Comment thread pkg/controllers/apis/job_info.go
name: "partition size 0 (invalid), index 5",
partitionSize: 0,
index: 5,
expectedPart: "-1", // Go returns 0 for division by zero

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The comment // Go returns 0 for division by zero is incorrect. In Go, integer division by zero causes a runtime panic. The code in createJobPod correctly handles this edge case by checking if ts.PartitionPolicy.PartitionSize <= 0 and setting partitionID to -1, which is what this test case correctly asserts. The comment is misleading and should be removed or corrected to reflect the actual behavior.

Suggested change
expectedPart: "-1", // Go returns 0 for division by zero
expectedPart: "-1",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@wangyang0616 wangyang0616 changed the title [WIP]SubGroupPolicy enables optimized Kthena subgroup-based Gang Scheduling SubGroupPolicy enables optimized Kthena subgroup-based Gang Scheduling Dec 9, 2025
@volcano-sh-bot volcano-sh-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 9, 2025
@wangyang0616
wangyang0616 force-pushed the feature_subgroup_update branch 4 times, most recently from 30a1c2f to 87d0fd9 Compare December 11, 2025 02:52
Comment thread pkg/scheduler/api/sub_job_info_test.go Outdated
MatchLabelKeys: []string{"any"},
},
pod: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{}, // 无标签

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete the Chinese comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread pkg/scheduler/api/sub_job_info_test.go Outdated
{
LabelKey: "key2",
Key: "app",
Operator: "invalid", // 无效的操作符

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. Please check all the Chinese comments if we don't need it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@JesseStutler

JesseStutler commented Dec 11, 2025

Copy link
Copy Markdown
Member

Just want to verify that does this PR means that the pods must first match the labelSelector, and then be divided into different groups based on different keys? @wangyang0616

@hzxuzhonghu hzxuzhonghu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, not big problem, since this is mostly the logic updating subJob construction, while the scheduling has already been merged

Comment thread pkg/controllers/apis/job_info.go Outdated
job.Pods[key] = make(map[string]*v1.Pod, len(pods))
for pn, pod := range pods {
job.Pods[key][pn] = pod
clonedPod := pod.DeepCopy()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I donot see we mutate the pod. Deepcopy is a costy op, so i think maybe we can keep it as still

@wangyang0616 wangyang0616 Dec 11, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. The change has been reverted.

@wangyang0616

Copy link
Copy Markdown
Member Author

Just want to verify that does this PR means that the pods must first match the labelSelector, and then be divided into different groups based on different keys? @wangyang0616

Yes, LabelSelector is an explicit condition that defines the valid scope for pod grouping. When the controller creates a PodGroup based on a VCJob, it automatically configures the LabelSelector information to match the corresponding tasks.

return values

// Log when no matching rules are configured, using default group
klog.V(4).Infof("No MatchLabelKeys configured for policy, pod %s/%s uses default subjob group", pod.Namespace, pod.Name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a pod matches the LabelSelector but is missing some labels in MatchLabelKeys, then it will belongs to the default subjob, right?

@ouyangshengjia ouyangshengjia Dec 11, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better that if a SubGroupPolicy is configured with only LabelSelector and empty MatchLabelKeys, the pods matching the LabelSelector should be assigned to a separate SubJob.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the definition of subgroup, it is recommended to use LabelSelector and matchLabelKey in combination, and express the subgroup logic through explicit declaration. This avoids excessive implicit default behaviors and improves maintainability.

@wangyang0616

Copy link
Copy Markdown
Member Author

/retest

Signed-off-by: wangyang0616 <wangyang8126@gmail.com>
Signed-off-by: wangyang0616 <wangyang8126@gmail.com>
Signed-off-by: wangyang0616 <wangyang8126@gmail.com>
Signed-off-by: wangyang0616 <wangyang8126@gmail.com>
… the YAML files

Signed-off-by: wangyang0616 <wangyang8126@gmail.com>
@wangyang0616
wangyang0616 force-pushed the feature_subgroup_update branch from d4e39ca to 44f392e Compare December 13, 2025 07:19
Signed-off-by: wangyang0616 <wangyang8126@gmail.com>
@wangyang0616
wangyang0616 force-pushed the feature_subgroup_update branch from 44f392e to 08a9b37 Compare December 15, 2025 08:20
@hzxuzhonghu

Copy link
Copy Markdown
Member

/lgtm
/approve

@volcano-sh-bot volcano-sh-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 15, 2025
@volcano-sh-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hzxuzhonghu

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@volcano-sh-bot volcano-sh-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 15, 2025
@volcano-sh-bot
volcano-sh-bot merged commit 1be4c9d into volcano-sh:master Dec 15, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enables role-based elasticity and Gang Scheduling for distributed inference workloads (Kthena)

5 participants