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
601a7b4c
Commit
601a7b4c
authored
Nov 27, 2023
by
aria1th
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cache divisors / fix ruff
parent
23c36f59
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
18 deletions
+26
-18
extensions-builtin/hypertile/hypertile.py
extensions-builtin/hypertile/hypertile.py
+15
-9
extensions-builtin/hypertile/scripts/hypertile_script.py
extensions-builtin/hypertile/scripts/hypertile_script.py
+1
-1
extensions-builtin/hypertile/scripts/hypertile_xyz.py
extensions-builtin/hypertile/scripts/hypertile_xyz.py
+10
-8
No files found.
extensions-builtin/hypertile/hypertile.py
View file @
601a7b4c
...
@@ -6,7 +6,6 @@ Original author: @tfernd Github: https://github.com/tfernd/HyperTile
...
@@ -6,7 +6,6 @@ Original author: @tfernd Github: https://github.com/tfernd/HyperTile
from
__future__
import
annotations
from
__future__
import
annotations
import
functools
from
dataclasses
import
dataclass
from
dataclasses
import
dataclass
from
typing
import
Callable
from
typing
import
Callable
...
@@ -189,20 +188,27 @@ DEPTH_LAYERS_XL = {
...
@@ -189,20 +188,27 @@ DEPTH_LAYERS_XL = {
RNG_INSTANCE
=
random
.
Random
()
RNG_INSTANCE
=
random
.
Random
()
@
cache
def
random_divisor
(
value
:
int
,
min_value
:
int
,
/
,
max_options
:
int
=
1
)
->
int
:
def
get_divisors
(
value
:
int
,
min_value
:
int
,
/
,
max_options
:
int
=
1
)
->
list
[
int
]
:
"""
"""
Returns
a random divisor
of value that
Returns
divisors
of value that
x * min_value <= value
x * min_value <= value
i
f max_options is 1, the behavior is deterministic
i
n big -> small order, amount of divisors is limited by max_options
"""
"""
max_options
=
max
(
1
,
max_options
)
# at least 1 option should be returned
min_value
=
min
(
min_value
,
value
)
min_value
=
min
(
min_value
,
value
)
# All big divisors of value (inclusive)
divisors
=
[
i
for
i
in
range
(
min_value
,
value
+
1
)
if
value
%
i
==
0
]
# divisors in small -> big order
divisors
=
[
i
for
i
in
range
(
min_value
,
value
+
1
)
if
value
%
i
==
0
]
# divisors in small -> big order
ns
=
[
value
//
i
for
i
in
divisors
[:
max_options
]]
# has at least 1 element # big -> small order
ns
=
[
value
//
i
for
i
in
divisors
[:
max_options
]]
# has at least 1 element # big -> small order
return
ns
def
random_divisor
(
value
:
int
,
min_value
:
int
,
/
,
max_options
:
int
=
1
)
->
int
:
"""
Returns a random divisor of value that
x * min_value <= value
if max_options is 1, the behavior is deterministic
"""
ns
=
get_divisors
(
value
,
min_value
,
max_options
=
max_options
)
# get cached divisors
idx
=
RNG_INSTANCE
.
randint
(
0
,
len
(
ns
)
-
1
)
idx
=
RNG_INSTANCE
.
randint
(
0
,
len
(
ns
)
-
1
)
return
ns
[
idx
]
return
ns
[
idx
]
...
@@ -212,7 +218,7 @@ def set_hypertile_seed(seed: int) -> None:
...
@@ -212,7 +218,7 @@ def set_hypertile_seed(seed: int) -> None:
RNG_INSTANCE
.
seed
(
seed
)
RNG_INSTANCE
.
seed
(
seed
)
@
functools
.
cache
@
cache
def
largest_tile_size_available
(
width
:
int
,
height
:
int
)
->
int
:
def
largest_tile_size_available
(
width
:
int
,
height
:
int
)
->
int
:
"""
"""
Calculates the largest tile size available for a given width and height
Calculates the largest tile size available for a given width and height
...
...
extensions-builtin/hypertile/scripts/hypertile_script.py
View file @
601a7b4c
...
@@ -75,4 +75,4 @@ def on_ui_settings():
...
@@ -75,4 +75,4 @@ def on_ui_settings():
script_callbacks
.
on_ui_settings
(
on_ui_settings
)
script_callbacks
.
on_ui_settings
(
on_ui_settings
)
script_callbacks
.
on_before_ui
(
add_axis_options
)
script_callbacks
.
on_before_ui
(
add_axis_options
)
\ No newline at end of file
extensions-builtin/hypertile/scripts/hypertile_xyz.py
View file @
601a7b4c
from
modules
import
scripts
from
modules
import
scripts
xyz_grid
=
[
x
for
x
in
scripts
.
scripts_data
if
x
.
script_class
.
__module__
==
"xyz_grid.py"
][
0
]
.
module
from
modules.shared
import
opts
from
modules.shared
import
opts
xyz_grid
=
[
x
for
x
in
scripts
.
scripts_data
if
x
.
script_class
.
__module__
==
"xyz_grid.py"
][
0
]
.
module
def
int_applier
(
value_name
:
str
,
min_range
:
int
=
-
1
,
max_range
:
int
=
-
1
):
def
int_applier
(
value_name
:
str
,
min_range
:
int
=
-
1
,
max_range
:
int
=
-
1
):
"""
"""
Returns a function that applies the given value to the given value_name in opts.data.
Returns a function that applies the given value to the given value_name in opts.data.
"""
"""
# convert to int
# convert to int
def
validate
(
value_name
:
str
,
value
:
str
):
def
validate
(
value_name
:
str
,
value
:
str
):
try
:
if
not
value
.
isnumeric
():
value
=
int
(
value
)
raise
ValueError
(
f
"Value {value} for {value_name} must be an integer"
)
except
:
value
=
int
(
value
)
raise
ValueError
(
f
"Value {value} for {value_name} is not an integer"
)
# validate value
# validate value
if
not
min_range
==
-
1
:
if
not
min_range
==
-
1
:
assert
value
>=
min_range
,
f
"Value {value} for {value_name} must be greater than or equal to {min_range}"
assert
value
>=
min_range
,
f
"Value {value} for {value_name} must be greater than or equal to {min_range}"
...
@@ -46,7 +46,9 @@ def add_axis_options():
...
@@ -46,7 +46,9 @@ def add_axis_options():
xyz_grid
.
AxisOption
(
"[Hypertile] VAE Max Tile Size"
,
int
,
int_applier
(
"hypertile_max_tile_vae"
,
0
,
512
)),
xyz_grid
.
AxisOption
(
"[Hypertile] VAE Max Tile Size"
,
int
,
int_applier
(
"hypertile_max_tile_vae"
,
0
,
512
)),
xyz_grid
.
AxisOption
(
"[Hypertile] VAE Swap Size"
,
int
,
int_applier
(
"hypertile_swap_size_vae"
,
0
,
64
)),
xyz_grid
.
AxisOption
(
"[Hypertile] VAE Swap Size"
,
int
,
int_applier
(
"hypertile_swap_size_vae"
,
0
,
64
)),
]
]
# check if the axis options have already been added
set_a
=
set
([
opt
.
label
for
opt
in
xyz_grid
.
axis_options
])
if
any
(
set
(
opt
.
label
for
opt
in
extra_axis_options
)
.
intersection
(
set
(
opt
.
label
for
opt
in
xyz_grid
.
axis_options
))):
set_b
=
set
([
opt
.
label
for
opt
in
extra_axis_options
])
if
set_a
.
intersection
(
set_b
):
return
return
xyz_grid
.
axis_options
.
extend
(
extra_axis_options
)
\ No newline at end of file
xyz_grid
.
axis_options
.
extend
(
extra_axis_options
)
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