Lazy Loading for CLI Performance Optimization #241
+998
−273
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.
These changes introduce a lazy loading system that improves the HPCLI startup performance. Dependencies are no longer loaded upfront (resulting in 2+ second startup time) and are now loaded only when needed, reducing the help command times by 50% while maintaining full functionality during execution.
Architecture
1. LazyImportManager
Replaces traditional imports with a config based system the defers heavy modules until they're accessed. Integrates with
__getattr__
Python mechanism2. LazyRegistry
Provides lightweight substitutes for heavy registries during CLI generation. The flow now stores basic metadata for immediate CLI option generation, and defers full schemas until commands are actually executed and need validation
3. LazyDecorator
Applies decorators based on current needs from the system. For example - immediately applies for CLI generation decorators (needed for help text), and deferred application for runtime decorators (telemetry, logging) that are ONLY needed during command execution
4. CommandRegistry
Removes the need for hardcoded command mappings by enabling commands to self-register with metadata during imports. This allows the CLI to discover available commands without loading heavy modules/deps; selects which modules to load based on which commands users actually run.
How they all work together
These components form the pipeline as such:
Example
hyp create hyp-pytorch-job --help
!hyp create hyp-jumpstart-endpoint --model-id deepseek-llm-r1-distill-qwen-1-5b --instance-type ml.g5.8xlarge --endpoint-name new-endpoint
PR Approval Steps
For Requester
For Reviewer
For Requester
section to double check each item.