Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
0f8603a5
Commit
0f8603a5
authored
Jan 10, 2023
by
AUTOMATIC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add support for transformers==4.25.1
add fallback for when quick model creation fails
parent
ce3f639e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
8 deletions
+42
-8
modules/sd_disable_initialization.py
modules/sd_disable_initialization.py
+36
-6
modules/sd_models.py
modules/sd_models.py
+6
-2
No files found.
modules/sd_disable_initialization.py
View file @
0f8603a5
...
...
@@ -30,30 +30,53 @@ class DisableInitialization:
def
CLIPTextModel_from_pretrained
(
pretrained_model_name_or_path
,
*
model_args
,
**
kwargs
):
return
self
.
CLIPTextModel_from_pretrained
(
None
,
*
model_args
,
config
=
pretrained_model_name_or_path
,
state_dict
=
{},
**
kwargs
)
def
transformers_utils_hub_get_from_cache
(
url
,
*
args
,
local_files_only
=
False
,
**
kwargs
):
def
transformers_modeling_utils_load_pretrained_model
(
*
args
,
**
kwargs
):
args
=
args
[
0
:
3
]
+
(
'/'
,
)
+
args
[
4
:]
# resolved_archive_file; must set it to something to prevent what seems to be a bug
return
self
.
transformers_modeling_utils_load_pretrained_model
(
*
args
,
**
kwargs
)
def
transformers_utils_hub_get_file_from_cache
(
original
,
url
,
*
args
,
**
kwargs
):
# this file is always 404, prevent making request
if
url
==
'https://huggingface.co/openai/clip-vit-large-patch14/resolve/main/added_tokens.json'
:
raise
transformers
.
utils
.
hub
.
EntryNotFoundError
try
:
return
self
.
transformers_utils_hub_get_from_cache
(
url
,
*
args
,
local_files_only
=
True
,
**
kwargs
)
return
original
(
url
,
*
args
,
local_files_only
=
True
,
**
kwargs
)
except
Exception
as
e
:
return
self
.
transformers_utils_hub_get_from_cache
(
url
,
*
args
,
local_files_only
=
False
,
**
kwargs
)
return
original
(
url
,
*
args
,
local_files_only
=
False
,
**
kwargs
)
def
transformers_utils_hub_get_from_cache
(
url
,
*
args
,
local_files_only
=
False
,
**
kwargs
):
return
transformers_utils_hub_get_file_from_cache
(
self
.
transformers_utils_hub_get_from_cache
,
url
,
*
args
,
**
kwargs
)
def
transformers_tokenization_utils_base_cached_file
(
url
,
*
args
,
local_files_only
=
False
,
**
kwargs
):
return
transformers_utils_hub_get_file_from_cache
(
self
.
transformers_tokenization_utils_base_cached_file
,
url
,
*
args
,
**
kwargs
)
def
transformers_configuration_utils_cached_file
(
url
,
*
args
,
local_files_only
=
False
,
**
kwargs
):
return
transformers_utils_hub_get_file_from_cache
(
self
.
transformers_configuration_utils_cached_file
,
url
,
*
args
,
**
kwargs
)
self
.
init_kaiming_uniform
=
torch
.
nn
.
init
.
kaiming_uniform_
self
.
init_no_grad_normal
=
torch
.
nn
.
init
.
_no_grad_normal_
self
.
init_no_grad_uniform_
=
torch
.
nn
.
init
.
_no_grad_uniform_
self
.
create_model_and_transforms
=
open_clip
.
create_model_and_transforms
self
.
CLIPTextModel_from_pretrained
=
ldm
.
modules
.
encoders
.
modules
.
CLIPTextModel
.
from_pretrained
self
.
transformers_utils_hub_get_from_cache
=
transformers
.
utils
.
hub
.
get_from_cache
self
.
transformers_modeling_utils_load_pretrained_model
=
getattr
(
transformers
.
modeling_utils
.
PreTrainedModel
,
'_load_pretrained_model'
,
None
)
self
.
transformers_tokenization_utils_base_cached_file
=
getattr
(
transformers
.
tokenization_utils_base
,
'cached_file'
,
None
)
self
.
transformers_configuration_utils_cached_file
=
getattr
(
transformers
.
configuration_utils
,
'cached_file'
,
None
)
self
.
transformers_utils_hub_get_from_cache
=
getattr
(
transformers
.
utils
.
hub
,
'get_from_cache'
,
None
)
torch
.
nn
.
init
.
kaiming_uniform_
=
do_nothing
torch
.
nn
.
init
.
_no_grad_normal_
=
do_nothing
torch
.
nn
.
init
.
_no_grad_uniform_
=
do_nothing
open_clip
.
create_model_and_transforms
=
create_model_and_transforms_without_pretrained
ldm
.
modules
.
encoders
.
modules
.
CLIPTextModel
.
from_pretrained
=
CLIPTextModel_from_pretrained
transformers
.
utils
.
hub
.
get_from_cache
=
transformers_utils_hub_get_from_cache
if
self
.
transformers_modeling_utils_load_pretrained_model
is
not
None
:
transformers
.
modeling_utils
.
PreTrainedModel
.
_load_pretrained_model
=
transformers_modeling_utils_load_pretrained_model
if
self
.
transformers_tokenization_utils_base_cached_file
is
not
None
:
transformers
.
tokenization_utils_base
.
cached_file
=
transformers_tokenization_utils_base_cached_file
if
self
.
transformers_configuration_utils_cached_file
is
not
None
:
transformers
.
configuration_utils
.
cached_file
=
transformers_configuration_utils_cached_file
if
self
.
transformers_utils_hub_get_from_cache
is
not
None
:
transformers
.
utils
.
hub
.
get_from_cache
=
transformers_utils_hub_get_from_cache
def
__exit__
(
self
,
exc_type
,
exc_val
,
exc_tb
):
torch
.
nn
.
init
.
kaiming_uniform_
=
self
.
init_kaiming_uniform
...
...
@@ -61,5 +84,12 @@ class DisableInitialization:
torch
.
nn
.
init
.
_no_grad_uniform_
=
self
.
init_no_grad_uniform_
open_clip
.
create_model_and_transforms
=
self
.
create_model_and_transforms
ldm
.
modules
.
encoders
.
modules
.
CLIPTextModel
.
from_pretrained
=
self
.
CLIPTextModel_from_pretrained
transformers
.
utils
.
hub
.
get_from_cache
=
self
.
transformers_utils_hub_get_from_cache
if
self
.
transformers_modeling_utils_load_pretrained_model
is
not
None
:
transformers
.
modeling_utils
.
PreTrainedModel
.
_load_pretrained_model
=
self
.
transformers_modeling_utils_load_pretrained_model
if
self
.
transformers_tokenization_utils_base_cached_file
is
not
None
:
transformers
.
utils
.
hub
.
cached_file
=
self
.
transformers_tokenization_utils_base_cached_file
if
self
.
transformers_configuration_utils_cached_file
is
not
None
:
transformers
.
utils
.
hub
.
cached_file
=
self
.
transformers_configuration_utils_cached_file
if
self
.
transformers_utils_hub_get_from_cache
is
not
None
:
transformers
.
utils
.
hub
.
get_from_cache
=
self
.
transformers_utils_hub_get_from_cache
modules/sd_models.py
View file @
0f8603a5
...
...
@@ -14,7 +14,7 @@ import ldm.modules.midas as midas
from
ldm.util
import
instantiate_from_config
from
modules
import
shared
,
modelloader
,
devices
,
script_callbacks
,
sd_vae
,
sd_disable_initialization
from
modules
import
shared
,
modelloader
,
devices
,
script_callbacks
,
sd_vae
,
sd_disable_initialization
,
errors
from
modules.paths
import
models_path
from
modules.sd_hijack_inpainting
import
do_inpainting_hijack
,
should_hijack_inpainting
...
...
@@ -333,7 +333,11 @@ def load_model(checkpoint_info=None):
timer
=
Timer
()
with
sd_disable_initialization
.
DisableInitialization
():
try
:
with
sd_disable_initialization
.
DisableInitialization
():
sd_model
=
instantiate_from_config
(
sd_config
.
model
)
except
Exception
as
e
:
print
(
'Failed to create model quickly; will retry using slow method.'
,
file
=
sys
.
stderr
)
sd_model
=
instantiate_from_config
(
sd_config
.
model
)
elapsed_create
=
timer
.
elapsed
()
...
...
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