Skip to content

Commit

Permalink
Fix ControlNetUnit copy issue (#2910)
Browse files Browse the repository at this point in the history
* Fix ControlNetUnit copy issue

* Add copy test
  • Loading branch information
huchenlei authored May 20, 2024
1 parent a5c0da5 commit b197f7c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal_controlnet/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,7 @@ def parse(cls, text: str) -> ControlNetUnit:
for (key, value) in (item.strip().split(": "),)
},
)

def __copy__(self) -> ControlNetUnit:
"""Override the behavior on `copy.copy` calls."""
return self.copy()
9 changes: 9 additions & 0 deletions unit_tests/args_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
import torch
import numpy as np
from copy import copy
from dataclasses import dataclass

from internal_controlnet.args import ControlNetUnit
Expand Down Expand Up @@ -249,3 +250,11 @@ def test_infotext_parsing():

def test_alias():
ControlNetUnit.from_dict({"lowvram": True})


def test_copy():
unit1 = ControlNetUnit(enabled=True, module="none")
unit2 = copy(unit1)
unit2.enabled = False
assert unit1.enabled
assert not unit2.enabled

0 comments on commit b197f7c

Please sign in to comment.