-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Krea2 Modular Pipeline Support, Documentation, Test Cases #14083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6f8e01b
2bae576
30c5138
7450dc4
4e4da7f
4da8d49
bc0c912
689ee82
d235700
5a609ca
3de62bd
988beb9
8022f8e
93f59d9
e6e288f
afd27d3
3de7fad
e3b07ab
909bcc5
07ccbb2
ec123ba
debb4dd
0eeca0d
a21b285
421d212
2750680
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,7 @@ import torch | |
| from diffusers import Krea2Pipeline | ||
|
|
||
| # Load from a local directory produced by the Krea 2 conversion (no hub repo yet). | ||
| pipe = Krea2Pipeline.from_pretrained("path/to/krea2-diffusers", torch_dtype=torch.bfloat16) | ||
| pipe = Krea2Pipeline.from_pretrained("krea/Krea-2-Raw", torch_dtype=torch.bfloat16) | ||
| pipe.to("cuda") | ||
|
|
||
| prompt = "a fox in the snow" | ||
|
|
@@ -50,6 +50,27 @@ image = pipe( | |
| image.save("krea2.png") | ||
| ``` | ||
|
|
||
| We additionally provide an example for using Krea2 Turbo : | ||
|
|
||
| ```python | ||
| import torch | ||
| from diffusers import Krea2Pipeline | ||
|
|
||
| pipe = Krea2Pipeline.from_pretrained("krea/Krea-2-Turbo", torch_dtype=torch.bfloat16) | ||
| pipe.to("cuda") | ||
|
|
||
| image = pipe( | ||
| "a fox in the snow", | ||
| height=1024, | ||
| width=1024, | ||
| num_inference_steps=8, | ||
| guidance_scale=0.0, | ||
| generator=torch.Generator("cuda").manual_seed(0), | ||
| ).images[0] | ||
| image.save("krea2_turbo.png") | ||
| ``` | ||
|
|
||
|
|
||
| ## Krea2Pipeline | ||
|
|
||
| [[autodoc]] Krea2Pipeline | ||
|
|
@@ -59,3 +80,61 @@ image.save("krea2.png") | |
| ## Krea2PipelineOutput | ||
|
|
||
| [[autodoc]] pipelines.krea2.pipeline_output.Krea2PipelineOutput | ||
|
|
||
| ## Modular | ||
|
|
||
| Krea 2 is also available as a [modular pipeline](../../modular_diffusers/overview). Classifier-free guidance is | ||
| configured through the `guider` component rather than a `guidance_scale` call argument. Krea 2 uses cond-anchored CFG, | ||
| which is [`ClassifierFreeGuidance`] with `use_original_formulation=True`; a scale of `0.0` disables guidance (the TDM | ||
| checkpoint). | ||
|
|
||
| ```python | ||
| import torch | ||
| from diffusers import ClassifierFreeGuidance, ModularPipeline | ||
|
|
||
| pipe = ModularPipeline.from_pretrained("krea/Krea-2-Raw") | ||
| pipe.load_components(torch_dtype=torch.bfloat16) | ||
| pipe.to("cuda") | ||
|
|
||
| pipe.update_components(guider=ClassifierFreeGuidance(guidance_scale=4.5, use_original_formulation=True)) | ||
|
|
||
| image = pipe( | ||
| prompt="a fox in the snow", | ||
| height=1024, | ||
| width=1024, | ||
| num_inference_steps=28, | ||
| generator=torch.Generator("cuda").manual_seed(0), | ||
| ).images[0] | ||
| image.save("krea2.png") | ||
| ``` | ||
|
|
||
| We additionally provide an example for using Krea2 Turbo. The distilled checkpoint disables guidance by | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ohh i think turbo should have its own set of blocks that it maps to, it is a different checkpoint this way the distilled krea should not accept negative prompt and it should have guider disabled by default |
||
| setting the `guider` scale to `0.0` and samples in a few steps: | ||
|
|
||
| ```python | ||
| import torch | ||
| from diffusers import ClassifierFreeGuidance, ModularPipeline | ||
|
|
||
| pipe = ModularPipeline.from_pretrained("krea/Krea-2-Turbo") | ||
| pipe.load_components(torch_dtype=torch.bfloat16) | ||
| pipe.to("cuda") | ||
|
|
||
| pipe.update_components(guider=ClassifierFreeGuidance(guidance_scale=0.0, use_original_formulation=True)) | ||
|
|
||
| image = pipe( | ||
| prompt="a fox in the snow", | ||
| height=1024, | ||
| width=1024, | ||
| num_inference_steps=8, | ||
| generator=torch.Generator("cuda").manual_seed(0), | ||
| ).images[0] | ||
| image.save("krea2_turbo.png") | ||
| ``` | ||
|
|
||
| ## Krea2ModularPipeline | ||
|
|
||
| [[autodoc]] Krea2ModularPipeline | ||
|
|
||
| ## Krea2AutoBlocks | ||
|
|
||
| [[autodoc]] Krea2AutoBlocks | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from ...utils import ( | ||
| DIFFUSERS_SLOW_IMPORT, | ||
| OptionalDependencyNotAvailable, | ||
| _LazyModule, | ||
| get_objects_from_module, | ||
| is_torch_available, | ||
| is_transformers_available, | ||
| ) | ||
|
|
||
|
|
||
| _dummy_objects = {} | ||
| _import_structure = {} | ||
|
|
||
| try: | ||
| if not (is_transformers_available() and is_torch_available()): | ||
| raise OptionalDependencyNotAvailable() | ||
| except OptionalDependencyNotAvailable: | ||
| from ...utils import dummy_torch_and_transformers_objects # noqa F403 | ||
|
|
||
| _dummy_objects.update(get_objects_from_module(dummy_torch_and_transformers_objects)) | ||
| else: | ||
| _import_structure["modular_blocks_krea2"] = ["Krea2AutoBlocks"] | ||
| _import_structure["modular_pipeline"] = ["Krea2ModularPipeline"] | ||
|
|
||
| if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT: | ||
| try: | ||
| if not (is_transformers_available() and is_torch_available()): | ||
| raise OptionalDependencyNotAvailable() | ||
| except OptionalDependencyNotAvailable: | ||
| from ...utils.dummy_torch_and_transformers_objects import * # noqa F403 | ||
| else: | ||
| from .modular_blocks_krea2 import Krea2AutoBlocks | ||
| from .modular_pipeline import Krea2ModularPipeline | ||
| else: | ||
| import sys | ||
|
|
||
| sys.modules[__name__] = _LazyModule( | ||
| __name__, | ||
| globals()["__file__"], | ||
| _import_structure, | ||
| module_spec=__spec__, | ||
| ) | ||
|
|
||
| for name, value in _dummy_objects.items(): | ||
| setattr(sys.modules[__name__], name, value) |
Uh oh!
There was an error while loading. Please reload this page.