add option to cache pip wheels

This commit is contained in:
Cyberes 2023-01-09 13:19:19 -07:00
parent bf943c9d9f
commit b6c474928c
No known key found for this signature in database
GPG Key ID: 194A1C358AACFC39
1 changed files with 22 additions and 11 deletions

View File

@ -71,13 +71,13 @@
"# symlink_to_notebooks = True # Enables the creation of symlinks back to /notebooks/\n",
"# model_storage_dir = '/tmp/stable-diffusion/models' # Where the models will be downloaded to.\n",
"# repo_storage_dir = '/notebooks' # Where the repository will be downloaded to.\n",
"# export_storage_dir = '/notebooks/exports' # Where the generated images will be exported to.\n",
"# pip_cache_dir = None # Cache pip downloads to this directory so you don't have to re-download everything.\n",
"\n",
"# Paid Tier\n",
"# symlink_to_notebooks = False\n",
"# model_storage_dir = '/storage/models'\n",
"# repo_storage_dir = '/notebooks'\n",
"# export_storage_dir = '/notebooks/exports'\n",
"# pip_cache_dir = '/storage/pip/cache'\n",
"\n",
"\n",
"# Other optional settings\n",
@ -115,10 +115,11 @@
" # If you don't set a password, anyone can install and run arbitrary code on your machine!\n",
" # Instead, use gradio_auth which will automatically enable extensions when set.\n",
"\n",
"\n",
"export_storage_dir = '/notebooks/exports' # Where the generated images will be exported to.\n",
" \n",
"# ===================================================================================================\n",
"# Save variables to Jupiter's temp storage so we can access it even if the kernel restarts.\n",
"%store symlink_to_notebooks model_storage_dir repo_storage_dir export_storage_dir activate_xformers link_novelai_anime_vae download_scripts activate_deepdanbooru activate_medvram disable_pickle_check gradio_port gradio_auth search_paperspace_datasets ui_theme insecure_extension_access"
"%store symlink_to_notebooks model_storage_dir repo_storage_dir export_storage_dir activate_xformers link_novelai_anime_vae download_scripts activate_deepdanbooru activate_medvram disable_pickle_check gradio_port gradio_auth search_paperspace_datasets ui_theme insecure_extension_access pip_cache_dir"
]
},
{
@ -210,8 +211,8 @@
"outputs": [],
"source": [
"try:\n",
" %store -r symlink_to_notebooks model_storage_dir repo_storage_dir activate_xformers download_scripts activate_deepdanbooru\n",
" test = [symlink_to_notebooks, model_storage_dir, repo_storage_dir, activate_xformers, download_scripts, activate_deepdanbooru]\n",
" %store -r symlink_to_notebooks model_storage_dir repo_storage_dir activate_xformers download_scripts activate_deepdanbooru pip_cache_dir\n",
" test = [symlink_to_notebooks, model_storage_dir, repo_storage_dir, activate_xformers, download_scripts, activate_deepdanbooru, pip_cache_dir]\n",
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
@ -222,19 +223,26 @@
"%cd \"{repo_storage_dir}/stable-diffusion-webui\"\n",
"\n",
"!pip install --upgrade pip\n",
"!pip install --upgrade wheel setuptools\n",
"\n",
"if pip_cache_dir:\n",
" !pip install git+https://github.com/pixelb/crudini.git\n",
" !mkdir -p \"{pip_cache_dir}\"\n",
" !python3 -m crudini --set /etc/pip.conf global cache-dir \"{pip_cache_dir}\"\n",
" !echo \"Set pip cache directory: $(pip cache dir)\"\n",
"\n",
"import os\n",
"\n",
"# Import launch.py which will automatically run the install script but not launch the WebUI.\n",
"# They require a few specific external git repo commits so we have to do it their way. \n",
"import launch\n",
"launch.prepare_environment()\n",
"\n",
"# The installer isn't installing deepdanbooru right now so we'll do it manually\n",
"# The installer isn't installing deepdanbooru right now so we'll do it manually.\n",
"if activate_deepdanbooru:\n",
" !pip install \"git+https://github.com/KichangKim/DeepDanbooru.git@edf73df4cdaeea2cf00e9ac08bd8a9026b7a7b26#egg=deepdanbooru[tensorflow]\" # tensorflow==2.10.0 tensorflow-io==0.27.0 flatbuffers==1.12\n",
"\n",
"# latent-diffusion is a requirement but launch.py isn't downloading it so we'll do it manually.\n",
"# TODO: can this be removed?\n",
"if not os.path.exists(f'{repo_storage_dir}/stable-diffusion-webui/repositories/latent-diffusion'):\n",
" !git clone https://github.com/crowsonkb/k-diffusion.git \"{repo_storage_dir}/stable-diffusion-webui/repositories/k-diffusion\"\n",
" !git clone https://github.com/Hafiidz/latent-diffusion.git \"{repo_storage_dir}/stable-diffusion-webui/repositories/latent-diffusion\"\n",
@ -956,8 +964,8 @@
"outputs": [],
"source": [
"try:\n",
" %store -r model_storage_dir repo_storage_dir\n",
" test = [model_storage_dir, repo_storage_dir]\n",
" %store -r model_storage_dir repo_storage_dir pip_cache_dir\n",
" test = [model_storage_dir, repo_storage_dir, pip_cache_dir]\n",
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
@ -966,7 +974,10 @@
" sys.exit(1)\n",
"\n",
"# Get some storage back\n",
"!pip cache purge\n",
"\n",
"if not pip_cache_dir:\n",
" !pip cache purge\n",
" !echo \"Purged pip cache\"\n",
"!cd \"{model_storage_dir}\" && rm *.aria2\n",
"!apt remove --purge -y aria2 p7zip-full\n",
"!apt autoremove --purge -y\n",