Skip to content

Commit

Permalink
fix upload/reload buttons to workaround webui bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wkpark committed Oct 15, 2023
1 parent 1ecf93b commit 1305ed4
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions scripts/model_mixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,16 +948,26 @@ def change_mode(mode):
unload_sd_model = gr.Button("Unload model to free VRAM")
reload_sd_model = gr.Button("Reload model back to VRAM")

def call_func_and_return_text(func, text):
def handler():
t = Timer()
func()
t.record(text)

return f'{text} in {t.total:.1f}s'

return handler

unload_sd_model.click(
fn=sd_models.unload_model_weights,
fn=call_func_and_return_text(lambda: sd_models.send_model_to_cpu(shared.sd_model), 'Unloaded the checkpoint'),
inputs=[],
outputs=[]
outputs=[logging]
)

reload_sd_model.click(
fn=sd_models.reload_model_weights,
fn=call_func_and_return_text(lambda: sd_models.send_model_to_device(shared.sd_model), 'Reload the checkpoint'),
inputs=[],
outputs=[]
outputs=[logging]
)

def addblockweights(val, blockopt, *blocks):
Expand Down

0 comments on commit 1305ed4

Please sign in to comment.