forked from comfyanonymous/ComfyUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't unload/reload model from CPU uselessly.
- Loading branch information
1 parent
e3e6594
commit a84cd0d
Showing
3 changed files
with
62 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
|
||
current_loaded_model = None | ||
|
||
|
||
def unload_model(): | ||
global current_loaded_model | ||
if current_loaded_model is not None: | ||
current_loaded_model.model.cpu() | ||
current_loaded_model.unpatch_model() | ||
current_loaded_model = None | ||
|
||
|
||
def load_model_gpu(model): | ||
global current_loaded_model | ||
if model is current_loaded_model: | ||
return | ||
unload_model() | ||
try: | ||
real_model = model.patch_model() | ||
except Exception as e: | ||
model.unpatch_model() | ||
raise e | ||
current_loaded_model = model | ||
real_model.cuda() | ||
return current_loaded_model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters