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
fcf513e0
"git@developer.sourcefind.cn:orangecat/ollama.git" did not exist on "68ee42f995a04bd163eb1c714f53d4c25ab25474"
Commit
fcf513e0
authored
May 03, 2023
by
comfyanonymous
Browse files
Refactor.
parent
a74e176a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
6 deletions
+8
-6
comfy/sd.py
comfy/sd.py
+5
-1
comfy/utils.py
comfy/utils.py
+2
-4
comfy_extras/nodes_upscale_model.py
comfy_extras/nodes_upscale_model.py
+1
-1
No files found.
comfy/sd.py
View file @
fcf513e0
...
...
@@ -515,6 +515,8 @@ class VAE:
def
decode_tiled_
(
self
,
samples
,
tile_x
=
64
,
tile_y
=
64
,
overlap
=
16
):
steps
=
samples
.
shape
[
0
]
*
utils
.
get_tiled_scale_steps
(
samples
.
shape
[
3
],
samples
.
shape
[
2
],
tile_x
,
tile_y
,
overlap
)
steps
+=
samples
.
shape
[
0
]
*
utils
.
get_tiled_scale_steps
(
samples
.
shape
[
3
],
samples
.
shape
[
2
],
tile_x
//
2
,
tile_y
*
2
,
overlap
)
steps
+=
samples
.
shape
[
0
]
*
utils
.
get_tiled_scale_steps
(
samples
.
shape
[
3
],
samples
.
shape
[
2
],
tile_x
*
2
,
tile_y
//
2
,
overlap
)
pbar
=
utils
.
ProgressBar
(
steps
)
decode_fn
=
lambda
a
:
(
self
.
first_stage_model
.
decode
(
1.
/
self
.
scale_factor
*
a
.
to
(
self
.
device
))
+
1.0
)
...
...
@@ -566,7 +568,9 @@ class VAE:
self
.
first_stage_model
=
self
.
first_stage_model
.
to
(
self
.
device
)
pixel_samples
=
pixel_samples
.
movedim
(
-
1
,
1
).
to
(
self
.
device
)
steps
=
utils
.
get_tiled_scale_steps
(
pixel_samples
.
shape
[
3
],
pixel_samples
.
shape
[
2
],
tile_x
,
tile_y
,
overlap
)
steps
=
pixel_samples
.
shape
[
0
]
*
utils
.
get_tiled_scale_steps
(
pixel_samples
.
shape
[
3
],
pixel_samples
.
shape
[
2
],
tile_x
,
tile_y
,
overlap
)
steps
+=
pixel_samples
.
shape
[
0
]
*
utils
.
get_tiled_scale_steps
(
pixel_samples
.
shape
[
3
],
pixel_samples
.
shape
[
2
],
tile_x
//
2
,
tile_y
*
2
,
overlap
)
steps
+=
pixel_samples
.
shape
[
0
]
*
utils
.
get_tiled_scale_steps
(
pixel_samples
.
shape
[
3
],
pixel_samples
.
shape
[
2
],
tile_x
*
2
,
tile_y
//
2
,
overlap
)
pbar
=
utils
.
ProgressBar
(
steps
)
samples
=
utils
.
tiled_scale
(
pixel_samples
,
lambda
a
:
self
.
first_stage_model
.
encode
(
2.
*
a
-
1.
).
sample
()
*
self
.
scale_factor
,
tile_x
,
tile_y
,
overlap
,
upscale_amount
=
(
1
/
8
),
out_channels
=
4
,
pbar
=
pbar
)
...
...
comfy/utils.py
View file @
fcf513e0
import
torch
import
math
def
load_torch_file
(
ckpt
,
safe_load
=
False
):
if
ckpt
.
lower
().
endswith
(
".safetensors"
):
...
...
@@ -63,10 +64,7 @@ def common_upscale(samples, width, height, upscale_method, crop):
return
torch
.
nn
.
functional
.
interpolate
(
s
,
size
=
(
height
,
width
),
mode
=
upscale_method
)
def
get_tiled_scale_steps
(
width
,
height
,
tile_x
,
tile_y
,
overlap
):
it_1
=
-
(
height
//
-
(
tile_y
*
2
-
overlap
))
*
-
(
width
//
-
(
tile_x
//
2
-
overlap
))
it_2
=
-
(
height
//
-
(
tile_y
//
2
-
overlap
))
*
-
(
width
//
-
(
tile_x
*
2
-
overlap
))
it_3
=
-
(
height
//
-
(
tile_y
-
overlap
))
*
-
(
width
//
-
(
tile_x
-
overlap
))
return
it_1
+
it_2
+
it_3
return
math
.
ceil
((
height
/
(
tile_y
-
overlap
)))
*
math
.
ceil
((
width
/
(
tile_x
-
overlap
)))
@
torch
.
inference_mode
()
def
tiled_scale
(
samples
,
function
,
tile_x
=
64
,
tile_y
=
64
,
overlap
=
8
,
upscale_amount
=
4
,
out_channels
=
3
,
pbar
=
None
):
...
...
comfy_extras/nodes_upscale_model.py
View file @
fcf513e0
...
...
@@ -40,7 +40,7 @@ class ImageUpscaleWithModel:
tile
=
128
+
64
overlap
=
8
steps
=
-
(
in_img
.
shape
[
2
]
//
-
(
tile
-
overlap
))
*
-
(
in_img
.
shape
[
3
]
//
-
(
tile
-
overlap
)
)
steps
=
in_img
.
shape
[
0
]
*
comfy
.
utils
.
get_tiled_scale_steps
(
in_img
.
shape
[
3
],
in_img
.
shape
[
2
],
tile_x
=
tile
,
tile_y
=
tile
,
overlap
=
overlap
)
pbar
=
comfy
.
utils
.
ProgressBar
(
steps
)
s
=
comfy
.
utils
.
tiled_scale
(
in_img
,
lambda
a
:
upscale_model
(
a
),
tile_x
=
tile
,
tile_y
=
tile
,
overlap
=
overlap
,
upscale_amount
=
upscale_model
.
scale
,
pbar
=
pbar
)
upscale_model
.
cpu
()
...
...
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