diff --git a/README.md b/README.md index 7471681..ae5e415 100644 --- a/README.md +++ b/README.md @@ -212,7 +212,7 @@ imagine_image_files(prompts, outdir="./my-art") ## Requirements - ~10 gb space for models to download -- A decent computer with either a CUDA supported graphics card or M1 processor. +- A decent computer with either a CUDA supported graphics card (and CUDA installed) or an M1 processor. - Python installed. Preferably Python 3.10. (not conda) - For macOS [rust](https://www.rust-lang.org/tools/install) and setuptools-rust must be installed to compile the `tokenizer` library. They can be installed via: `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh` and `pip install setuptools-rust` @@ -230,6 +230,10 @@ docker run -it --gpus all -v $HOME/.cache/huggingface:/root/.cache/huggingface - [Example Colab](https://colab.research.google.com/drive/1rOvQNs0Cmn_yU1bKWjCOHzGVDgZkaTtO?usp=sharing) ## ChangeLog +**7.1.1** +- fix: memory/speed regression introduced in 6.1.0 +- fix: model switching now clears memory better, thus avoiding out of memory errors + **7.1.0** - feature: 🎉 Stable Diffusion 2.1. Generated people are no longer (completely) distorted. Use with `--model SD-2.1` or `--model SD-2.0-v` diff --git a/imaginairy/model_manager.py b/imaginairy/model_manager.py index 3b3dd1c..0029115 100644 --- a/imaginairy/model_manager.py +++ b/imaginairy/model_manager.py @@ -63,8 +63,14 @@ class MemoryAwareModel: return getattr(self._model, key) def unload_model(self): - del self._model - self._model = None + if self._model is not None: + del self._model.cond_stage_model + del self._model.first_stage_model + del self._model.model + del self._model + self._model = None + if get_device() == "cuda": + torch.cuda.empty_cache() gc.collect() diff --git a/tests/expected_output/test_model_versions__a photo of a bowl of fruit_SD-2.0-v.png b/tests/expected_output/test_model_versions__a photo of a bowl of fruit_SD-2.0-v.png index 295b3e1..65b059b 100644 Binary files a/tests/expected_output/test_model_versions__a photo of a bowl of fruit_SD-2.0-v.png and b/tests/expected_output/test_model_versions__a photo of a bowl of fruit_SD-2.0-v.png differ diff --git a/tests/test_api.py b/tests/test_api.py index bab56e6..2c05e23 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -54,7 +54,7 @@ def test_model_versions(filename_base_for_orig_outputs, model_version): ) ) - threshold = 10000 + threshold = 14000 for i, result in enumerate(imagine(prompts)): img_path = f"{filename_base_for_orig_outputs}_{result.prompt.prompt_text}_{result.prompt.model}.png" @@ -157,7 +157,7 @@ def test_img_to_img_fruit_2_gold( "k_dpm_2_a": 26000, "k_dpm_adaptive": 13000, } - threshold = threshold_lookup.get(sampler_type, 10000) + threshold = threshold_lookup.get(sampler_type, 11000) pillow_fit_image_within(img).save(f"{filename_base_for_orig_outputs}__orig.jpg") img_path = f"{filename_base_for_outputs}.png" diff --git a/tests/test_clip_embedder.py b/tests/test_clip_embedder.py index 2a5a44a..0f1b97e 100644 --- a/tests/test_clip_embedder.py +++ b/tests/test_clip_embedder.py @@ -21,4 +21,5 @@ def test_text_conditioning(): "263e5ee7d2be087d816e094b80ffc546", # mps "41818051d7c469fc57d0a940c9d24d82", "b5f29fb26bceb60dcde19ec7ec5a0711", + "88245bdb2a83b49092407fc5b4c473ab", # ubuntu, torch 1.12.1 cu116 } diff --git a/tests/test_enhancers.py b/tests/test_enhancers.py index 4f6decf..bc8a904 100644 --- a/tests/test_enhancers.py +++ b/tests/test_enhancers.py @@ -60,7 +60,7 @@ def test_clip_masking(filename_base_for_outputs): result = next(imagine(prompt)) img_path = f"{filename_base_for_outputs}.png" - assert_image_similar_to_expectation(result.img, img_path=img_path, threshold=600) + assert_image_similar_to_expectation(result.img, img_path=img_path, threshold=1000) boolean_mask_test_cases = [