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
03eadbb5
"doc/git@developer.sourcefind.cn:wangsen/paddle_dbnet.git" did not exist on "3f62ea21d40bdc4779b561fff8bb7e7d24abbf1d"
Commit
03eadbb5
authored
Dec 06, 2023
by
asagi4
Browse files
Make HyperTile deterministic
parent
2db86b46
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
9 deletions
+6
-9
comfy_extras/nodes_hypertile.py
comfy_extras/nodes_hypertile.py
+6
-9
No files found.
comfy_extras/nodes_hypertile.py
View file @
03eadbb5
...
@@ -2,9 +2,10 @@
...
@@ -2,9 +2,10 @@
import
math
import
math
from
einops
import
rearrange
from
einops
import
rearrange
import
random
# Use torch rng for consistency across generations
from
torch
import
randint
def
random_divisor
(
value
:
int
,
min_value
:
int
,
/
,
max_options
:
int
=
1
,
counter
=
0
)
->
int
:
def
random_divisor
(
value
:
int
,
min_value
:
int
,
/
,
max_options
:
int
=
1
)
->
int
:
min_value
=
min
(
min_value
,
value
)
min_value
=
min
(
min_value
,
value
)
# All big divisors of value (inclusive)
# All big divisors of value (inclusive)
...
@@ -12,8 +13,7 @@ def random_divisor(value: int, min_value: int, /, max_options: int = 1, counter
...
@@ -12,8 +13,7 @@ def random_divisor(value: int, min_value: int, /, max_options: int = 1, counter
ns
=
[
value
//
i
for
i
in
divisors
[:
max_options
]]
# has at least 1 element
ns
=
[
value
//
i
for
i
in
divisors
[:
max_options
]]
# has at least 1 element
random
.
seed
(
counter
)
idx
=
randint
(
low
=
0
,
high
=
len
(
ns
)
-
1
,
size
=
(
1
,)).
item
()
idx
=
random
.
randint
(
0
,
len
(
ns
)
-
1
)
return
ns
[
idx
]
return
ns
[
idx
]
...
@@ -42,7 +42,6 @@ class HyperTile:
...
@@ -42,7 +42,6 @@ class HyperTile:
latent_tile_size
=
max
(
32
,
tile_size
)
//
8
latent_tile_size
=
max
(
32
,
tile_size
)
//
8
self
.
temp
=
None
self
.
temp
=
None
self
.
counter
=
1
def
hypertile_in
(
q
,
k
,
v
,
extra_options
):
def
hypertile_in
(
q
,
k
,
v
,
extra_options
):
if
q
.
shape
[
-
1
]
in
apply_to
:
if
q
.
shape
[
-
1
]
in
apply_to
:
...
@@ -53,10 +52,8 @@ class HyperTile:
...
@@ -53,10 +52,8 @@ class HyperTile:
h
,
w
=
round
(
math
.
sqrt
(
hw
*
aspect_ratio
)),
round
(
math
.
sqrt
(
hw
/
aspect_ratio
))
h
,
w
=
round
(
math
.
sqrt
(
hw
*
aspect_ratio
)),
round
(
math
.
sqrt
(
hw
/
aspect_ratio
))
factor
=
2
**
((
q
.
shape
[
-
1
]
//
model_channels
)
-
1
)
if
scale_depth
else
1
factor
=
2
**
((
q
.
shape
[
-
1
]
//
model_channels
)
-
1
)
if
scale_depth
else
1
nh
=
random_divisor
(
h
,
latent_tile_size
*
factor
,
swap_size
,
self
.
counter
)
nh
=
random_divisor
(
h
,
latent_tile_size
*
factor
,
swap_size
)
self
.
counter
+=
1
nw
=
random_divisor
(
w
,
latent_tile_size
*
factor
,
swap_size
)
nw
=
random_divisor
(
w
,
latent_tile_size
*
factor
,
swap_size
,
self
.
counter
)
self
.
counter
+=
1
if
nh
*
nw
>
1
:
if
nh
*
nw
>
1
:
q
=
rearrange
(
q
,
"b (nh h nw w) c -> (b nh nw) (h w) c"
,
h
=
h
//
nh
,
w
=
w
//
nw
,
nh
=
nh
,
nw
=
nw
)
q
=
rearrange
(
q
,
"b (nh h nw w) c -> (b nh nw) (h w) c"
,
h
=
h
//
nh
,
w
=
w
//
nw
,
nh
=
nh
,
nw
=
nw
)
...
...
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