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
b4723bb8
Commit
b4723bb8
authored
Jun 08, 2024
by
AUTOMATIC1111
Committed by
GitHub
Jun 08, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15815 from AUTOMATIC1111/torch-float64-or-float32
fix soft inpainting on mps and xpu, torch_utils.float64
parents
6450d24a
f015b941
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
7 deletions
+16
-7
extensions-builtin/soft-inpainting/scripts/soft_inpainting.py
...nsions-builtin/soft-inpainting/scripts/soft_inpainting.py
+4
-5
modules/sd_samplers_timesteps_impl.py
modules/sd_samplers_timesteps_impl.py
+3
-2
modules/torch_utils.py
modules/torch_utils.py
+9
-0
No files found.
extensions-builtin/soft-inpainting/scripts/soft_inpainting.py
View file @
b4723bb8
...
...
@@ -3,6 +3,7 @@ import gradio as gr
import
math
from
modules.ui_components
import
InputAccordion
import
modules.scripts
as
scripts
from
modules.torch_utils
import
float64
class
SoftInpaintingSettings
:
...
...
@@ -79,13 +80,11 @@ def latent_blend(settings, a, b, t):
# Calculate the magnitude of the interpolated vectors. (We will remove this magnitude.)
# 64-bit operations are used here to allow large exponents.
current_magnitude
=
torch
.
norm
(
image_interp
,
p
=
2
,
dim
=
1
,
keepdim
=
True
)
.
to
(
torch
.
float64
)
.
add_
(
0.00001
)
current_magnitude
=
torch
.
norm
(
image_interp
,
p
=
2
,
dim
=
1
,
keepdim
=
True
)
.
to
(
float64
(
image_interp
)
)
.
add_
(
0.00001
)
# Interpolate the powered magnitudes, then un-power them (bring them back to a power of 1).
a_magnitude
=
torch
.
norm
(
a
,
p
=
2
,
dim
=
1
,
keepdim
=
True
)
.
to
(
torch
.
float64
)
.
pow_
(
settings
.
inpaint_detail_preservation
)
*
one_minus_t3
b_magnitude
=
torch
.
norm
(
b
,
p
=
2
,
dim
=
1
,
keepdim
=
True
)
.
to
(
torch
.
float64
)
.
pow_
(
settings
.
inpaint_detail_preservation
)
*
t3
a_magnitude
=
torch
.
norm
(
a
,
p
=
2
,
dim
=
1
,
keepdim
=
True
)
.
to
(
float64
(
a
))
.
pow_
(
settings
.
inpaint_detail_preservation
)
*
one_minus_t3
b_magnitude
=
torch
.
norm
(
b
,
p
=
2
,
dim
=
1
,
keepdim
=
True
)
.
to
(
float64
(
b
))
.
pow_
(
settings
.
inpaint_detail_preservation
)
*
t3
desired_magnitude
=
a_magnitude
desired_magnitude
.
add_
(
b_magnitude
)
.
pow_
(
1
/
settings
.
inpaint_detail_preservation
)
del
a_magnitude
,
b_magnitude
,
t3
,
one_minus_t3
...
...
modules/sd_samplers_timesteps_impl.py
View file @
b4723bb8
...
...
@@ -5,13 +5,14 @@ import numpy as np
from
modules
import
shared
from
modules.models.diffusion.uni_pc
import
uni_pc
from
modules.torch_utils
import
float64
@
torch
.
no_grad
()
def
ddim
(
model
,
x
,
timesteps
,
extra_args
=
None
,
callback
=
None
,
disable
=
None
,
eta
=
0.0
):
alphas_cumprod
=
model
.
inner_model
.
inner_model
.
alphas_cumprod
alphas
=
alphas_cumprod
[
timesteps
]
alphas_prev
=
alphas_cumprod
[
torch
.
nn
.
functional
.
pad
(
timesteps
[:
-
1
],
pad
=
(
1
,
0
))]
.
to
(
torch
.
float64
if
x
.
device
.
type
!=
'mps'
and
x
.
device
.
type
!=
'xpu'
else
torch
.
float32
)
alphas_prev
=
alphas_cumprod
[
torch
.
nn
.
functional
.
pad
(
timesteps
[:
-
1
],
pad
=
(
1
,
0
))]
.
to
(
float64
(
x
)
)
sqrt_one_minus_alphas
=
torch
.
sqrt
(
1
-
alphas
)
sigmas
=
eta
*
np
.
sqrt
((
1
-
alphas_prev
.
cpu
()
.
numpy
())
/
(
1
-
alphas
.
cpu
())
*
(
1
-
alphas
.
cpu
()
/
alphas_prev
.
cpu
()
.
numpy
()))
...
...
@@ -43,7 +44,7 @@ def ddim(model, x, timesteps, extra_args=None, callback=None, disable=None, eta=
def
plms
(
model
,
x
,
timesteps
,
extra_args
=
None
,
callback
=
None
,
disable
=
None
):
alphas_cumprod
=
model
.
inner_model
.
inner_model
.
alphas_cumprod
alphas
=
alphas_cumprod
[
timesteps
]
alphas_prev
=
alphas_cumprod
[
torch
.
nn
.
functional
.
pad
(
timesteps
[:
-
1
],
pad
=
(
1
,
0
))]
.
to
(
torch
.
float64
if
x
.
device
.
type
!=
'mps'
and
x
.
device
.
type
!=
'xpu'
else
torch
.
float32
)
alphas_prev
=
alphas_cumprod
[
torch
.
nn
.
functional
.
pad
(
timesteps
[:
-
1
],
pad
=
(
1
,
0
))]
.
to
(
float64
(
x
)
)
sqrt_one_minus_alphas
=
torch
.
sqrt
(
1
-
alphas
)
extra_args
=
{}
if
extra_args
is
None
else
extra_args
...
...
modules/torch_utils.py
View file @
b4723bb8
from
__future__
import
annotations
import
torch.nn
import
torch
def
get_param
(
model
)
->
torch
.
nn
.
Parameter
:
...
...
@@ -15,3 +16,11 @@ def get_param(model) -> torch.nn.Parameter:
return
param
raise
ValueError
(
f
"No parameters found in model {model!r}"
)
def
float64
(
t
:
torch
.
Tensor
):
"""return torch.float64 if device is not mps or xpu, else return torch.float32"""
match
t
.
device
.
type
:
case
'mps'
,
'xpu'
:
return
torch
.
float32
return
torch
.
float64
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