Skip to content

Commit 9c12c30

Browse files
committed
update
1 parent 0a71d38 commit 9c12c30

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

src/diffusers/loaders/lora_pipeline.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
_MODULE_NAME_TO_ATTRIBUTE_MAP_FLUX = {"x_embedder": "in_channels"}
7171

7272

73-
def _dequantize_weight_for_expanded_lora(model, module):
73+
def _maybe_dequantize_weight_for_expanded_lora(model, module):
7474
if is_bitsandbytes_available():
7575
from ..quantizers.bitsandbytes import dequantize_bnb_weight
7676

@@ -2060,8 +2060,9 @@ def _maybe_expand_transformer_param_shape_or_error_(
20602060
parent_module = transformer.get_submodule(parent_module_name)
20612061

20622062
if is_quantized:
2063-
module_weight = _dequantize_weight_for_expanded_lora(transformer, module)
2063+
module_weight = _maybe_dequantize_weight_for_expanded_lora(transformer, module)
20642064

2065+
# TODO: consider if this layer needs to be a quantized layer as well if `is_quantized` is True.
20652066
with torch.device("meta"):
20662067
expanded_module = torch.nn.Linear(
20672068
in_features, out_features, bias=bias, dtype=module_weight.dtype

tests/quantization/gguf/test_gguf.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,22 @@
88
from diffusers import (
99
AuraFlowPipeline,
1010
AuraFlowTransformer2DModel,
11+
FluxControlPipeline,
1112
FluxPipeline,
1213
FluxTransformer2DModel,
1314
GGUFQuantizationConfig,
1415
SD3Transformer2DModel,
1516
StableDiffusion3Pipeline,
1617
)
18+
from diffusers.utils import load_image
1719
from diffusers.utils.testing_utils import (
1820
is_gguf_available,
1921
nightly,
2022
numpy_cosine_similarity_distance,
2123
require_accelerate,
2224
require_big_gpu_with_torch_cuda,
2325
require_gguf_version_greater_or_equal,
26+
require_peft_backend,
2427
torch_device,
2528
)
2629

@@ -456,3 +459,46 @@ def test_pipeline_inference(self):
456459
)
457460
max_diff = numpy_cosine_similarity_distance(expected_slice, output_slice)
458461
assert max_diff < 1e-4
462+
463+
464+
@require_peft_backend
465+
@nightly
466+
@require_big_gpu_with_torch_cuda
467+
@require_accelerate
468+
@require_gguf_version_greater_or_equal("0.10.0")
469+
class FluxControlLoRAGGUFTests(unittest.TestCase):
470+
def test_lora_loading(self):
471+
ckpt_path = "https://huggingface.co/city96/FLUX.1-dev-gguf/blob/main/flux1-dev-Q2_K.gguf"
472+
transformer = FluxTransformer2DModel.from_single_file(
473+
ckpt_path,
474+
quantization_config=GGUFQuantizationConfig(compute_dtype=torch.bfloat16),
475+
torch_dtype=torch.bfloat16,
476+
)
477+
pipe = FluxControlPipeline.from_pretrained(
478+
"black-forest-labs/FLUX.1-dev",
479+
transformer=transformer,
480+
torch_dtype=torch.bfloat16,
481+
).to("cuda")
482+
pipe.load_lora_weights("black-forest-labs/FLUX.1-Canny-dev-lora")
483+
484+
prompt = "A robot made of exotic candies and chocolates of different kinds. The background is filled with confetti and celebratory gifts."
485+
control_image = load_image(
486+
"https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/control_image_robot_canny.png"
487+
)
488+
489+
output = pipe(
490+
prompt=prompt,
491+
control_image=control_image,
492+
height=256,
493+
width=256,
494+
num_inference_steps=10,
495+
guidance_scale=30.0,
496+
output_type="np",
497+
generator=torch.manual_seed(0),
498+
).images
499+
500+
out_slice = output[0, -3:, -3:, -1].flatten()
501+
expected_slice = np.array([0.8047, 0.8359, 0.8711, 0.6875, 0.7070, 0.7383, 0.5469, 0.5820, 0.6641])
502+
503+
max_diff = numpy_cosine_similarity_distance(expected_slice, out_slice)
504+
self.assertTrue(max_diff < 1e-3)

0 commit comments

Comments
 (0)