Skip to content
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

Validate pytorchjob workers are configured when elasticpolicy is configured #2320

Merged

Conversation

tarat44
Copy link
Contributor

@tarat44 tarat44 commented Nov 4, 2024

What this PR does / why we need it:
This PR adds a check in the Pytorchjob validating webhook to ensure that if a user configures an elastic policy that they have defined a worker spec. Previously defining an elastic policy with no worker spec was resulting in a nil pointer exception on this line. Additionally, we added validation to ensure that the worker spec defines at least one replica.

Which issue(s) this PR fixes (optional, in Fixes #<issue number>, #<issue number>, ... format, will close the issue(s) when PR gets merged):
Fixes #2278

Checklist:

  • Docs included if any changes are user facing

Signed-off-by: tarat44 <[email protected]>
Co-authored-by: ricardov1 <[email protected]>
Co-authored-by: alenawang <[email protected]>
@tarat44 tarat44 changed the title Validate workers for elasticpolicy Validate workers are configured when elasticpolicy is configured Nov 4, 2024
@tarat44 tarat44 changed the title Validate workers are configured when elasticpolicy is configured Validate pytorchjob workers are configured when elasticpolicy is configured Nov 4, 2024
@coveralls
Copy link

coveralls commented Nov 4, 2024

Pull Request Test Coverage Report for Build 12184193267

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 11663764609: 0.0%
Covered Lines: 77
Relevant Lines: 77

💛 - Coveralls

@tenzen-y
Copy link
Member

tenzen-y commented Nov 5, 2024

@tarat44 tarat44 force-pushed the validate-workers-for-elasticpolicy branch from fad6922 to a4a0050 Compare November 6, 2024 15:28
@tarat44
Copy link
Contributor Author

tarat44 commented Nov 6, 2024

@tarat44 In advance, could you sign to DCO?

https://github.com/kubeflow/training-operator/pull/2320/checks?check_run_id=32498218264

@tenzen-y Thanks for bringing this to my attention, and I apologize for the delay. I combined the commits into one and provided the sign off message.

@tarat44
Copy link
Contributor Author

tarat44 commented Dec 3, 2024

@tenzen-y @andreyvelich @kuizhiqing I wanted to follow up on this to see if it would be possible to have this fix in the next release of the training operator version 1

Copy link
Member

@andreyvelich andreyvelich left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution @tarat44!
Overall, lgtm
/assign @kubeflow/wg-training-leads @Electronic-Waste

pkg/webhooks/pytorch/pytorchjob_webhook.go Outdated Show resolved Hide resolved
workerPath := specPath.Child("pytorchReplicaSpecs").Child("Worker")
if !ok {
allErrs = append(allErrs, field.Required(workerPath, "must be configured if elastic policy is used"))
} else if workerReplicaSpec.Replicas != nil && int(*workerReplicaSpec.Replicas) < 1 {
Copy link
Member

Choose a reason for hiding this comment

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

Do you need this check ? Isn't the default value for Replicas is 1 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We added this validation to cover the case where replicas is explicitly set to 0 since the default is only set when it is nil https://github.com/kubeflow/training-operator/blob/master/pkg/apis/kubeflow.org/v1/defaulting_utils.go#L43

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should have a separate validation that disallow users to set Replicas < 1 since it is invalid option ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that makes sense- we will update it to a separate validation that won't depend on whether elastic policy is set. Is it okay to have both validations in the same PR or would you prefer we separate that one into its own PR?

Copy link
Member

@andreyvelich andreyvelich Dec 5, 2024

Choose a reason for hiding this comment

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

I think, it is fine to add this simple check in this PR if you can @tarat44!

Copy link
Contributor Author

@tarat44 tarat44 Dec 5, 2024

Choose a reason for hiding this comment

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

@andreyvelich, we separated the validation for worker replicas being at least 1. I also realized that we had worker as an attribute, instead of a key in the pytorchReplicaSpecs map, in the error field path so we fixed it to use the map representation. It should be good to re-review now

tarat44 and others added 2 commits December 4, 2024 16:46
Co-authored-by: Andrey Velichkevich <[email protected]>
Signed-off-by: Tara Tufano <[email protected]>
@andreyvelich
Copy link
Member

Thanks for this work @tarat44!
/lgtm
/approve

Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andreyvelich

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

The pull request process is described here

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

@google-oss-prow google-oss-prow bot merged commit 2392c36 into kubeflow:master Dec 5, 2024
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Training Operator crashes when submitting PyTorchJob with elasticPolicy but without worker template defined
4 participants