Skip to content

Instantly share code, notes, and snippets.

@putuoka
Last active August 28, 2022 16:04
Show Gist options
  • Save putuoka/572c57c0a3844bcee0377924d0e6eb91 to your computer and use it in GitHub Desktop.
Save putuoka/572c57c0a3844bcee0377924d0e6eb91 to your computer and use it in GitHub Desktop.
Prog Rock Stable.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Prog Rock Stable.ipynb",
"provenance": [],
"collapsed_sections": [
"aZn37_DUwGC2",
"A6y98K_6-n0A",
"hYb6lkTB_S5N"
],
"authorship_tag": "ABX9TyPXfB8iNlA4qk0T8APc1hfD",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU",
"gpuClass": "standard"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/putuoka/572c57c0a3844bcee0377924d0e6eb91/prog-rock-stable.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"Learn to try writing colab for Prog Rock Stable https://github.com/lowfuel/progrock-stable"
],
"metadata": {
"id": "GYwwW17GHvrJ"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 412
},
"id": "fJdYQupujee7",
"outputId": "961f03e9-3236-4162-ecac-02164f1faa02"
},
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"<IPython.core.display.HTML object>"
],
"text/html": [
"<h2>you have a tesla T4, use free training options</h2>"
]
},
"metadata": {}
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"Sat Aug 27 01:51:48 2022 \n",
"+-----------------------------------------------------------------------------+\n",
"| NVIDIA-SMI 460.32.03 Driver Version: 460.32.03 CUDA Version: 11.2 |\n",
"|-------------------------------+----------------------+----------------------+\n",
"| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |\n",
"| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |\n",
"| | | MIG M. |\n",
"|===============================+======================+======================|\n",
"| 0 Tesla T4 Off | 00000000:00:04.0 Off | 0 |\n",
"| N/A 40C P8 9W / 70W | 0MiB / 15109MiB | 0% Default |\n",
"| | | N/A |\n",
"+-------------------------------+----------------------+----------------------+\n",
" \n",
"+-----------------------------------------------------------------------------+\n",
"| Processes: |\n",
"| GPU GI CI PID Type Process name GPU Memory |\n",
"| ID ID Usage |\n",
"|=============================================================================|\n",
"| No running processes found |\n",
"+-----------------------------------------------------------------------------+\n"
]
}
],
"source": [
"#@markdown select best GPU to be used\n",
"# restart runtime until it gets better gpu\n",
"from IPython.display import HTML\n",
"from subprocess import getoutput\n",
"s = getoutput('nvidia-smi')\n",
"if 'K80' in s:\n",
" gpu = 'you have a K80, try different kinds of settings'\n",
"elif 'T4' in s:\n",
" gpu = 'you have a tesla T4, use free training options'\n",
"elif 'P100' in s:\n",
" gpu = 'you have a P100, try different kinds of settings'\n",
"display(HTML(f\"<h2>{gpu}</h2>\"))\n",
"print(s)"
]
},
{
"cell_type": "markdown",
"source": [
"###Download CKPT File From Gdrive(Fastest)"
],
"metadata": {
"id": "aZn37_DUwGC2"
}
},
{
"cell_type": "markdown",
"source": [
"You can create a shortcut to your google drive in main folder\n",
"https://drive.google.com/file/d/1wHFgl0ivCmIZv88hVZXkb8oy9qCuaBGA/view?usp=sharing\n",
"\n",
"**The weights must be in the google drive root folder**"
],
"metadata": {
"id": "TYsNj6_wwzYy"
}
},
{
"cell_type": "code",
"source": [
"from google.colab import drive\n",
"drive.mount('/gdrive')"
],
"metadata": {
"id": "eBTg1XfmxEMs"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"!cp '/gdrive/My Drive/model.ckpt' /content/sd-v1-4.ckpt"
],
"metadata": {
"id": "RGssr3mOxKm5"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"### Download CKPT file from torrent"
],
"metadata": {
"id": "A6y98K_6-n0A"
}
},
{
"cell_type": "code",
"source": [
"!python -m pip install --upgrade pip setuptools wheel\n",
"!python -m pip install lbry-libtorrent\n",
"!apt install python3-libtorrent"
],
"metadata": {
"id": "Sm3aXDNv-ezW"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import libtorrent as lt\n",
"import time\n",
"import datetime\n",
"\n",
"ses = lt.session()\n",
"ses.listen_on(6881, 6891)\n",
"params = {\n",
" 'save_path': '/content/'}\n",
"link = \"magnet:?xt=urn:btih:3a4a612d75ed088ea542acac52f9f45987488d1c&dn=sd-v1-4.ckpt&tr=udp%3a%2f%2ftracker.openbittorrent.com%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337\" # PASTE TORRENT/MAGNET LINK HERE\n",
"print(link)\n",
"\n",
"handle = lt.add_magnet_uri(ses, link, params)\n",
"ses.start_dht()\n",
"\n",
"begin = time.time()\n",
"print(datetime.datetime.now())\n",
"\n",
"print ('Downloading Metadata...')\n",
"while (not handle.has_metadata()):\n",
" time.sleep(1)\n",
"print ('Got Metadata, Starting Torrent Download...')\n",
"\n",
"print(\"Starting\", handle.name())\n",
"\n",
"while (handle.status().state != lt.torrent_status.seeding):\n",
" s = handle.status()\n",
" state_str = ['queued', 'checking', 'downloading metadata', \\\n",
" 'downloading', 'finished', 'seeding', 'allocating']\n",
" print ('%.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s ' % \\\n",
" (s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, \\\n",
" s.num_peers, state_str[s.state]))\n",
" time.sleep(5)\n",
"\n",
"end = time.time()\n",
"print(handle.name(), \"COMPLETE\")\n",
"\n",
"print(\"Elapsed Time: \",int((end-begin)//60),\"min :\", int((end-begin)%60), \"sec\")\n",
"\n",
"print(datetime.datetime.now())"
],
"metadata": {
"id": "sY4mHcZ0_Lxs"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"###Set Up & Run"
],
"metadata": {
"id": "hYb6lkTB_S5N"
}
},
{
"cell_type": "code",
"source": [
"!git clone https://github.com/lowfuel/progrock-stable prs\n",
"%cd prs"
],
"metadata": {
"id": "9qeb4IU__iC8"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"!pip install torch numpy omegaconf clean-fid json5\n",
"!pip install -e git+https://github.com/openai/CLIP.git@main#egg=clip \n",
"!pip install -e git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers"
],
"metadata": {
"id": "Um7V2q7RDobo"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"\n",
"!pip install pytorch-lightning torch-fidelity\n",
"!pip install numpy omegaconf einops kornia pytorch-lightning\n",
"!pip install albumentations transformers\n",
"!pip install ftfy jsonmerge resize-right torchdiffeq tqdm"
],
"metadata": {
"id": "PoZNL5hzEJqs"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"!mv /content/sd-v1-4.ckpt ./models/sd-v1-4.ckpt"
],
"metadata": {
"id": "ZvdGhkbPFhr7"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"!python prs.py -p \"beautiful island in pacific\" --gobig"
],
"metadata": {
"id": "ST8hgkjwDk3b"
},
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment