From 1c2089ed718aa387196c49fe92515c671adc53a6 Mon Sep 17 00:00:00 2001 From: xodn348 Date: Wed, 13 May 2026 09:18:33 +0000 Subject: [PATCH] fix(dynamic_modules): enforce trust_remote_code for community pipeline branch --- src/diffusers/utils/dynamic_modules_utils.py | 6 ++++++ tests/pipelines/test_pipelines.py | 13 +++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/diffusers/utils/dynamic_modules_utils.py b/src/diffusers/utils/dynamic_modules_utils.py index 46aeb514484d..0013bd0bf55c 100644 --- a/src/diffusers/utils/dynamic_modules_utils.py +++ b/src/diffusers/utils/dynamic_modules_utils.py @@ -327,6 +327,12 @@ def get_cached_module_file( f"Pass `trust_remote_code=True` to allow loading remote code modules." ) elif is_community_pipeline: + if not trust_remote_code: + raise ValueError( + f"Loading community pipeline '{pretrained_model_name_or_path}' requires executing code " + f"from the diffusers/community-pipelines-mirror dataset.\n" + f"Pass `trust_remote_code=True` to allow loading community pipeline code modules." + ) available_versions = get_diffusers_versions() # cut ".dev0" latest_version = "v" + ".".join(__version__.split(".")[:3]) diff --git a/tests/pipelines/test_pipelines.py b/tests/pipelines/test_pipelines.py index 1df2cfa569e7..f1fb27c216d3 100644 --- a/tests/pipelines/test_pipelines.py +++ b/tests/pipelines/test_pipelines.py @@ -1064,8 +1064,17 @@ def test_global_disable_remote_code(self): ) def test_load_custom_github(self): + with self.assertRaises(ValueError) as cm: + DiffusionPipeline.from_pretrained( + "google/ddpm-cifar10-32", custom_pipeline="one_step_unet", custom_revision="main" + ) + self.assertIn( + "Pass `trust_remote_code=True` to allow loading community pipeline code modules.", + str(cm.exception), + ) + pipeline = DiffusionPipeline.from_pretrained( - "google/ddpm-cifar10-32", custom_pipeline="one_step_unet", custom_revision="main" + "google/ddpm-cifar10-32", custom_pipeline="one_step_unet", custom_revision="main", trust_remote_code=True ) # make sure that on "main" pipeline gives only ones because of: https://github.com/huggingface/diffusers/pull/1690 @@ -1079,7 +1088,7 @@ def test_load_custom_github(self): del sys.modules["diffusers_modules.git.one_step_unet"] pipeline = DiffusionPipeline.from_pretrained( - "google/ddpm-cifar10-32", custom_pipeline="one_step_unet", custom_revision="0.10.2" + "google/ddpm-cifar10-32", custom_pipeline="one_step_unet", custom_revision="0.10.2", trust_remote_code=True ) with torch.no_grad(): output = pipeline()