Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
renzhc
diffusers_dcu
Commits
638cc035
Unverified
Commit
638cc035
authored
Jul 21, 2025
by
YiYi Xu
Committed by
GitHub
Jul 21, 2025
Browse files
[Modular] update the collection behavior (#11963)
* only remove from the collection
parent
9db9be65
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
2 deletions
+26
-2
src/diffusers/modular_pipelines/components_manager.py
src/diffusers/modular_pipelines/components_manager.py
+24
-2
src/diffusers/modular_pipelines/modular_pipeline_utils.py
src/diffusers/modular_pipelines/modular_pipeline_utils.py
+2
-0
No files found.
src/diffusers/modular_pipelines/components_manager.py
View file @
638cc035
...
@@ -386,6 +386,7 @@ class ComponentsManager:
...
@@ -386,6 +386,7 @@ class ComponentsManager:
id(component) is Python's built-in unique identifier for the object
id(component) is Python's built-in unique identifier for the object
"""
"""
component_id
=
f
"
{
name
}
_
{
id
(
component
)
}
"
component_id
=
f
"
{
name
}
_
{
id
(
component
)
}
"
is_new_component
=
True
# check for duplicated components
# check for duplicated components
for
comp_id
,
comp
in
self
.
components
.
items
():
for
comp_id
,
comp
in
self
.
components
.
items
():
...
@@ -394,6 +395,7 @@ class ComponentsManager:
...
@@ -394,6 +395,7 @@ class ComponentsManager:
if
comp_name
==
name
:
if
comp_name
==
name
:
logger
.
warning
(
f
"ComponentsManager: component '
{
name
}
' already exists as '
{
comp_id
}
'"
)
logger
.
warning
(
f
"ComponentsManager: component '
{
name
}
' already exists as '
{
comp_id
}
'"
)
component_id
=
comp_id
component_id
=
comp_id
is_new_component
=
False
break
break
else
:
else
:
logger
.
warning
(
logger
.
warning
(
...
@@ -426,7 +428,9 @@ class ComponentsManager:
...
@@ -426,7 +428,9 @@ class ComponentsManager:
logger
.
warning
(
logger
.
warning
(
f
"ComponentsManager: removing existing
{
name
}
from collection '
{
collection
}
':
{
comp_id
}
"
f
"ComponentsManager: removing existing
{
name
}
from collection '
{
collection
}
':
{
comp_id
}
"
)
)
self
.
remove
(
comp_id
)
# remove existing component from this collection (if it is not in any other collection, will be removed from ComponentsManager)
self
.
remove_from_collection
(
comp_id
,
collection
)
self
.
collections
[
collection
].
add
(
component_id
)
self
.
collections
[
collection
].
add
(
component_id
)
logger
.
info
(
logger
.
info
(
f
"ComponentsManager: added component '
{
name
}
' in collection '
{
collection
}
':
{
component_id
}
"
f
"ComponentsManager: added component '
{
name
}
' in collection '
{
collection
}
':
{
component_id
}
"
...
@@ -434,11 +438,29 @@ class ComponentsManager:
...
@@ -434,11 +438,29 @@ class ComponentsManager:
else
:
else
:
logger
.
info
(
f
"ComponentsManager: added component '
{
name
}
' as '
{
component_id
}
'"
)
logger
.
info
(
f
"ComponentsManager: added component '
{
name
}
' as '
{
component_id
}
'"
)
if
self
.
_auto_offload_enabled
:
if
self
.
_auto_offload_enabled
and
is_new_component
:
self
.
enable_auto_cpu_offload
(
self
.
_auto_offload_device
)
self
.
enable_auto_cpu_offload
(
self
.
_auto_offload_device
)
return
component_id
return
component_id
def
remove_from_collection
(
self
,
component_id
:
str
,
collection
:
str
):
"""
Remove a component from a collection.
"""
if
collection
not
in
self
.
collections
:
logger
.
warning
(
f
"Collection '
{
collection
}
' not found in ComponentsManager"
)
return
if
component_id
not
in
self
.
collections
[
collection
]:
logger
.
warning
(
f
"Component '
{
component_id
}
' not found in collection '
{
collection
}
'"
)
return
# remove from the collection
self
.
collections
[
collection
].
remove
(
component_id
)
# check if this component is in any other collection
comp_colls
=
[
coll
for
coll
,
comps
in
self
.
collections
.
items
()
if
component_id
in
comps
]
if
not
comp_colls
:
# only if no other collection contains this component, remove it
logger
.
warning
(
f
"ComponentsManager: removing component '
{
component_id
}
' from ComponentsManager"
)
self
.
remove
(
component_id
)
def
remove
(
self
,
component_id
:
str
=
None
):
def
remove
(
self
,
component_id
:
str
=
None
):
"""
"""
Remove a component from the ComponentsManager.
Remove a component from the ComponentsManager.
...
...
src/diffusers/modular_pipelines/modular_pipeline_utils.py
View file @
638cc035
...
@@ -185,6 +185,8 @@ class ComponentSpec:
...
@@ -185,6 +185,8 @@ class ComponentSpec:
Unique identifier for this spec's pretrained load, composed of repo|subfolder|variant|revision (no empty
Unique identifier for this spec's pretrained load, composed of repo|subfolder|variant|revision (no empty
segments).
segments).
"""
"""
if
self
.
default_creation_method
==
"from_config"
:
return
"null"
parts
=
[
getattr
(
self
,
k
)
for
k
in
self
.
loading_fields
()]
parts
=
[
getattr
(
self
,
k
)
for
k
in
self
.
loading_fields
()]
parts
=
[
"null"
if
p
is
None
else
p
for
p
in
parts
]
parts
=
[
"null"
if
p
is
None
else
p
for
p
in
parts
]
return
"|"
.
join
(
p
for
p
in
parts
if
p
)
return
"|"
.
join
(
p
for
p
in
parts
if
p
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment