2022-06-28 00:58:17 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
2022-07-11 17:19:06 +00:00
"colab_type": "text",
"id": "view-in-github"
2022-06-28 00:58:17 +00:00
},
"source": [
"<a href=\"https://colab.research.google.com/github/kuprel/min-dalle/blob/main/min_dalle.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "3WL-G_f2_ld8"
},
"source": [
"# min(DALL·E)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Zl_ZFisFApeh"
},
"source": [
2022-07-01 22:16:55 +00:00
"### Install"
2022-06-28 00:58:17 +00:00
]
},
{
"cell_type": "code",
2022-07-11 16:38:23 +00:00
"execution_count": 1,
2022-06-28 00:58:17 +00:00
"metadata": {
2022-06-30 14:02:08 +00:00
"cellView": "code",
2022-07-04 20:30:39 +00:00
"colab": {
"base_uri": "https://localhost:8080/"
2022-07-05 03:17:31 +00:00
},
"id": "ix_xt4X1_6F4",
2022-07-11 16:38:23 +00:00
"outputId": "7b0178cf-9818-40f9-f7ab-7d06a5f8ae5b"
2022-06-28 00:58:17 +00:00
},
2022-07-04 20:30:39 +00:00
"outputs": [
{
2022-07-11 16:38:23 +00:00
"name": "stdout",
2022-07-11 17:19:06 +00:00
"output_type": "stream",
2022-07-04 20:30:39 +00:00
"text": [
2022-07-11 16:38:23 +00:00
"Mon Jul 11 16:30:52 2022 \n",
2022-07-04 20:30:39 +00:00
"+-----------------------------------------------------------------------------+\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 P100-PCIE... Off | 00000000:00:04.0 Off | 0 |\n",
2022-07-11 16:38:23 +00:00
"| N/A 36C P0 27W / 250W | 0MiB / 16280MiB | 0% Default |\n",
2022-07-04 20:30:39 +00:00
"| | | 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",
2022-07-09 14:30:12 +00:00
"+-----------------------------------------------------------------------------+\n",
"Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
2022-07-11 16:38:23 +00:00
"Collecting min-dalle==0.3.12\n",
" Downloading min-dalle-0.3.12.tar.gz (10 kB)\n",
"Requirement already satisfied: torch>=1.11 in /usr/local/lib/python3.7/dist-packages (from min-dalle==0.3.12) (1.11.0+cu113)\n",
"Requirement already satisfied: typing_extensions>=4.1 in /usr/local/lib/python3.7/dist-packages (from min-dalle==0.3.12) (4.1.1)\n",
"Requirement already satisfied: numpy>=1.21 in /usr/local/lib/python3.7/dist-packages (from min-dalle==0.3.12) (1.21.6)\n",
"Requirement already satisfied: pillow>=7.1 in /usr/local/lib/python3.7/dist-packages (from min-dalle==0.3.12) (7.1.2)\n",
"Requirement already satisfied: requests>=2.23 in /usr/local/lib/python3.7/dist-packages (from min-dalle==0.3.12) (2.23.0)\n",
"Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2.23->min-dalle==0.3.12) (2.10)\n",
"Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests>=2.23->min-dalle==0.3.12) (3.0.4)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests>=2.23->min-dalle==0.3.12) (2022.6.15)\n",
"Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests>=2.23->min-dalle==0.3.12) (1.24.3)\n",
2022-07-09 14:30:12 +00:00
"Building wheels for collected packages: min-dalle\n",
" Building wheel for min-dalle (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
2022-07-11 16:38:23 +00:00
" Created wheel for min-dalle: filename=min_dalle-0.3.12-py3-none-any.whl size=10673 sha256=c16cf367ea607357b8db7735f8859001d41a7a0b013224ac38cc730d7edb8c63\n",
" Stored in directory: /root/.cache/pip/wheels/2c/15/26/963d2a412cc59dbf07a77ac814ab5c8eb4e3a892415967af0d\n",
2022-07-09 14:30:12 +00:00
"Successfully built min-dalle\n",
"Installing collected packages: min-dalle\n",
2022-07-11 16:38:23 +00:00
"Successfully installed min-dalle-0.3.12\n"
2022-07-04 20:30:39 +00:00
]
}
],
2022-06-28 00:58:17 +00:00
"source": [
2022-07-07 12:21:20 +00:00
"! nvidia-smi\n",
2022-07-11 17:19:06 +00:00
"! pip install min-dalle"
2022-06-28 00:58:17 +00:00
]
},
2022-06-29 13:43:42 +00:00
{
"cell_type": "markdown",
2022-06-30 15:25:24 +00:00
"metadata": {
"id": "kViq2dMbGDKt"
},
2022-06-29 13:43:42 +00:00
"source": [
2022-07-09 14:35:17 +00:00
"### Load Model\n",
2022-07-10 17:23:42 +00:00
"`float32` is faster than `float16` but uses more GPU memory. Change the `grid_size` to 3 or less if using `float32`."
2022-06-30 15:25:24 +00:00
]
2022-06-29 13:43:42 +00:00
},
{
"cell_type": "code",
2022-07-11 16:38:23 +00:00
"execution_count": 2,
2022-06-29 13:43:42 +00:00
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
2022-06-30 15:25:24 +00:00
},
"id": "8W-L2ICFGFup",
2022-07-11 16:38:23 +00:00
"outputId": "e382228a-50f9-4a01-d561-c232428cf940"
2022-06-29 13:43:42 +00:00
},
"outputs": [
{
2022-07-11 16:38:23 +00:00
"name": "stdout",
2022-07-11 17:19:06 +00:00
"output_type": "stream",
2022-06-29 13:43:42 +00:00
"text": [
2022-07-11 16:38:23 +00:00
"downloading tokenizer params\n",
2022-07-01 21:34:23 +00:00
"intializing TextTokenizer\n",
2022-07-11 16:38:23 +00:00
"downloading encoder params\n",
2022-07-02 13:04:13 +00:00
"initializing DalleBartEncoder\n",
2022-07-11 16:38:23 +00:00
"downloading decoder params\n",
2022-07-02 13:04:13 +00:00
"initializing DalleBartDecoder\n",
2022-07-11 16:38:23 +00:00
"downloading detokenizer params\n",
2022-06-30 19:17:35 +00:00
"initializing VQGanDetokenizer\n"
2022-06-29 13:43:42 +00:00
]
}
2022-06-30 15:25:24 +00:00
],
"source": [
2022-07-10 17:24:52 +00:00
"dtype = \"float16\" #@param [\"float32\", \"float16\", \"bfloat16\"]\n",
2022-07-05 15:53:27 +00:00
"from IPython.display import display, update_display\n",
2022-07-07 14:28:07 +00:00
"import torch\n",
2022-07-01 23:44:24 +00:00
"from min_dalle import MinDalle\n",
2022-06-30 15:25:24 +00:00
"\n",
2022-07-07 14:28:07 +00:00
"model = MinDalle(\n",
2022-07-10 17:23:42 +00:00
" dtype=getattr(torch, dtype),\n",
2022-07-07 14:28:07 +00:00
" is_mega=True, \n",
" is_reusable=True\n",
")"
2022-06-29 13:43:42 +00:00
]
},
2022-06-28 00:58:17 +00:00
{
"cell_type": "markdown",
2022-06-28 15:01:31 +00:00
"metadata": {
2022-06-28 15:05:59 +00:00
"id": "c52TV1GbBNgS"
},
"source": [
2022-07-02 18:54:18 +00:00
"### Generate Images\n",
2022-07-05 01:42:27 +00:00
"\n",
2022-07-09 14:30:12 +00:00
"- `grid_size` Size of the image grid. Reduce this if you run out of GPU memory.\n",
2022-07-05 03:01:13 +00:00
"\n",
2022-07-05 13:37:52 +00:00
"- `intermediate_outputs` Whether to show intermediate output. Adds a small delay and increases memory usage.\n",
2022-07-05 03:01:13 +00:00
"\n",
2022-07-05 21:22:20 +00:00
"- `supercondition_factor` Higher values result in better agreement with the text but a narrower variety of generated images\n",
"\n",
"- `top_k` Each image token is sampled from the top $k$ most probable tokens"
2022-06-28 15:05:59 +00:00
]
2022-06-28 00:58:17 +00:00
},
{
"cell_type": "code",
2022-07-11 16:38:23 +00:00
"execution_count": 3,
2022-06-28 00:58:17 +00:00
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
2022-07-11 16:38:23 +00:00
"height": 995
2022-06-28 15:05:59 +00:00
},
"id": "nQ0UG05dA4p2",
2022-07-11 16:38:23 +00:00
"outputId": "4af26983-0b57-4437-faf7-7bd97fa579d7"
2022-06-28 00:58:17 +00:00
},
"outputs": [
{
"data": {
2022-07-11 17:19:06 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAABQAAAAUACAIAAACXhmigAAEAAElEQVR4nJy9Zbxt2VXm/Z+6bMuRa3XLq1JecQ9xQiAQCAQNvI00bm/T3QRt7A0SrNPdQHAIBNcmpEkIMQJxr6qkJOV+9ciWtda08X44NwL0L9A9vp011557nd+e65lzjPGMZyj++LXcF1gbTKFyDEuWC7oKByWzSvgaVYiZjSmLgdqxWHFoi7O7dBX9gmIQjff4CmtwgVMLzJzpab3xCPvbX7X19lMPA6B/4BfL07+Y4R568JsM+/QJJ4wDTkgF40iRGJh2xES0nAzIGVq4/X38+s9zYF/6nXz5d6ET9KxHlKUP5JHGcXpB06ACIeAEZxlG6pow0imSYv8UY0R6mmOkFfWEsdBtsMgoS9SogjYMA7aQRyqLAqXJiQRaUwacJa0pQjZ4R5+xin5g3pET40jUGI816AJQTViuEM28JYzsLtmYkJdERW0YM76GCJZc2DvLeXP2lpRCrugzdYVT5BHr2dtDhFnHkEmZztEvWAkTh1JkkEwCDP0eF22zs8IaFgpbI4VaURJNw2pJSmzOyYX9BY2nRJaRzY5YcDVpRNfkRL/g2JTFPiiiZV1Qhs4TA8qwv0fTcHyT04FhZKpYLUjgHAbEIhEsy4TPbE3Y7yFjW4JgFN6gC7piscB7uooRQqCzDGv6wqwiJ7RHMlHhK8YlE8cYqTyDAgfgFf2A1eRASVQTFontKf0KEbJQW8jETEnYlhJxHeH8533G0Xvu7v06Be+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CFFuhmXX
2022-06-28 00:58:17 +00:00
"text/plain": [
2022-07-11 16:38:23 +00:00
"<PIL.Image.Image image mode=RGB size=1280x1280 at 0x7F6C72852E50>"
2022-07-11 17:19:06 +00:00
]
2022-06-28 00:58:17 +00:00
},
2022-07-11 17:19:06 +00:00
"metadata": {},
"output_type": "display_data"
2022-06-29 17:55:23 +00:00
},
{
2022-07-11 16:38:23 +00:00
"name": "stdout",
2022-07-11 17:19:06 +00:00
"output_type": "stream",
2022-06-29 17:55:23 +00:00
"text": [
2022-07-11 16:38:23 +00:00
"CPU times: user 1min 22s, sys: 2.91 s, total: 1min 25s\n",
"Wall time: 1min 28s\n"
2022-06-29 17:55:23 +00:00
]
2022-06-28 00:58:17 +00:00
}
2022-06-28 15:05:59 +00:00
],
"source": [
2022-06-29 17:55:23 +00:00
"%%time\n",
"\n",
2022-07-03 22:40:27 +00:00
"text = \"Dali painting of WALL·E\" #@param {type:\"string\"}\n",
2022-07-05 13:37:52 +00:00
"intermediate_outputs = True #@param {type:\"boolean\"}\n",
2022-07-09 14:30:12 +00:00
"grid_size = 5 #@param {type:\"integer\"}\n",
2022-07-12 00:58:00 +00:00
"temperature = 2 #@param {type:\"slider\", min:0.01, max:3, step:0.01}\n",
2022-07-11 16:38:23 +00:00
"supercondition_factor = 16 #@param {type:\"number\"}\n",
"top_k = 256 #@param {type:\"integer\"}\n",
2022-07-05 13:37:52 +00:00
"log2_mid_count = 3 if intermediate_outputs else 0\n",
2022-07-04 20:06:14 +00:00
"\n",
2022-07-05 00:06:28 +00:00
"image_stream = model.generate_image_stream(\n",
2022-07-05 01:25:38 +00:00
" text=text,\n",
2022-07-05 13:37:52 +00:00
" seed=-1,\n",
2022-07-05 01:25:38 +00:00
" grid_size=grid_size,\n",
2022-07-05 13:37:52 +00:00
" log2_mid_count=log2_mid_count,\n",
2022-07-11 18:09:50 +00:00
" temperature=temperature,\n",
2022-07-11 16:30:10 +00:00
" top_k=int(top_k),\n",
" supercondition_factor=float(supercondition_factor)\n",
2022-07-04 21:44:30 +00:00
")\n",
"\n",
2022-07-05 02:52:00 +00:00
"is_first = True\n",
2022-07-05 00:06:28 +00:00
"for image in image_stream:\n",
2022-07-05 02:52:00 +00:00
" display_image = display if is_first else update_display\n",
" display_image(image, display_id=1)\n",
" is_first = False"
2022-06-28 00:58:17 +00:00
]
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
2022-06-28 15:05:59 +00:00
"collapsed_sections": [
"Zl_ZFisFApeh"
],
2022-07-11 17:19:06 +00:00
"include_colab_link": true,
2022-06-30 15:25:24 +00:00
"name": "min-dalle",
2022-07-11 17:19:06 +00:00
"provenance": []
2022-06-28 00:58:17 +00:00
},
"gpuClass": "standard",
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
2022-07-11 17:19:06 +00:00
}