From 74e2c61501a63861cd4b04ae17e1093a4ffde83e Mon Sep 17 00:00:00 2001 From: Subodh Bansode Date: Tue, 6 Oct 2026 14:37:18 +0530 Subject: [PATCH 1/2] Fix active adapter detection for text encoders Signed-off-by: Subodh Bansode --- src/diffusers/loaders/lora_base.py | 2 +- tests/lora/utils.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/diffusers/loaders/lora_base.py b/src/diffusers/loaders/lora_base.py index ec23d6e09d22..6c383b1c3347 100644 --- a/src/diffusers/loaders/lora_base.py +++ b/src/diffusers/loaders/lora_base.py @@ -921,7 +921,7 @@ def get_active_adapters(self) -> list[str]: for component in self._lora_loadable_modules: model = getattr(self, component, None) - if model is not None and issubclass(model.__class__, ModelMixin): + if model is not None and issubclass(model.__class__, (ModelMixin, PreTrainedModel)): for module in model.modules(): if isinstance(module, BaseTunerLayer): active_adapters = module.active_adapters diff --git a/tests/lora/utils.py b/tests/lora/utils.py index dacfd61cc9f0..ea832f2e4de1 100644 --- a/tests/lora/utils.py +++ b/tests/lora/utils.py @@ -500,6 +500,21 @@ def test_simple_inference_with_text_lora_unloaded(self): "Fused lora should change the output", ) + def test_get_active_adapters_text_encoder_only(self): + """ + Tests that get_active_adapters correctly reports active adapters when only the text encoder has a LoRA attached. + """ + if not self.supports_text_encoder_loras: + pytest.skip("Skipping test as text encoder LoRAs are not currently supported.") + + components, text_lora_config, _ = self.get_dummy_components() + pipe = self.pipeline_class(**components) + pipe = pipe.to(torch_device) + + pipe, _ = self.add_adapters_to_pipeline(pipe, text_lora_config, denoiser_lora_config=None, adapter_name="default") + + self.assertEqual(pipe.get_active_adapters(), ["default"]) + def test_simple_inference_with_text_lora_save_load(self): """ Tests a simple usecase where users could use saving utilities for LoRA. From f656aa9a5660fe50548f7f1df48150967dad7442 Mon Sep 17 00:00:00 2001 From: Subodh Bansode Date: Thu, 8 Oct 2026 10:15:08 +0530 Subject: [PATCH 2/2] test: move text encoder adapter regression test Signed-off-by: Subodh Bansode --- tests/lora/utils.py | 15 --------------- tests/pipelines/testing_utils/lora.py | 12 ++++++++++++ 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/tests/lora/utils.py b/tests/lora/utils.py index ea832f2e4de1..dacfd61cc9f0 100644 --- a/tests/lora/utils.py +++ b/tests/lora/utils.py @@ -500,21 +500,6 @@ def test_simple_inference_with_text_lora_unloaded(self): "Fused lora should change the output", ) - def test_get_active_adapters_text_encoder_only(self): - """ - Tests that get_active_adapters correctly reports active adapters when only the text encoder has a LoRA attached. - """ - if not self.supports_text_encoder_loras: - pytest.skip("Skipping test as text encoder LoRAs are not currently supported.") - - components, text_lora_config, _ = self.get_dummy_components() - pipe = self.pipeline_class(**components) - pipe = pipe.to(torch_device) - - pipe, _ = self.add_adapters_to_pipeline(pipe, text_lora_config, denoiser_lora_config=None, adapter_name="default") - - self.assertEqual(pipe.get_active_adapters(), ["default"]) - def test_simple_inference_with_text_lora_save_load(self): """ Tests a simple usecase where users could use saving utilities for LoRA. diff --git a/tests/pipelines/testing_utils/lora.py b/tests/pipelines/testing_utils/lora.py index 87d1da8fac52..661d2908b9ec 100644 --- a/tests/pipelines/testing_utils/lora.py +++ b/tests/pipelines/testing_utils/lora.py @@ -700,6 +700,18 @@ def test_simple_inference_with_text_denoiser_multi_adapter_weighted(self, base_p msg="output with no lora and output with lora disabled should give same results", ) + def test_get_active_adapters_text_encoder_only(self): + """ + Tests that get_active_adapters correctly reports active adapters when only the text encoder has a LoRA attached. + """ + if not self.text_encoder_components: + pytest.skip("Skipping test as text encoder LoRAs are not currently supported.") + + pipe = self.get_pipeline().to(torch_device) + self.add_adapters_to_pipeline(pipe, components=self.text_encoder_components, adapter_name="default") + + assert pipe.get_active_adapters() == ["default"] + def test_get_adapters(self): pipe = self.get_pipeline().to(torch_device)