Skip to content

[modular] not pass trust_remote_code to external repos #13204

Merged
yiyixuxu merged 9 commits intomainfrom
modular-not-remote-unless-local
Mar 3, 2026
Merged

[modular] not pass trust_remote_code to external repos #13204
yiyixuxu merged 9 commits intomainfrom
modular-not-remote-unless-local

Conversation

@yiyixuxu
Copy link
Collaborator

@yiyixuxu yiyixuxu commented Mar 2, 2026

based on this discussion
huggingface/blog#3278 (comment)

@yiyixuxu yiyixuxu requested review from DN6 and sayakpaul March 3, 2026 06:02
Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

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

I like it!

I left some thoughts to discuss. LMK if anything is unclear.

Comment on lines +2361 to +2366
f"To load this component manually:\n"
f" from diffusers import AutoModel\n"
f' {name} = AutoModel.from_pretrained("{spec.pretrained_model_name_or_path}", trust_remote_code=True)\n'
f" pipe.update_components({name} = {name})\n"
)
logger.warning(warning_msg)
Copy link
Member

Choose a reason for hiding this comment

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

Of course, we cannot generalize to all possible combinations but what if the underlying component is a scheduler or a non-modeling component?

For schedulers, we could have AutoScheduler or something so that users won't have to remember a specific class name. For others (such as tokenizers, image processors), we already have "auto" classes.

I guess it's not that big a use case yet, but just wanted to flag.

Copy link
Member

Choose a reason for hiding this comment

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

Also, should we error instead? If the user-side logger is not configured appropriately then this warning could go unnoticed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i updated the message
tried to make it error but reverted back to warning for now: it would be a little annoying that you won't be able to use load_components() because one element is not loadable


block = ModularPipelineBlocks.from_pretrained(pipeline_repo_dir, trust_remote_code=True)
pipe = block.init_pipeline()
pipe.save_pretrained(pipeline_repo_dir)
Copy link
Member

Choose a reason for hiding this comment

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

Should we also inspect the modular_model_index.json file here (checking if the repo paths were serialized as expected)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think if we can load it back, we are fine (we loaded it back next and verified the path too)

Copy link
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.

Thanks 👍🏽

yiyixuxu and others added 2 commits March 3, 2026 00:33
Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>
assert pipe.unet is not None
assert getattr(pipe, "vae", None) is None

def test_load_components_selective_loading_incremental(self):
Copy link
Member

Choose a reason for hiding this comment

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

Do we also test if pipe doesn't have other expected components (like scheduler)?

Comment on lines +2364 to +2367
f"to the pipeline via `pipe.update_components()`. For example, if it is a custom model:\n\n"
f' {name} = AutoModel.from_pretrained("{spec.pretrained_model_name_or_path}", trust_remote_code=True)\n'
f" pipe.update_components({name}={name})\n"
)
Copy link
Member

Choose a reason for hiding this comment

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

This is perfect, thank you!

Comment on lines +767 to +769
import json

from diffusers import UNet2DConditionModel
Copy link
Member

Choose a reason for hiding this comment

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

(nit): maybe we could shift all the imports to the top.

for key in original_state_dict:
assert torch.equal(original_state_dict[key], loaded_state_dict[key]), f"Mismatch in {key}"

def test_save_pretrained_updates_index_for_model_with_no_load_id(self, tmp_path):
Copy link
Member

Choose a reason for hiding this comment

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

Very cool test!

@yiyixuxu yiyixuxu merged commit 1fe688a into main Mar 3, 2026
16 checks passed
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.

3 participants