-
Notifications
You must be signed in to change notification settings - Fork 41
Fix trainer detection for custom Docker images with regex pattern matching #31
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
Closed
jskswamy
wants to merge
13
commits into
kubeflow:main
from
jskswamy:fix/trainer-detection-custom-images
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2b08be7
Add optional dependencies for testing
jskswamy c5cf2bc
Add centralized trainer configurations and detection logic
jskswamy e57b003
Refactor TrainerFramework to Framework Enum
jskswamy f3f3bcf
Update trainer detection tests to handle edge cases
jskswamy 9ef621e
Reorganize tests to co-location with source files
jskswamy 82ecdf3
Remove underscore prefixes from utility functions
jskswamy 76eba6d
Require explicit 'pytorch' in image names for PyTorch detection
jskswamy c0a7d93
Add explanatory comments for essential None checks
jskswamy baf87ba
Remove redundant ALL_TRAINERS dictionary
jskswamy b3aed48
Remove uv and testing setup to focus PR on trainer detection logic
jskswamy d3c0043
Improve trainer detection API with default parameter and better encap…
jskswamy 48aa98b
Rename detect_trainer_from_image_patterns to get_trainer_from_image
jskswamy fa5778b
Fix accelerator count validation to handle zero values properly
jskswamy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| from kubeflow.trainer.types import types | ||
|
|
||
|
|
||
| class TestTrainerConfigurations: | ||
| """Test cases for trainer configurations and types.""" | ||
|
|
||
| def test_centralized_trainer_configs(self): | ||
| """Test that centralized trainer configurations are properly defined.""" | ||
| # Verify all trainer frameworks have configurations | ||
| for framework in types.Framework: | ||
| assert framework in types.TRAINER_CONFIGS | ||
| trainer = types.TRAINER_CONFIGS[framework] | ||
| assert trainer.framework == framework | ||
|
|
||
| def test_default_trainer_uses_centralized_config(self): | ||
| """Test that DEFAULT_TRAINER uses centralized configuration.""" | ||
| assert types.DEFAULT_TRAINER == types.TRAINER_CONFIGS[types.Framework.TORCH] | ||
| assert types.DEFAULT_TRAINER.framework == types.Framework.TORCH |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to keep framework argument given that
TRAINER_CONFIGSDict has the Framework type in the Dict key.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the
frameworkfield in theTrainerclass, I'd like to share my thoughts on why this field exists and why it serves a legitimate purpose:The
frameworkField Has Critical ImportanceAfter investigating the codebase, I discovered that the
Trainerclass andframeworkfield were pre-existing before this PR. The field was intentionally designed to serve specific purposes:Critical Importance for API Design
The
frameworkfield is essential for maintaining a clean, self-contained API:Trainerobject must "know" what framework it represents without external contextTrainerobject, they can immediately determine its framework without reverse-engineering from other fieldsSelf-Contained Data Structure
The
frameworkfield makesTrainerobjects self-contained and self-documenting:Breaking Changes Would Be Required
Removing the field would require:
Architectural Integrity
The field maintains the principle of encapsulation —
Trainerobject should contain all information about itself, including what framework it represents.Why Dictionary Instead of Array?
The choice of using
TRAINER_CONFIGS: Dict[Framework, Trainer]instead of an array of trainers was a performance and design optimization:Performance Benefits
Design Benefits
My Take
The
frameworkfield serves critical architectural purposes for API design and object encapsulation. The dictionary structure provides performance benefits, but the field itself is essential for maintaining clean, self-contained objects.Removing the field would break the original design intent, make the API less clean and efficient, and potentially introduce breaking changes. The field was intentionally designed this way for good reasons, and I believe we should keep it to maintain the integrity of the API design.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that we should have dict to represent all Trainers where key is the Framework name and value is the Trainer object.
The question is should we also keep
frameworkargument in the Trainer object. This is mostly used to just show users what framework this Trainer is using.I am fine to keep it for now.
WDYT @szaher @astefanutti @Electronic-Waste ?