Skip to content

Extract duplicate retry logic from from_huggingface methods#51

Merged
suzukimain merged 4 commits intoupdate-v9from
copilot/sub-pr-49-again
Dec 16, 2025
Merged

Extract duplicate retry logic from from_huggingface methods#51
suzukimain merged 4 commits intoupdate-v9from
copilot/sub-pr-49-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 16, 2025

The retry logic for model loading was duplicated identically across three from_huggingface methods in EasyPipelineForText2Image, EasyPipelineForImage2Image, and EasyPipelineForInpainting.

Changes

  • Extracted _load_pipeline_with_retry helper function that encapsulates:

    • Candidate index and failed count tracking
    • HuggingFace search with retry on failure
    • Pipeline loading from single file or pretrained checkpoint
    • Recursive retry logic with configurable max_retries
  • Updated all three from_huggingface methods to delegate to the helper, passing only:

    • Pipeline class
    • Model identifier
    • Pipeline mapping (TEXT2IMAGE, IMAGE2IMAGE, or INPAINT)
    • Forwarded kwargs

Impact

Reduces code by ~93 lines. Future changes to retry behavior now require updates in a single location.

# Before: 67 lines of identical retry logic in each method
def from_huggingface(cls, pretrained_model_link_or_path, **kwargs):
    kwargs.update(_status)
    candidate_index = kwargs.pop('_candidate_index', 0)
    # ... 60+ more lines of retry logic

# After: 7 lines delegating to shared helper
def from_huggingface(cls, pretrained_model_link_or_path, **kwargs):
    kwargs.update(_status)
    return _load_pipeline_with_retry(
        cls, pretrained_model_link_or_path,
        SINGLE_FILE_CHECKPOINT_TEXT2IMAGE_PIPELINE_MAPPING, **kwargs
    )

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits December 16, 2025 09:29
- Created _load_pipeline_with_retry helper function to consolidate retry logic
- Updated all three from_huggingface methods to use the shared helper
- Reduced code duplication by ~93 lines
- Maintained identical behavior across all three pipeline types

Co-authored-by: suzukimain <131413573+suzukimain@users.noreply.github.com>
- Removed incorrect failed_count increment before warning
- Adjusted warning message format to match original code
- Ensures backward compatibility with existing behavior

Co-authored-by: suzukimain <131413573+suzukimain@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on model loading enhancements Extract duplicate retry logic from from_huggingface methods Dec 16, 2025
Copilot AI requested a review from suzukimain December 16, 2025 09:35
@suzukimain suzukimain closed this Dec 16, 2025
@suzukimain suzukimain reopened this Dec 16, 2025
@suzukimain suzukimain marked this pull request as ready for review December 16, 2025 09:48
Copilot AI review requested due to automatic review settings December 16, 2025 09:48
@suzukimain suzukimain merged commit 4c9b216 into update-v9 Dec 16, 2025
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.

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants