Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
diffusers
Commits
577b8a27
Unverified
Commit
577b8a27
authored
Mar 05, 2024
by
Sayak Paul
Committed by
GitHub
Mar 05, 2024
Browse files
[Core] errors should be caught as soon as possible. (#7203)
errors should be caught as soon as possible.
parent
13f0c8b2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
27 deletions
+27
-27
src/diffusers/pipelines/pipeline_utils.py
src/diffusers/pipelines/pipeline_utils.py
+27
-27
No files found.
src/diffusers/pipelines/pipeline_utils.py
View file @
577b8a27
...
...
@@ -1079,6 +1079,33 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
use_onnx
=
kwargs
.
pop
(
"use_onnx"
,
None
)
load_connected_pipeline
=
kwargs
.
pop
(
"load_connected_pipeline"
,
False
)
if
low_cpu_mem_usage
and
not
is_accelerate_available
():
low_cpu_mem_usage
=
False
logger
.
warning
(
"Cannot initialize model with low cpu memory usage because `accelerate` was not found in the"
" environment. Defaulting to `low_cpu_mem_usage=False`. It is strongly recommended to install"
" `accelerate` for faster and less memory-intense model loading. You can do so with:
\n
```
\n
pip"
" install accelerate
\n
```
\n
."
)
if
device_map
is
not
None
and
not
is_torch_version
(
">="
,
"1.9.0"
):
raise
NotImplementedError
(
"Loading and dispatching requires torch >= 1.9.0. Please either update your PyTorch version or set"
" `device_map=None`."
)
if
low_cpu_mem_usage
is
True
and
not
is_torch_version
(
">="
,
"1.9.0"
):
raise
NotImplementedError
(
"Low memory initialization requires torch >= 1.9.0. Please either update your PyTorch version or set"
" `low_cpu_mem_usage=False`."
)
if
low_cpu_mem_usage
is
False
and
device_map
is
not
None
:
raise
ValueError
(
f
"You cannot set `low_cpu_mem_usage` to False while using device_map=
{
device_map
}
for loading and"
" dispatching. Please make sure to set `low_cpu_mem_usage=True`."
)
# 1. Download the checkpoints and configs
# use snapshot download here to get it working from from_pretrained
if
not
os
.
path
.
isdir
(
pretrained_model_name_or_path
):
...
...
@@ -1211,33 +1238,6 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
f
"Keyword arguments
{
unused_kwargs
}
are not expected by
{
pipeline_class
.
__name__
}
and will be ignored."
)
if
low_cpu_mem_usage
and
not
is_accelerate_available
():
low_cpu_mem_usage
=
False
logger
.
warning
(
"Cannot initialize model with low cpu memory usage because `accelerate` was not found in the"
" environment. Defaulting to `low_cpu_mem_usage=False`. It is strongly recommended to install"
" `accelerate` for faster and less memory-intense model loading. You can do so with:
\n
```
\n
pip"
" install accelerate
\n
```
\n
."
)
if
device_map
is
not
None
and
not
is_torch_version
(
">="
,
"1.9.0"
):
raise
NotImplementedError
(
"Loading and dispatching requires torch >= 1.9.0. Please either update your PyTorch version or set"
" `device_map=None`."
)
if
low_cpu_mem_usage
is
True
and
not
is_torch_version
(
">="
,
"1.9.0"
):
raise
NotImplementedError
(
"Low memory initialization requires torch >= 1.9.0. Please either update your PyTorch version or set"
" `low_cpu_mem_usage=False`."
)
if
low_cpu_mem_usage
is
False
and
device_map
is
not
None
:
raise
ValueError
(
f
"You cannot set `low_cpu_mem_usage` to False while using device_map=
{
device_map
}
for loading and"
" dispatching. Please make sure to set `low_cpu_mem_usage=True`."
)
# import it here to avoid circular import
from
diffusers
import
pipelines
...
...
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