enhance model loading logic in BaseModelPool and CLIPVisionModelPool for better configuration handling#150
Conversation
…for better configuration handling
There was a problem hiding this comment.
Pull Request Overview
This pull request enhances the model loading logic in the BaseModelPool and CLIPVisionModelPool classes to improve configuration handling and error reporting. The changes address issue #149 by providing more robust model loading mechanisms.
- Enhanced the
load_modelmethod in both base and CLIP vision model pools to handle different configuration types more systematically - Replaced conditional if-else chains with pattern matching for better type handling and code readability
- Added comprehensive error handling and logging for better debugging experience
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| fusion_bench/modelpool/base_pool.py | Refactored load_model method to use pattern matching and improved error handling for different model configuration types |
| fusion_bench/modelpool/clip_vision/modelpool.py | Enhanced load_model method with pattern matching, better documentation, and improved logging messages |
| fusion_bench/method/opcm/opcm.py | Added assertion to ensure model loading doesn't return None |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
|
||
| # handle different model configuration types | ||
| match self._models[model_name_or_config]: | ||
| case str() as model_path: |
There was a problem hiding this comment.
[nitpick] Using str() as a pattern in match statements is unusual syntax. Consider using case model_path if isinstance(model_path, str): or simply case str(model_path): for better readability and consistency.
| case str() as model_path: | |
| case model_path if isinstance(model_path, str): |
| # Load and return the CLIPVisionModel from the resolved path | ||
| return CLIPVisionModel.from_pretrained(repo_path, *args, **kwargs) | ||
|
|
||
| case nn.Module() as model: |
There was a problem hiding this comment.
[nitpick] Similar to the string pattern, nn.Module() as a pattern is unconventional. Consider using case model if isinstance(model, nn.Module): for better code clarity.
| case nn.Module() as model: | |
| case model if isinstance(model, nn.Module): |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This pull request should fix issue #149