Uh oh!
There was an error while loading. Please reload this page.
[Modular] support standard repo - #11944
Conversation
yiyixuxu
commented
Jul 17, 2025
cc @vladmandic let me know if this works for you |
HuggingFaceDocBuilderDev
commented
Jul 17, 2025
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
thanks @yiyixuxu, this is pretty much what i asked for! few comments:
warningswarnings during convert: warnings during generate: imagescode# pip install git+https://github.com/huggingface/diffusers@modular-standard-repoimporttorchimportdiffusersmodel='/mnt/models/stable-diffusion/mine/tempest-by-vlad-0.1.safetensors'# https://civitai.com/models/1157409/tempest-by-vlad cache_dir='/mnt/models/huggingface'modular_map= {
'StableDiffusionXLPipeline': 'StableDiffusionXLAutoBlocks',
}
defget_args():
return {
'prompt': 'a photo of an astronaut in a diner',
'num_inference_steps': 20,
'generator': torch.Generator(device='cuda').manual_seed(42),
}
defconvert_to_modular(standard_pipe):
try:
modular_cls=modular_map.get(standard_pipe.__class__.__name__, None)
ifmodular_clsisNone:
raiseValueError(f'unknown: cls={standard_pipe.__class__.__name__}')
modular_cls=getattr(diffusers, modular_cls, None)
ifmodular_clsisNone:
raiseValueError(f'invalid: cls={standard_pipe.__class__.__name__}')
modular_blocks=modular_cls()
modular_pipe=modular_blocks.init_pipeline()
components_dct= {k: vfork, vinstandard_pipe.components.items() ifvisnotNone}
modular_pipe.update_components(**components_dct, **standard_pipe.parameters)
modular_pipe.original_pipe=standard_pipeprint(f'convert: from={standard_pipe.__class__.__name__} to={modular_pipe.__class__.__name__}')
returnmodular_pipeexceptExceptionase:
print(f'convert: error={e}')
raiseedefrestore_standard(modular_pipe):
ifhasattr(modular_pipe, 'original_pipe'):
print(f'convert: from={modular_pipe.__class__.__name__} to={modular_pipe.original_pipe.__class__.__name__}')
returnmodular_pipe.original_pipedefgc():
importgcgc.collect()
torch.cuda.empty_cache()
torch.cuda.ipc_collect()
print(f'memory: free={torch.cuda.mem_get_info()[0]} peak={torch.cuda.memory_stats()["allocated_bytes.all.peak"]}')
torch.cuda.reset_peak_memory_stats()
if__name__=='__main__':
print('loading')
pipe=diffusers.StableDiffusionXLPipeline.from_single_file(model, torch_dtype=torch.bfloat16, cache_dir=cache_dir).to('cuda')
gc()
print('generate: standard')
output=pipe(**get_args())
print(f'output: {output}')
gc()
image=output.images[0]
image.save('standard-default1.png')
print('generate: modular')
pipe=convert_to_modular(pipe)
output=pipe(**get_args())
gc()
print(f'output: {output}')
image=output.intermediates['images'][0]
image.save('standard-modular1.png')
print('generate: standard')
pipe=restore_standard(pipe)
output=pipe(**get_args())
gc()
image=output.images[0]
image.save('standard-default2.png')
pipe=Nonegc() |
warningsI removed the warnings during the generation (changed to However, we are still iterating everything, so that may change in future too image differenceThe results from modular and standard pipelines are not going to be the same: Other than the guider, we are also taking this opportunity to refactor all our pipeline methods to make them more modular and easy to customize upon - this is an ongoing effort, we are likely to change more as we integrate more pipelines into modular diffusers However, once modular is out of experimental feature, moving forward, we will make sure new pipelines will have same results in both systems for now, I think if reproducibility is important for SD.NEXT users, I think we can only convert if they need to use a new guider class that's not supported in standard pipeline outputI updated image=t2i_pipe(prompt=prompt, num_inference_steps=25, output="images")[0]
image.save(f"{output_name}_1.png")
image=t2i_pipe(prompt=prompt, num_inference_steps=25).images[0]
image.save(f"{output_name}_2.png")
image=t2i_pipe(prompt=prompt, num_inference_steps=25).intermediates['images'][0]
image.save(f"{output_name}_3.png") |
thanks @yiyixuxu re: warnings - all good |
Uh oh!
There was an error while loading. Please reload this page.



fix#11915
this PR support using standard repo in Modular system
option1
option2
option3