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
e33bb8fe
Commit
e33bb8fe
authored
Jun 10, 2024
by
AUTOMATIC1111
Committed by
GitHub
Jun 10, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15984 from huchenlei/before_every_sampling
Add process_before_every_sampling hook
parents
a84000c2
17e84615
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
0 deletions
+39
-0
modules/processing.py
modules/processing.py
+24
-0
modules/scripts.py
modules/scripts.py
+15
-0
No files found.
modules/processing.py
View file @
e33bb8fe
...
...
@@ -1330,6 +1330,15 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
# here we generate an image normally
x
=
self
.
rng
.
next
()
if
self
.
scripts
is
not
None
:
self
.
scripts
.
process_before_every_sampling
(
p
=
self
,
x
=
x
,
noise
=
x
,
c
=
conditioning
,
uc
=
unconditional_conditioning
)
samples
=
self
.
sampler
.
sample
(
self
,
x
,
conditioning
,
unconditional_conditioning
,
image_conditioning
=
self
.
txt2img_image_conditioning
(
x
))
del
x
...
...
@@ -1430,6 +1439,13 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
if
self
.
scripts
is
not
None
:
self
.
scripts
.
before_hr
(
self
)
self
.
scripts
.
process_before_every_sampling
(
p
=
self
,
x
=
samples
,
noise
=
noise
,
c
=
self
.
hr_c
,
uc
=
self
.
hr_uc
,
)
samples
=
self
.
sampler
.
sample_img2img
(
self
,
samples
,
noise
,
self
.
hr_c
,
self
.
hr_uc
,
steps
=
self
.
hr_second_pass_steps
or
self
.
steps
,
image_conditioning
=
image_conditioning
)
...
...
@@ -1743,6 +1759,14 @@ class StableDiffusionProcessingImg2Img(StableDiffusionProcessing):
self
.
extra_generation_params
[
"Noise multiplier"
]
=
self
.
initial_noise_multiplier
x
*=
self
.
initial_noise_multiplier
if
self
.
scripts
is
not
None
:
self
.
scripts
.
process_before_every_sampling
(
p
=
self
,
x
=
self
.
init_latent
,
noise
=
x
,
c
=
conditioning
,
uc
=
unconditional_conditioning
)
samples
=
self
.
sampler
.
sample_img2img
(
self
,
self
.
init_latent
,
x
,
conditioning
,
unconditional_conditioning
,
image_conditioning
=
self
.
image_conditioning
)
if
self
.
mask
is
not
None
:
...
...
modules/scripts.py
View file @
e33bb8fe
...
...
@@ -187,6 +187,13 @@ class Script:
"""
pass
def
process_before_every_sampling
(
self
,
p
,
*
args
,
**
kwargs
):
"""
Similar to process(), called before every sampling.
If you use high-res fix, this will be called two times.
"""
pass
def
process_batch
(
self
,
p
,
*
args
,
**
kwargs
):
"""
Same as process(), but called for every batch.
...
...
@@ -826,6 +833,14 @@ class ScriptRunner:
except
Exception
:
errors
.
report
(
f
"Error running process: {script.filename}"
,
exc_info
=
True
)
def
process_before_every_sampling
(
self
,
p
,
**
kwargs
):
for
script
in
self
.
ordered_scripts
(
'process_before_every_sampling'
):
try
:
script_args
=
p
.
script_args
[
script
.
args_from
:
script
.
args_to
]
script
.
process_before_every_sampling
(
p
,
*
script_args
,
**
kwargs
)
except
Exception
:
errors
.
report
(
f
"Error running process_before_every_sampling: {script.filename}"
,
exc_info
=
True
)
def
before_process_batch
(
self
,
p
,
**
kwargs
):
for
script
in
self
.
ordered_scripts
(
'before_process_batch'
):
try
:
...
...
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