feat: Add train() and optimize() methods to TrainJobTemplate#347
feat: Add train() and optimize() methods to TrainJobTemplate#347sujalshah-bit wants to merge 1 commit intokubeflow:mainfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
🎉 Welcome to the Kubeflow SDK! 🎉 Thanks for opening your first PR! We're happy to have you as part of our community 🚀 Here's what happens next:
Join the community:
Feel free to ask questions in the comments if you need any help or clarification! |
There was a problem hiding this comment.
Pull request overview
This PR turns TrainJobTemplate from a passive configuration object into an executable entrypoint by adding convenience methods that delegate to TrainerClient and OptimizerClient.
Changes:
- Added
TrainJobTemplate.train()to submit a TrainJob via an injectedTrainerClient. - Added
TrainJobTemplate.optimize()to submit an OptimizationJob via an injectedOptimizerClient(using the template astrial_template). - Introduced postponed annotation evaluation (
from __future__ import annotations) plusTYPE_CHECKINGimports to avoid runtime circular imports.
kubeflow/trainer/types/types.py
Outdated
|
|
||
| # Change it to list: BUILTIN_CONFIGS, once we support more Builtin Trainer configs. | ||
| TORCH_TUNE = BuiltinTrainer.__annotations__["config"].__name__.lower().replace("config", "") | ||
| TORCH_TUNE = TORCH_TUNE = TorchTuneConfig.__name__.lower().replace("config", "") |
There was a problem hiding this comment.
The constant assignment TORCH_TUNE = TORCH_TUNE = ... is redundant and looks accidental; simplify to a single assignment to avoid confusion and potential lint issues.
| TORCH_TUNE = TORCH_TUNE = TorchTuneConfig.__name__.lower().replace("config", "") | |
| TORCH_TUNE = TorchTuneConfig.__name__.lower().replace("config", "") |
| def train( | ||
| self, | ||
| client: TrainerClient, | ||
| options: list | None = None, | ||
| ) -> str: | ||
| """Create a TrainJob using this template's configuration. |
There was a problem hiding this comment.
The TODO comment above TrainJobTemplate about adding train()/optimize() is now outdated after introducing these methods; remove or update it to avoid misleading future readers.
TrainJobTemplate was a passive data container with no way to actually execute jobs. This change lets the template act as an entrypoint to both TrainerClient and OptimizerClient. - train() delegates to TrainerClient.train() using the template's pre-configured runtime, initializer, and trainer - optimize() delegates to OptimizerClient.optimize() passing self as the trial_template for hyperparameter tuning TYPE_CHECKING is used to avoid circular imports since TrainerClient and OptimizerClient both already import types.py. Signed-off-by: Sujal Shah <sujalshah28092004@gmail.com>
e32e9e4 to
c13ea6b
Compare
What this PR does / why we need it:
TrainJobTemplate was a passive data container with no way to actually execute jobs. This change lets the template act as an entrypoint to both TrainerClient and OptimizerClient.
TYPE_CHECKING is used to avoid circular imports since TrainerClient and OptimizerClient both already import types.py.
Which issue(s) this PR fixes (optional, in
Fixes #<issue number>, #<issue number>, ...format, will close the issue(s) when PR gets merged):Fixes NONE
Checklist: