Skip to content

corrects single file path validation logic#13363

Open
andrew-w-ross wants to merge 1 commit intohuggingface:mainfrom
andrew-w-ross:fix-single-file-path-check
Open

corrects single file path validation logic#13363
andrew-w-ross wants to merge 1 commit intohuggingface:mainfrom
andrew-w-ross:fix-single-file-path-check

Conversation

@andrew-w-ross
Copy link
Copy Markdown

@andrew-w-ross andrew-w-ross commented Mar 30, 2026

What does this PR do?

Fix's loading ModularPipelines loading component specs where pretrained_model_name_or_path is a path.

Didn't bother opening an issue considering the tiny size of the fix.

Before submitting

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

Copy link
Copy Markdown
Collaborator

@DN6 DN6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @andrew-w-ross! Small change requested to the test, but good to merge once that's updated 👍🏽

Comment on lines +730 to +751
def test_load_components_loads_local_single_file_path(self, tmp_path):
pipe = ModularPipeline.from_pretrained("hf-internal-testing/tiny-stable-diffusion-xl-pipe")

local_ckpt_path = hf_hub_download(
repo_id="lllyasviel/ControlNet-v1-1",
filename="control_v11p_sd15_canny.pth",
local_dir=str(tmp_path),
)

pipe._component_specs["controlnet"] = ComponentSpec(
name="controlnet",
type_hint=ControlNetModel,
pretrained_model_name_or_path=local_ckpt_path,
)

pipe.load_components(names="controlnet")

assert pipe.controlnet is not None
assert isinstance(pipe.controlnet, ControlNetModel)
assert pipe._component_specs["controlnet"].pretrained_model_name_or_path == local_ckpt_path
assert getattr(pipe.controlnet, "_diffusers_load_id", None) not in (None, "null")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small update to the test so we use a tiny controlnet instead of the larger ~1GB one in this test.

Suggested change
def test_load_components_loads_local_single_file_path(self, tmp_path):
pipe = ModularPipeline.from_pretrained("hf-internal-testing/tiny-stable-diffusion-xl-pipe")
local_ckpt_path = hf_hub_download(
repo_id="lllyasviel/ControlNet-v1-1",
filename="control_v11p_sd15_canny.pth",
local_dir=str(tmp_path),
)
pipe._component_specs["controlnet"] = ComponentSpec(
name="controlnet",
type_hint=ControlNetModel,
pretrained_model_name_or_path=local_ckpt_path,
)
pipe.load_components(names="controlnet")
assert pipe.controlnet is not None
assert isinstance(pipe.controlnet, ControlNetModel)
assert pipe._component_specs["controlnet"].pretrained_model_name_or_path == local_ckpt_path
assert getattr(pipe.controlnet, "_diffusers_load_id", None) not in (None, "null")
def test_load_components_loads_local_single_file_path(self, tmp_path):
pipe = ModularPipeline.from_pretrained("hf-internal-testing/tiny-stable-diffusion-xl-pipe")
model = ControlNetModel.from_pretrained("hf-internal-testing/tiny-controlnet")
model.save_pretrained(tmp_path)
local_ckpt_path = str(tmp_path / "diffusion_pytorch_model.safetensors")
pipe._component_specs["controlnet"] = ComponentSpec(
name="controlnet",
type_hint=ControlNetModel,
pretrained_model_name_or_path=local_ckpt_path,
)
pipe.load_components(names="controlnet", config=str(tmp_path))
assert pipe.controlnet is not None
assert isinstance(pipe.controlnet, ControlNetModel)
assert pipe._component_specs["controlnet"].pretrained_model_name_or_path == local_ckpt_path
assert getattr(pipe.controlnet, "_diffusers_load_id", None) not in (None, "null")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants