Skip to content

Commit

Permalink
Increased allowed random seed range
Browse files Browse the repository at this point in the history
  • Loading branch information
MoonRide303 committed Oct 23, 2023
1 parent 23a7559 commit 81650a4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion fooocus_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = '2.1.732'
version = '2.1.733'
9 changes: 2 additions & 7 deletions modules/async_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,8 @@ def handler(args):
controlnet_cpds_path = None
clip_vision_path, ip_negative_path, ip_adapter_path = None, None, None

seed = image_seed
max_seed = int(1024 * 1024 * 1024)
if not isinstance(seed, int):
seed = random.randint(1, max_seed)
if seed < 0:
seed = - seed
seed = seed % max_seed
seed = int(image_seed)
print(f'[Parameters] Seed = {seed}')

if performance_selection == 'Speed':
steps = 30
Expand Down
5 changes: 4 additions & 1 deletion modules/expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from modules.path import fooocus_expansion_path
from fcbh.model_patcher import ModelPatcher

# limitation of np.random.seed(), called from transformers.set_seed()
SEED_LIMIT_NUMPY = 2**32


fooocus_magic_split = [
', extremely',
Expand Down Expand Up @@ -54,7 +57,7 @@ def __call__(self, prompt, seed):
print('Fooocus Expansion loaded by itself.')
model_management.load_model_gpu(self.patcher)

seed = int(seed)
seed = int(seed) % SEED_LIMIT_NUMPY
set_seed(seed)
origin = safe_str(prompt)
prompt = origin + fooocus_magic_split[seed % len(fooocus_magic_split)]
Expand Down
4 changes: 4 additions & 0 deletions update_log.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.1.733

* Increased allowed random seed range.

# 2.1.728

* Fixed some potential numerical problems since 2.1.723
Expand Down
18 changes: 14 additions & 4 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
from modules.private_logger import get_current_html_path
from modules.ui_gradio_extensions import reload_javascript

# as in k-diffusion (sampling.py)
MIN_SEED = 0
MAX_SEED = 2**63 - 1


def generate_clicked(*args):
execution_start_time = time.perf_counter()
Expand Down Expand Up @@ -193,16 +197,22 @@ def clear_default_image():
info='Describing what you do not want to see.', lines=2,
value=modules.path.default_negative_prompt)
seed_random = gr.Checkbox(label='Random', value=True)
image_seed = gr.Number(label='Seed', value=0, precision=0, visible=False)
image_seed = gr.Textbox(label='Seed', value=0, max_lines=1, visible=False) # workaround for https://github.com/gradio-app/gradio/issues/5354

def random_checked(r):
return gr.update(visible=not r)

def refresh_seed(r, s):
def refresh_seed(r, seed_string):
if r:
return random.randint(1, 1024*1024*1024)
return random.randint(MIN_SEED, MAX_SEED)
else:
return s
try:
seed_value = int(seed_string)
if MIN_SEED <= seed_value <= MAX_SEED:
return seed_value
except ValueError:
pass
return random.randint(MIN_SEED, MAX_SEED)

seed_random.change(random_checked, inputs=[seed_random], outputs=[image_seed], queue=False)

Expand Down

0 comments on commit 81650a4

Please sign in to comment.