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
chenpangpang
ComfyUI
Commits
58185397
Commit
58185397
authored
Apr 23, 2023
by
BlenderNeko
Browse files
add docstrings
parent
8d2de420
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
13 deletions
+20
-13
comfy/sample.py
comfy/sample.py
+15
-12
nodes.py
nodes.py
+5
-1
No files found.
comfy/sample.py
View file @
58185397
...
@@ -2,22 +2,21 @@ import torch
...
@@ -2,22 +2,21 @@ import torch
import
comfy.model_management
import
comfy.model_management
def
prepare_noise
(
latent
,
seed
,
disable_noise
):
def
prepare_noise
(
latent
,
seed
):
"""creates random noise given a LATENT and a seed"""
latent_image
=
latent
[
"samples"
]
latent_image
=
latent
[
"samples"
]
if
disable_noise
:
batch_index
=
0
noise
=
torch
.
zeros
(
latent_image
.
size
(),
dtype
=
latent_image
.
dtype
,
layout
=
latent_image
.
layout
,
device
=
"cpu"
)
if
"batch_index"
in
latent
:
else
:
batch_index
=
latent
[
"batch_index"
]
batch_index
=
0
if
"batch_index"
in
latent
:
generator
=
torch
.
manual_seed
(
seed
)
batch_index
=
latent
[
"batch_index"
]
for
i
in
range
(
batch_index
):
noise
=
torch
.
randn
([
1
]
+
list
(
latent_image
.
size
())[
1
:],
dtype
=
latent_image
.
dtype
,
layout
=
latent_image
.
layout
,
generator
=
generator
,
device
=
"cpu"
)
generator
=
torch
.
manual_seed
(
seed
)
noise
=
torch
.
randn
(
latent_image
.
size
(),
dtype
=
latent_image
.
dtype
,
layout
=
latent_image
.
layout
,
generator
=
generator
,
device
=
"cpu"
)
for
i
in
range
(
batch_index
):
noise
=
torch
.
randn
([
1
]
+
list
(
latent_image
.
size
())[
1
:],
dtype
=
latent_image
.
dtype
,
layout
=
latent_image
.
layout
,
generator
=
generator
,
device
=
"cpu"
)
noise
=
torch
.
randn
(
latent_image
.
size
(),
dtype
=
latent_image
.
dtype
,
layout
=
latent_image
.
layout
,
generator
=
generator
,
device
=
"cpu"
)
return
noise
return
noise
def
create_mask
(
latent
,
noise
):
def
create_mask
(
latent
,
noise
):
"""creates a mask for a given LATENT and noise"""
noise_mask
=
None
noise_mask
=
None
device
=
comfy
.
model_management
.
get_torch_device
()
device
=
comfy
.
model_management
.
get_torch_device
()
if
"noise_mask"
in
latent
:
if
"noise_mask"
in
latent
:
...
@@ -30,6 +29,7 @@ def create_mask(latent, noise):
...
@@ -30,6 +29,7 @@ def create_mask(latent, noise):
return
noise_mask
return
noise_mask
def
broadcast_cond
(
cond
,
noise
):
def
broadcast_cond
(
cond
,
noise
):
"""broadcasts conditioning to the noise batch size"""
device
=
comfy
.
model_management
.
get_torch_device
()
device
=
comfy
.
model_management
.
get_torch_device
()
copy
=
[]
copy
=
[]
for
p
in
cond
:
for
p
in
cond
:
...
@@ -41,6 +41,7 @@ def broadcast_cond(cond, noise):
...
@@ -41,6 +41,7 @@ def broadcast_cond(cond, noise):
return
copy
return
copy
def
load_c_nets
(
positive
,
negative
):
def
load_c_nets
(
positive
,
negative
):
"""loads control nets in positive and negative conditioning"""
def
get_models
(
cond
):
def
get_models
(
cond
):
models
=
[]
models
=
[]
for
c
in
cond
:
for
c
in
cond
:
...
@@ -53,10 +54,12 @@ def load_c_nets(positive, negative):
...
@@ -53,10 +54,12 @@ def load_c_nets(positive, negative):
return
get_models
(
positive
)
+
get_models
(
negative
)
return
get_models
(
positive
)
+
get_models
(
negative
)
def
load_additional_models
(
positive
,
negative
):
def
load_additional_models
(
positive
,
negative
):
"""loads additional models in positive and negative conditioning"""
models
=
load_c_nets
(
positive
,
negative
)
models
=
load_c_nets
(
positive
,
negative
)
comfy
.
model_management
.
load_controlnet_gpu
(
models
)
comfy
.
model_management
.
load_controlnet_gpu
(
models
)
return
models
return
models
def
cleanup_additional_models
(
models
):
def
cleanup_additional_models
(
models
):
"""cleanup additional models that were loaded"""
for
m
in
models
:
for
m
in
models
:
m
.
cleanup
()
m
.
cleanup
()
\ No newline at end of file
nodes.py
View file @
58185397
...
@@ -744,7 +744,11 @@ def common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive,
...
@@ -744,7 +744,11 @@ def common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive,
device
=
comfy
.
model_management
.
get_torch_device
()
device
=
comfy
.
model_management
.
get_torch_device
()
latent_image
=
latent
[
"samples"
]
latent_image
=
latent
[
"samples"
]
noise
=
comfy
.
sample
.
prepare_noise
(
latent
,
seed
,
disable_noise
)
if
disable_noise
:
noise
=
torch
.
zeros
(
latent_image
.
size
(),
dtype
=
latent_image
.
dtype
,
layout
=
latent_image
.
layout
,
device
=
"cpu"
)
else
:
noise
=
comfy
.
sample
.
prepare_noise
(
latent
,
seed
)
noise_mask
=
comfy
.
sample
.
create_mask
(
latent
,
noise
)
noise_mask
=
comfy
.
sample
.
create_mask
(
latent
,
noise
)
real_model
=
None
real_model
=
None
...
...
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