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

Enable 0 workers replicaSpec for pytorchjob #6201

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

punkerpunker
Copy link

@punkerpunker punkerpunker commented Jan 28, 2025

Why are the changes needed?

Currently, PyTorchJob allows not to specify Worker in case only one worker (Master) is needed for the job. Current functionality of the plugin doesn't allow to do so, however, in some cases we still want to achieve a Master-only PyTorchJob.

What changes were proposed in this pull request?

Made a change so pytorch plugin is no longer complains about a 0-replica worker, but instead - if replicas=0 is passed, plugin just doesn't render it.

I understand this isn't a best design for the moment, but that is a least-invasive approach to achieve it without changing e.g pyflyte validation behavior (if e.g we accept that worker=None could be passed to the PyTorch task_config.

How was this patch tested?

We are running the fork code in our production environment

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Summary by Bito

Enhanced PyTorch operator plugin to support master-only configurations by removing the requirement for worker replicas. Modified replica specification logic to make worker specs optional. Updated test suite to validate both zero-worker and single-worker configurations.

Unit tests added: True

Estimated effort to review (1-5, lower is better): 2

Copy link

welcome bot commented Jan 28, 2025

Thank you for opening this pull request! 🙌

These tips will help get your PR across the finish line:

  • Most of the repos have a PR template; if not, fill it out to the best of your knowledge.
  • Sign off your commits (Reference: DCO Guide).

@flyte-bot
Copy link
Collaborator

flyte-bot commented Jan 28, 2025

Code Review Agent Run #29781f

Actionable Suggestions - 1
  • flyteplugins/go/tasks/plugins/k8s/kfoperators/pytorch/pytorch.go - 1
    • Consider consolidating duplicate jobSpec initialization · Line 150-163
Review Details
  • Files reviewed - 1 · Commit Range: 7a713eb..7a713eb
    • flyteplugins/go/tasks/plugins/k8s/kfoperators/pytorch/pytorch.go
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

@flyte-bot
Copy link
Collaborator

flyte-bot commented Jan 28, 2025

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Feature Improvement - Enable Zero-Worker PyTorch Jobs

pytorch.go - Modified worker replica handling to support zero-worker configurations

pytorch_test.go - Updated tests to verify zero-worker and single-worker scenarios

@flyte-bot
Copy link
Collaborator

flyte-bot commented Jan 28, 2025

Code Review Agent Run #c188b6

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 7a713eb..6560ee2
    • flyteplugins/go/tasks/plugins/k8s/kfoperators/pytorch/pytorch.go
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

@@ -145,16 +145,17 @@ func (p pytorchOperatorResourceHandler) BuildResource(ctx context.Context, taskC
"Invalid TaskSpecification, unsupported task template version [%v] key", taskTemplate.GetTaskTypeVersion())
}

if *workerReplicaSpec.Replicas <= 0 {
return nil, fmt.Errorf("number of workers must be greater than 0")
jobSpec := kubeflowv1.PyTorchJobSpec{}
Copy link
Member

Choose a reason for hiding this comment

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

Could we add a small unit test?

Copy link
Author

Choose a reason for hiding this comment

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

Hey @pingsutw, I've removed TestBuildResourcePytorchV1WithZeroWorker as it was intended to fail in the case corrected with this PR. Replaced it with the TestBuildResourcePytorchV1WithDifferentWorkersNumber test, thank you.

Copy link
Member

Choose a reason for hiding this comment

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

One unit test is failing. otherwise, lgtm.

Copy link
Author

Choose a reason for hiding this comment

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

Should be fixed now, thanks.

Copy link

codecov bot commented Jan 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 37.07%. Comparing base (45ce4c0) to head (644ce84).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6201      +/-   ##
==========================================
- Coverage   37.08%   37.07%   -0.01%     
==========================================
  Files        1318     1318              
  Lines      132707   132711       +4     
==========================================
+ Hits        49208    49209       +1     
- Misses      79244    79247       +3     
  Partials     4255     4255              
Flag Coverage Δ
unittests-datacatalog 51.58% <ø> (ø)
unittests-flyteadmin 54.31% <ø> (-0.03%) ⬇️
unittests-flytecopilot 30.99% <ø> (ø)
unittests-flytectl 62.33% <ø> (+0.04%) ⬆️
unittests-flyteidl 7.23% <ø> (ø)
unittests-flyteplugins 53.88% <100.00%> (+0.01%) ⬆️
unittests-flytepropeller 42.73% <ø> (ø)
unittests-flytestdlib 55.33% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@punkerpunker punkerpunker force-pushed the flyteplugins/allow-zero-worker-pytorchjob branch from a683ad3 to 33ab59b Compare January 29, 2025 21:09
@punkerpunker punkerpunker requested a review from pingsutw January 29, 2025 21:10
@punkerpunker punkerpunker force-pushed the flyteplugins/allow-zero-worker-pytorchjob branch from 33ab59b to 7464db6 Compare January 29, 2025 21:12
@flyte-bot
Copy link
Collaborator

flyte-bot commented Jan 29, 2025

Code Review Agent Run #59b7b8

Actionable Suggestions - 1
  • flyteplugins/go/tasks/plugins/k8s/kfoperators/pytorch/pytorch.go - 1
    • Consider validating masterReplicaSpec before use · Line 148-151
Review Details
  • Files reviewed - 2 · Commit Range: 25e2074..7464db6
    • flyteplugins/go/tasks/plugins/k8s/kfoperators/pytorch/pytorch.go
    • flyteplugins/go/tasks/plugins/k8s/kfoperators/pytorch/pytorch_test.go
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

Comment on lines +148 to +151
jobSpec := kubeflowv1.PyTorchJobSpec{}
replicaSpecs := map[commonOp.ReplicaType]*commonOp.ReplicaSpec{
kubeflowv1.PyTorchJobReplicaTypeMaster: masterReplicaSpec,
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider validating masterReplicaSpec before use

Consider validating that masterReplicaSpec is not nil before using it in the replicaSpecs map. A nil masterReplicaSpec could cause runtime issues.

Code suggestion
Check the AI-generated fix before applying
Suggested change
jobSpec := kubeflowv1.PyTorchJobSpec{}
replicaSpecs := map[commonOp.ReplicaType]*commonOp.ReplicaSpec{
kubeflowv1.PyTorchJobReplicaTypeMaster: masterReplicaSpec,
}
jobSpec := kubeflowv1.PyTorchJobSpec{}
if masterReplicaSpec == nil {
return nil, fmt.Errorf("master replica spec cannot be nil")
}
replicaSpecs := map[commonOp.ReplicaType]*commonOp.ReplicaSpec{
kubeflowv1.PyTorchJobReplicaTypeMaster: masterReplicaSpec,
}

Code Review Run #59b7b8


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

pingsutw
pingsutw previously approved these changes Jan 29, 2025
@punkerpunker punkerpunker force-pushed the flyteplugins/allow-zero-worker-pytorchjob branch from a71e27b to 644ce84 Compare January 30, 2025 00:50
@punkerpunker punkerpunker requested a review from pingsutw January 30, 2025 00:58
@flyte-bot
Copy link
Collaborator

flyte-bot commented Jan 30, 2025

Code Review Agent Run #216032

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 18f3de4..644ce84
    • flyteplugins/go/tasks/plugins/k8s/kfoperators/pytorch/pytorch.go
    • flyteplugins/go/tasks/plugins/k8s/kfoperators/pytorch/pytorch_test.go
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants