Skip to content

enhance model loading logic in BaseModelPool and CLIPVisionModelPool for better configuration handling#150

Merged
tanganke merged 2 commits into
mainfrom
develop
Sep 27, 2025
Merged

enhance model loading logic in BaseModelPool and CLIPVisionModelPool for better configuration handling#150
tanganke merged 2 commits into
mainfrom
develop

Conversation

@tanganke
Copy link
Copy Markdown
Owner

This pull request should fix issue #149

Copilot AI review requested due to automatic review settings September 27, 2025 01:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_model method 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.

Comment thread fusion_bench/modelpool/base_pool.py Outdated

# handle different model configuration types
match self._models[model_name_or_config]:
case str() as model_path:
Copy link

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
case str() as model_path:
case model_path if isinstance(model_path, str):

Copilot uses AI. Check for mistakes.
# Load and return the CLIPVisionModel from the resolved path
return CLIPVisionModel.from_pretrained(repo_path, *args, **kwargs)

case nn.Module() as model:
Copy link

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
case nn.Module() as model:
case model if isinstance(model, nn.Module):

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants