chore(trainer): add unit tests for get_args_using_torchtune_config and get_trainer_cr_from_builtin_trainer#416
Conversation
|
🎉 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! |
|
[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 |
There was a problem hiding this comment.
Pull request overview
Adds unit tests to improve coverage for TorchTune/BuiltinTrainer Kubernetes utility conversions, ensuring TorchTuneConfig fields and BuiltinTrainer CR generation behave as expected.
Changes:
- Added
_build_builtin_runtime()helper for constructing a TorchTune BuiltinTrainer runtime in tests. - Added parametrized tests for
utils.get_args_using_torchtune_config(). - Added parametrized tests for
utils.get_trainer_cr_from_builtin_trainer().
| @pytest.mark.parametrize( | ||
| "test_case", | ||
| [ | ||
| TestCase( | ||
| name="empty config produces empty args", |
There was a problem hiding this comment.
The PR description lists several test scenarios (e.g., “model_args only” and a “full config with all fields”) that aren’t represented in this parametrization, and TorchTuneConfig doesn’t appear to have a model_args field; please add the missing cases or update the PR description to match what’s actually tested.
…d get_trainer_cr_from_builtin_trainer Add comprehensive unit tests for two previously untested utility functions in kubeflow/trainer/backends/kubernetes/utils.py: - test_get_args_using_torchtune_config: 8 parametrized test cases covering empty config, dtype only, all scalar fields (dtype/batch_size/epochs/loss), LoRA peft_config, dataset_preprocess_config, HuggingFace dataset URIs (directory and file paths via initializer), and invalid dtype error. - test_get_trainer_cr_from_builtin_trainer: 4 parametrized test cases covering num_nodes with batch_size, resources_per_node, empty config, and invalid config type error. These functions had zero test coverage. The new tests follow existing patterns in the file using TestCase dataclass and pytest.mark.parametrize. Signed-off-by: Prabhaharan Velu <haranprabha.v@gmail.com>
f76b5fa to
c720be2
Compare
What this PR does
Adds comprehensive unit tests for two previously untested utility functions in
kubeflow/trainer/backends/kubernetes/utils.py:test_get_args_using_torchtune_config— 8 parametrized test cases:TorchTuneConfigproduces empty argsdtypeonly produces single dtype argdtype,batch_size,epochs,loss)peft_configwithLoraConfigappends LoRA argsdataset_preprocess_configappends dataset argshf://tatsu-lab/alpaca)hf://tatsu-lab/alpaca/data.json)ValueErrortest_get_trainer_cr_from_builtin_trainer— 4 parametrized test cases:num_nodesandbatch_sizeresources_per_nodeValueErrorWhy
Both
get_args_using_torchtune_config()andget_trainer_cr_from_builtin_trainer()had zero test coverage — confirmed via grep across the entire test suite. These functions are critical for converting SDKBuiltinTrainertypes into Kubernetes CR models and CLI arguments for torchtune.How
utils_test.pyusingTestCasedataclass andpytest.mark.parametrize_build_builtin_runtime()to construct a torchtune runtime withTORCH_TUNE_COMMANDruff check,ruff format --check, and pre-commit hooks