Skip to content

Commit 61b7cca

Browse files
deprecated onediffx.lora (#1179)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## 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`. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Shenghang Tsai <jackalcooper@gmail.com>
1 parent 1be9b27 commit 61b7cca

File tree

9 files changed

+46
-9
lines changed

9 files changed

+46
-9
lines changed

.github/workflows/examples.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ jobs:
306306
run: |
307307
docker exec -w /app/ComfyUI -d ${{ env.CONTAINER_NAME }} sh -c "python3 /app/ComfyUI/main.py --gpu-only --disable-cuda-malloc --port 8188 --extra-model-paths-config /src/onediff/tests/comfyui/extra_model_paths.yaml > /app/ComfyUI/onediff_comfyui.log 2>&1"
308308
sleep 30
309+
310+
309311
# print to check if comfy is launched successfully
310312
- run: docker exec ${{ env.CONTAINER_NAME }} ps aux
311313
- run: docker exec -w /src/onediff/onediff_comfy_nodes/benchmarks ${{ env.CONTAINER_NAME }} bash scripts/install_env.sh /app/ComfyUI
@@ -361,7 +363,7 @@ jobs:
361363
- if: matrix.test-suite == 'diffusers_examples'
362364
run: docker exec -w /src/onediff/onediff_diffusers_extensions ${{ env.CONTAINER_NAME }} bash examples/unet_save_and_load.sh --model_id=/share_nfs/hf_models/stable-diffusion-xl-base-1.0
363365
- if: matrix.test-suite == 'diffusers_examples'
364-
run: docker exec ${{ env.CONTAINER_NAME }} python3 -m pip install --user scikit-image "numpy<2" "diffusers==0.23" peft pytest "huggingface_hub<=0.25.0"
366+
run: docker exec ${{ env.CONTAINER_NAME }} python3 -m pip install --user scikit-image "numpy<2" "diffusers==0.23" peft==0.6.0 pytest "huggingface_hub<=0.25.0"
365367
- if: matrix.test-suite == 'diffusers_examples'
366368
run: docker exec -e ONEFLOW_MLIR_ENABLE_INFERENCE_OPTIMIZATION=0 ${{ env.CONTAINER_NAME }} python3 -m pytest -v onediff_diffusers_extensions/tests/test_lora.py --disable-warnings
367369

onediff_comfy_nodes/benchmarks/resources/workflows/oneflow/sdxl-control-lora-speedup.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
},
123123
"43": {
124124
"inputs": {
125-
"image": "control/sdxl-unet-control-lora-speedup.png",
125+
"image": "sdxl-unet-control-lora-speedup.png",
126126
"upload": "image"
127127
},
128128
"class_type": "LoadImage",

onediff_comfy_nodes/modules/oneflow/onediff_controlnet.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,12 @@ class control_lora_ops(ControlLoraOps, comfy.ops.manual_cast):
9595
sd = diffusion_model.state_dict()
9696
cm = self.control_model.state_dict()
9797
for k in sd:
98-
weight = comfy.model_management.resolve_lowvram_weight(
99-
sd[k], diffusion_model, k
100-
)
98+
# comfy.model_management.resolve_lowvram_weight(weight, model, key) always returns weight
99+
# and is removed now
100+
# weight = comfy.model_management.resolve_lowvram_weight(
101+
# sd[k], diffusion_model, k
102+
# )
103+
weight = sd[k]
101104
try:
102105
set_attr_of(self.control_model, k, weight)
103106
except Exception as e:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# pip install -r requirements.txt
22
transformers==4.27.1
3-
diffusers[torch]==0.19.3
3+
diffusers[torch]==0.27.0
44
onediff
55
chardet
66
opencv-python==4.8.0.74

onediff_diffusers_extensions/onediffx/lora/lora.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import functools
12
import warnings
23
from collections import OrderedDict
34
from pathlib import Path
@@ -37,10 +38,28 @@ class OneDiffXWarning(Warning):
3738

3839

3940
warnings.filterwarnings("always", category=OneDiffXWarning)
41+
warnings.filterwarnings("always", category=DeprecationWarning)
42+
43+
44+
def deprecated():
45+
def decorator(func):
46+
@functools.wraps(func)
47+
def wrapper(*args, **kwargs):
48+
warnings.warn(
49+
f"function {func.__name__} of onediffx.lora is deprecated",
50+
category=DeprecationWarning,
51+
)
52+
return func(*args, **kwargs)
53+
54+
return wrapper
55+
56+
return decorator
57+
4058

4159
USE_PEFT_BACKEND = False
4260

4361

62+
@deprecated()
4463
def load_and_fuse_lora(
4564
pipeline: LoraLoaderMixin,
4665
pretrained_model_name_or_path_or_dict: Union[str, Path, Dict[str, torch.Tensor]],
@@ -63,6 +82,7 @@ def load_and_fuse_lora(
6382
)
6483

6584

85+
@deprecated()
6686
def load_lora_and_optionally_fuse(
6787
pipeline: LoraLoaderMixin,
6888
pretrained_model_name_or_path_or_dict: Union[str, Path, Dict[str, torch.Tensor]],
@@ -186,6 +206,7 @@ def load_lora_and_optionally_fuse(
186206
)
187207

188208

209+
@deprecated()
189210
def unfuse_lora(pipeline: LoraLoaderMixin):
190211
def _unfuse_lora_apply(m: torch.nn.Module):
191212
if isinstance(m, (torch.nn.Linear, PatchedLoraProjection, torch.nn.Conv2d)):
@@ -205,6 +226,7 @@ def _unfuse_lora_apply(m: torch.nn.Module):
205226
pipeline.text_encoder_2.apply(_unfuse_lora_apply)
206227

207228

229+
@deprecated()
208230
def set_and_fuse_adapters(
209231
pipeline: LoraLoaderMixin,
210232
adapter_names: Optional[Union[List[str], str]] = None,
@@ -248,6 +270,7 @@ def set_adapters_apply(m):
248270
pipeline.text_encoder_2.apply(set_adapters_apply)
249271

250272

273+
@deprecated()
251274
def delete_adapters(
252275
self, adapter_names: Union[List[str], str] = None, safe_delete=True
253276
):
@@ -276,6 +299,7 @@ def delete_adapters_apply(m):
276299
self.text_encoder_2.apply(delete_adapters_apply)
277300

278301

302+
@deprecated()
279303
def get_active_adapters(self) -> List[str]:
280304
if hasattr(self, "_adapter_names"):
281305
return list(self._active_adapter_names.keys())

onediff_diffusers_extensions/tests/test_lora.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
)
3737

3838
image_file_prefix = "/share_nfs/onediff_ci/diffusers/images/1.0"
39+
if not Path(image_file_prefix).exists():
40+
Path(image_file_prefix).mkdir(parents=True)
3941

4042

4143
@pytest.fixture
@@ -163,6 +165,7 @@ def preload_multi_loras(pipe, loras):
163165
unfuse_lora(pipe)
164166

165167

168+
@pytest.mark.skip(reason="onediffx.lora is deprecated")
166169
def test_lora_loading(pipe, get_loras):
167170
pipe.unet = oneflow_compile(pipe.unet)
168171
pipe(
@@ -193,6 +196,7 @@ def test_lora_loading(pipe, get_loras):
193196
assert ssim > 0.92, f"LoRA {name} ssim too low"
194197

195198

199+
@pytest.mark.skip(reason="onediffx.lora is deprecated")
196200
def test_multi_lora_loading(pipe, get_multi_loras, get_loras):
197201
pipe.unet = oneflow_compile(pipe.unet)
198202
multi_loras = get_multi_loras()
@@ -226,6 +230,7 @@ def test_multi_lora_loading(pipe, get_multi_loras, get_loras):
226230
assert ssim > 0.92, f"LoRA {names} ssim too low"
227231

228232

233+
@pytest.mark.skip(reason="onediffx.lora is deprecated")
229234
def test_get_active_adapters(pipe, get_multi_loras, get_loras):
230235
multi_loras = get_multi_loras()
231236
preload_multi_loras(pipe, get_loras())
@@ -236,6 +241,7 @@ def test_get_active_adapters(pipe, get_multi_loras, get_loras):
236241
assert set(active_adapters) == set(names)
237242

238243

244+
@pytest.mark.skip(reason="onediffx.lora is deprecated")
239245
def test_delete_adapters(pipe, get_multi_loras, get_loras):
240246
multi_loras = get_multi_loras()
241247
for names, _ in multi_loras.items():
@@ -250,6 +256,7 @@ def test_delete_adapters(pipe, get_multi_loras, get_loras):
250256
assert set(active_adapters) == set(names) - set(names_to_delete)
251257

252258

259+
@pytest.mark.skip(reason="onediffx.lora is deprecated")
253260
def test_lora_numerical_stability():
254261
original_pipe = get_pipe("sd1.5")
255262
pipe = get_pipe("sd1.5")

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
python_requires=">=3.8.0",
1818
install_requires=[
1919
"transformers>=4.27.1",
20-
"diffusers>=0.19.3",
20+
"diffusers>=0.27.0",
2121
"accelerate",
2222
"torch",
2323
],

tests/comfy-docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ services:
3434
- ${PWD}/${COMFYUI_SRC_DIR}:/app/ComfyUI
3535
- /share_nfs/hf_models/comfyui_resources/custom_nodes/ComfyUI_IPAdapter_plus:/app/ComfyUI/custom_nodes/ComfyUI_IPAdapter_plus
3636
- /share_nfs/hf_models/comfyui_resources/input/input_image_vermeer.png:/app/ComfyUI/input/input_image_vermeer.png:ro
37+
- /share_nfs/hf_models/comfyui_resources/input/sdxl-unet-control-lora-speedup.png:/app/ComfyUI/input/sdxl-unet-control-lora-speedup.png:ro
3738
- /share_nfs/hf_models/comfyui_resources/input/a_car.png:/app/ComfyUI/input/a_car.png:ro
3839
- ${PWD}/onediff_comfy_nodes:/app/ComfyUI/custom_nodes/onediff_comfy_nodes
3940
- ${SDXL_BASE}:/app/ComfyUI/models/checkpoints/sd_xl_base_1.0.safetensors:ro
4041
- ${UNET_INT8}:/app/ComfyUI/models/unet_int8/unet_int8:ro
4142
- ${CONTROL_LORA_OPENPOSEXL2_RANK256}:/app/ComfyUI/models/controlnet/control-lora-openposeXL2-rank256.safetensors:ro
42-
- $PWD/tests/comfyui/workflows/input/control:/app/ComfyUI/input/control:ro
43+
# - $PWD/tests/comfyui/workflows/input/control:/app/ComfyUI/input/control:ro
4344
- $PWD:/src/onediff
4445
working_dir: /src/onediff
4546
restart: "no"

tests/comfyui/workflows/sdxl-control-lora-speedup.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
"Node name for S&R": "LoadImage"
124124
},
125125
"widgets_values": [
126-
"control/sdxl-unet-control-lora-speedup.png",
126+
"sdxl-unet-control-lora-speedup.png",
127127
"image"
128128
]
129129
},

0 commit comments

Comments
 (0)