Skip to content
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

deprecated onediffx.lora #1179

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open

Conversation

marigoold
Copy link
Collaborator

@marigoold marigoold commented Jan 9, 2025

Summary by CodeRabbit

  • Deprecation

    • Added deprecation warnings for several LoRA-related functions.
    • Marked existing LoRA tests as skipped due to deprecation.
  • Testing

    • Introduced a new test for evaluating numerical stability of model parameters during adapter loading and deletion.
  • Warning Management

    • Enhanced warning system to ensure deprecated functionality is clearly communicated to users.
  • Workflow Enhancements

    • Improved visibility into ComfyUI service status during tests.
    • Updated volume mappings in the Docker Compose configuration for the testing service.
  • Dependency Updates

    • Upgraded the diffusers package version in both requirements.txt and setup.py.

Copy link
Contributor

coderabbitai bot commented Jan 9, 2025

Walkthrough

The changes focus on marking certain LoRA-related functions and tests as deprecated in the OneDiff library. A new deprecated() decorator is introduced in the lora.py file to add warning messages to specific functions like load_and_fuse_lora, load_lora_and_optionally_fuse, and others. In the test file, corresponding tests are marked with @pytest.mark.skip() to indicate deprecation, and a new test for numerical stability is added to ensure model parameter consistency during adapter operations. Additionally, a workflow update enhances visibility of input files during ComfyUI testing.

Changes

File Change Summary
onediff_diffusers_extensions/onediffx/lora/lora.py - Added deprecated() decorator
- Applied deprecation warnings to multiple LoRA-related functions: load_and_fuse_lora, load_lora_and_optionally_fuse, unfuse_lora, set_and_fuse_adapters, delete_adapters, get_active_adapters
onediff_diffusers_extensions/tests/test_lora.py - Added test_lora_numerical_stability() test
- Marked existing tests (test_lora_loading, test_multi_lora_loading, test_get_active_adapters, test_delete_adapters) as skipped with deprecation reason
.github/workflows/examples.yml - Added commands to print process status of ComfyUI service and updated peft package installation to a fixed version
tests/comfy-docker-compose.yml - Added volume mapping for sdxl-unet-control-lora-speedup.png
- Commented out volume mapping for control directory
tests/comfyui/workflows/sdxl-control-lora-speedup.json - Changed image path in LoadImage node from "control/sdxl-unet-control-lora-speedup.png" to "sdxl-unet-control-lora-speedup.png"
onediff_diffusers_extensions/examples/requirements.txt - Updated diffusers version from 0.19.3 to 0.27.0
setup.py - Updated diffusers version requirement from >=0.19.3 to >=0.27.0
onediff_comfy_nodes/modules/oneflow/onediff_controlnet.py - Simplified weight assignment logic in OneDiffControlLora class by removing low VRAM weight resolution

Poem

🐰 Hop, hop, farewell to LoRA's old ways,
Warnings dance like rabbits through the code's maze.
Deprecated functions wave their last goodbye,
Numerical stability keeps our spirits high.
A new path beckons, with warnings so bright! 🚧


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 81029ac and 2eb74ae.

