Skip to content

Commit a707e31

Browse files
Apply style fixes
1 parent c1c0e9a commit a707e31

2 files changed

Lines changed: 20 additions & 17 deletions

File tree

src/diffusers/modular_pipelines/modular_pipeline.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,8 +1639,8 @@ def from_pretrained(
16391639
pretrained_model_name_or_path (`str` or `os.PathLike`, optional):
16401640
Path to a pretrained pipeline configuration. It will first try to load config from
16411641
`modular_model_index.json`, then fallback to `model_index.json` for compatibility with standard
1642-
non-modular repositories. If the pretrained_model_name_or_path does not contain any pipeline config, it will be set to None
1643-
during initialization.
1642+
non-modular repositories. If the pretrained_model_name_or_path does not contain any pipeline config, it
1643+
will be set to None during initialization.
16441644
trust_remote_code (`bool`, optional):
16451645
Whether to trust remote code when loading the pipeline, need to be set to True if you want to create
16461646
pipeline blocks based on the custom code in `pretrained_model_name_or_path`
@@ -2113,8 +2113,8 @@ def load_components(self, names: Optional[Union[List[str], str]] = None, **kwarg
21132113
**kwargs: additional kwargs to be passed to `from_pretrained()`.Can be:
21142114
- a single value to be applied to all components to be loaded, e.g. torch_dtype=torch.bfloat16
21152115
- a dict, e.g. torch_dtype={"unet": torch.bfloat16, "default": torch.float32}
2116-
- if potentially override ComponentSpec if passed a different loading field in kwargs, e.g. `pretrained_model_name_or_path`,
2117-
`variant`, `revision`, etc.
2116+
- if potentially override ComponentSpec if passed a different loading field in kwargs, e.g.
2117+
`pretrained_model_name_or_path`, `variant`, `revision`, etc.
21182118
"""
21192119

21202120
if names is None:
@@ -2397,12 +2397,12 @@ def _component_spec_to_dict(component_spec: ComponentSpec) -> Any:
23972397
Example:
23982398
>>> from diffusers.pipelines.modular_pipeline_utils import ComponentSpec >>> from diffusers import
23992399
UNet2DConditionModel >>> spec = ComponentSpec(
2400-
... name="unet", ... type_hint=UNet2DConditionModel, ... config=None, ... pretrained_model_name_or_path="path/to/repo", ...
2401-
subfolder="subfolder", ... variant=None, ... revision=None, ...
2402-
default_creation_method="from_pretrained",
2400+
... name="unet", ... type_hint=UNet2DConditionModel, ... config=None, ...
2401+
pretrained_model_name_or_path="path/to/repo", ... subfolder="subfolder", ... variant=None, ...
2402+
revision=None, ... default_creation_method="from_pretrained",
24032403
... ) >>> ModularPipeline._component_spec_to_dict(spec) {
2404-
"type_hint": ("diffusers", "UNet2DConditionModel"), "pretrained_model_name_or_path": "path/to/repo", "subfolder": "subfolder",
2405-
"variant": None, "revision": None,
2404+
"type_hint": ("diffusers", "UNet2DConditionModel"), "pretrained_model_name_or_path": "path/to/repo",
2405+
"subfolder": "subfolder", "variant": None, "revision": None,
24062406
}
24072407
"""
24082408
if component_spec.default_creation_method != "from_pretrained":
@@ -2451,11 +2451,13 @@ def _dict_to_component_spec(
24512451
ComponentSpec: A reconstructed ComponentSpec object.
24522452
24532453
Example:
2454-
>>> spec_dict = { ... "type_hint": ("diffusers", "UNet2DConditionModel"), ... "pretrained_model_name_or_path":
2455-
"stabilityai/stable-diffusion-xl", ... "subfolder": "unet", ... "variant": None, ... "revision": None, ...
2456-
} >>> ModularPipeline._dict_to_component_spec("unet", spec_dict) ComponentSpec(
2457-
name="unet", type_hint=UNet2DConditionModel, config=None, pretrained_model_name_or_path="stabilityai/stable-diffusion-xl",
2458-
subfolder="unet", variant=None, revision=None, default_creation_method="from_pretrained"
2454+
>>> spec_dict = { ... "type_hint": ("diffusers", "UNet2DConditionModel"), ...
2455+
"pretrained_model_name_or_path": "stabilityai/stable-diffusion-xl", ... "subfolder": "unet", ... "variant":
2456+
None, ... "revision": None, ... } >>> ModularPipeline._dict_to_component_spec("unet", spec_dict)
2457+
ComponentSpec(
2458+
name="unet", type_hint=UNet2DConditionModel, config=None,
2459+
pretrained_model_name_or_path="stabilityai/stable-diffusion-xl", subfolder="unet", variant=None,
2460+
revision=None, default_creation_method="from_pretrained"
24592461
)
24602462
"""
24612463
# make a shallow copy so we can pop() safely

src/diffusers/modular_pipelines/modular_pipeline_utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ def loading_fields(cls) -> List[str]:
183183
@property
184184
def load_id(self) -> str:
185185
"""
186-
Unique identifier for this spec's pretrained load, composed of pretrained_model_name_or_path|subfolder|variant|revision (no empty
187-
segments).
186+
Unique identifier for this spec's pretrained load, composed of
187+
pretrained_model_name_or_path|subfolder|variant|revision (no empty segments).
188188
"""
189189
if self.default_creation_method == "from_config":
190190
return "null"
@@ -203,7 +203,8 @@ def decode_load_id(cls, load_id: str) -> Dict[str, Optional[str]]:
203203
204204
Returns:
205205
Dict mapping loading field names to their values. e.g. {
206-
"pretrained_model_name_or_path": "path/to/repo", "subfolder": "subfolder", "variant": "variant", "revision": "revision"
206+
"pretrained_model_name_or_path": "path/to/repo", "subfolder": "subfolder", "variant": "variant",
207+
"revision": "revision"
207208
} If a segment value is "null", it's replaced with None. Returns None if load_id is "null" (indicating
208209
component not created with `load` method).
209210
"""

0 commit comments

Comments
 (0)