📒 Files selected for processing (1)
  • .github/workflows/examples.yml (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/examples.yml
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: comfy onediff:torch2.3-cuda11.8
  • GitHub Check: diffusers_examples onediff:torch2.3-cuda11.8

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c8f513e and 3fe0e2f.

📒 Files selected for processing (2)
  • onediff_diffusers_extensions/onediffx/lora/lora.py (7 hunks)
  • onediff_diffusers_extensions/tests/test_lora.py (6 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
onediff_diffusers_extensions/onediffx/lora/lora.py

49-49: No explicit stacklevel keyword argument found

(B028)

🔇 Additional comments (12)
onediff_diffusers_extensions/onediffx/lora/lora.py (6)

Line range hint 60-77: LGTM! Function correctly marked as deprecated.

The deprecation marking is appropriate while maintaining the existing functionality.

🧰 Tools
🪛 Ruff (0.8.2)

49-49: No explicit stacklevel keyword argument found

(B028)


Line range hint 83-203: LGTM! Function correctly marked as deprecated.

The deprecation marking is appropriate while maintaining the existing functionality.


Line range hint 207-224: LGTM! Function correctly marked as deprecated.

The deprecation marking is appropriate while maintaining the existing functionality.


Line range hint 227-268: LGTM! Function correctly marked as deprecated.

The deprecation marking is appropriate while maintaining the existing functionality.


Line range hint 271-297: LGTM! Function correctly marked as deprecated.

The deprecation marking is appropriate while maintaining the existing functionality.


Line range hint 300-305: LGTM! Function correctly marked as deprecated.

The deprecation marking is appropriate while maintaining the existing functionality.

onediff_diffusers_extensions/tests/test_lora.py (6)

39-40: LGTM! Directory creation check added.

The change ensures the test directory exists before running tests.


Line range hint 167-197: LGTM! Test correctly marked as skipped.

The test is appropriately marked as skipped due to the deprecation of onediffx.lora.


Line range hint 198-231: LGTM! Test correctly marked as skipped.

The test is appropriately marked as skipped due to the deprecation of onediffx.lora.


Line range hint 232-242: LGTM! Test correctly marked as skipped.

The test is appropriately marked as skipped due to the deprecation of onediffx.lora.


Line range hint 243-257: LGTM! Test correctly marked as skipped.

The test is appropriately marked as skipped due to the deprecation of onediffx.lora.


Line range hint 258-287: Consider keeping the numerical stability test active.

This test verifies an important aspect of the LoRA implementation - numerical stability after multiple adapter operations. Even though the LoRA functionality is deprecated, this test should remain active until the functionality is completely removed to ensure stability during the deprecation period.

Comment on lines 43 to 55
warnings.filterwarnings("always", category=DeprecationWarning)

def deprecated():
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
warnings.warn(
f"lora function {func.__name__} is deprecated",
category=DeprecationWarning,
)
return func(*args, **kwargs)
return wrapper
return decorator
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance deprecation warning with migration guidance and stacklevel.

The deprecation warning should include guidance on the recommended alternative and use the stacklevel parameter to point to the caller's location.

 def deprecated():
     def decorator(func):
         @functools.wraps(func)
         def wrapper(*args, **kwargs):
             warnings.warn(
-                f"lora function {func.__name__} is deprecated",
+                f"lora function {func.__name__} is deprecated. Please use diffusers.LoraLoaderMixin methods directly.",
                 category=DeprecationWarning,
+                stacklevel=2
             )
             return func(*args, **kwargs)
         return wrapper
     return decorator
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
warnings.filterwarnings("always", category=DeprecationWarning)
def deprecated():
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
warnings.warn(
f"lora function {func.__name__} is deprecated",
category=DeprecationWarning,
)
return func(*args, **kwargs)
return wrapper
return decorator
warnings.filterwarnings("always", category=DeprecationWarning)
def deprecated():
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
warnings.warn(
f"lora function {func.__name__} is deprecated. Please use diffusers.LoraLoaderMixin methods directly.",
category=DeprecationWarning,
stacklevel=2
)
return func(*args, **kwargs)
return wrapper
return decorator
🧰 Tools
🪛 Ruff (0.8.2)

49-49: No explicit stacklevel keyword argument found

(B028)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
.github/workflows/examples.yml (1)

308-310: LGTM! Consider adding error handling.

The addition of copying the test image file into the ComfyUI input directory is a good enhancement to the test setup.

Consider adding error handling to ensure the docker cp command succeeds:

-          docker cp /src/onediff/tests/comfyui/workflows/input/control/sdxl-unet-control-lora-speedup.png ${{ env.CONTAINER_NAME}}:/app/ComfyUI/input
+          docker cp /src/onediff/tests/comfyui/workflows/input/control/sdxl-unet-control-lora-speedup.png ${{ env.CONTAINER_NAME}}:/app/ComfyUI/input || {
+            echo "Failed to copy test image into container"
+            exit 1
+          }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f723864 and 5bd6dee.

📒 Files selected for processing (1)
  • .github/workflows/examples.yml (1 hunks)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
onediff_diffusers_extensions/examples/requirements.txt (1)

3-3: Consider aligning version specifications

The examples use an exact version match (==0.27.0) while setup.py uses a minimum version (>=0.27.0). Consider:

  1. Using >=0.27.0 here to match setup.py if the examples should work with future versions
  2. Adding a comment explaining why an exact version is required if ==0.27.0 is intentional
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8142e87 and d6e36ad.

📒 Files selected for processing (3)
  • onediff_comfy_nodes/benchmarks/resources/workflows/oneflow/sdxl-control-lora-speedup.json (1 hunks)
  • onediff_diffusers_extensions/examples/requirements.txt (1 hunks)
  • setup.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: diffusers_examples onediff-pro:torch2.3-cuda12.1
  • GitHub Check: diffusers_examples onediff:torch2.3-cuda11.8
🔇 Additional comments (2)
onediff_comfy_nodes/benchmarks/resources/workflows/oneflow/sdxl-control-lora-speedup.json (1)

125-125: Verify the image file location and accessibility.

The image path has been simplified from "control/sdxl-unet-control-lora-speedup.png" to "sdxl-unet-control-lora-speedup.png". Let's ensure this change is consistent and the file is accessible.

setup.py (1)

20-20: Verify compatibility with diffusers 0.27.0

The significant version bump from 0.19.3 to 0.27.0 might introduce breaking changes. Please ensure:

  1. The new version is compatible with the deprecated LoRA functionality
  2. All dependent features have been tested with this version

Let's check the release notes and potential breaking changes:

✅ Verification successful

Version upgrade to diffusers 0.27.0 is compatible with LoRA functionality

The codebase has robust LoRA support with custom implementations and extensive testing that ensures compatibility across diffusers versions. The version upgrade is safe to proceed with.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check diffusers changelog for breaking changes between 0.19.3 and 0.27.0

# Fetch the changelog
curl -s https://raw.githubusercontent.com/huggingface/diffusers/main/CHANGELOG.md | \
  awk '/## v0.27.0/,/## v0.19.3/' || echo "Failed to fetch changelog"

# Check if there are any existing issues related to this version
gh issue list --search "diffusers 0.27.0" --limit 5

Length of output: 282


Script:

#!/bin/bash
# Search for diffusers imports and usage
echo "=== Diffusers imports ==="
rg "from diffusers" -l

echo -e "\n=== LoRA related code ==="
rg "LoRA|lora" -i

echo -e "\n=== Diffusers specific class usage ==="
rg "diffusers\." -B 1 -A 1

Length of output: 73049

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.

1 participant