2022-06-28 00:58:17 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
2022-07-05 21:22:20 +00:00
"id": "view-in-github",
"colab_type": "text"
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-05 21:22:20 +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-05 21:22:20 +00:00
"outputId": "10a5df30-a55e-4180-dee9-844cf0aa1b69"
2022-06-28 00:58:17 +00:00
},
2022-07-04 20:30:39 +00:00
"outputs": [
{
2022-07-05 09:57:55 +00:00
"output_type": "stream",
2022-07-05 21:22:20 +00:00
"name": "stdout",
2022-07-04 20:30:39 +00:00
"text": [
"Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
2022-07-05 21:22:20 +00:00
"Collecting min-dalle==0.2.28\n",
" Using cached min-dalle-0.2.28.tar.gz (11 kB)\n",
"Requirement already satisfied: torch>=1.10.0 in /usr/local/lib/python3.7/dist-packages (from min-dalle==0.2.28) (1.11.0+cu113)\n",
"Requirement already satisfied: typing_extensions>=4.1.0 in /usr/local/lib/python3.7/dist-packages (from min-dalle==0.2.28) (4.1.1)\n",
"Requirement already satisfied: numpy>=1.21 in /usr/local/lib/python3.7/dist-packages (from min-dalle==0.2.28) (1.21.6)\n",
"Requirement already satisfied: pillow>=7.1 in /usr/local/lib/python3.7/dist-packages (from min-dalle==0.2.28) (7.1.2)\n",
"Requirement already satisfied: requests>=2.23 in /usr/local/lib/python3.7/dist-packages (from min-dalle==0.2.28) (2.23.0)\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.2.28) (1.24.3)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests>=2.23->min-dalle==0.2.28) (2022.6.15)\n",
"Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests>=2.23->min-dalle==0.2.28) (3.0.4)\n",
"Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2.23->min-dalle==0.2.28) (2.10)\n",
2022-07-05 09:52:30 +00:00
"Building wheels for collected packages: min-dalle\n",
" Building wheel for min-dalle (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
2022-07-05 21:22:20 +00:00
" Created wheel for min-dalle: filename=min_dalle-0.2.28-py3-none-any.whl size=11276 sha256=2950cee9d9859f67a8d19fb66ff3f8a6d48e8aa99527f854f6070dc9b104e07f\n",
" Stored in directory: /root/.cache/pip/wheels/c6/93/46/59099a6db4c0c4e962a4b02ea54705a5c4603ae365923f42b9\n",
2022-07-05 09:52:30 +00:00
"Successfully built min-dalle\n",
"Installing collected packages: min-dalle\n",
2022-07-05 21:22:20 +00:00
"Successfully installed min-dalle-0.2.28\n",
"Tue Jul 5 21:11:08 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-05 21:22:20 +00:00
"| N/A 35C 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",
"+-----------------------------------------------------------------------------+\n"
]
}
],
2022-06-28 00:58:17 +00:00
"source": [
2022-07-03 15:17:37 +00:00
"! pip install min-dalle\n",
"! nvidia-smi"
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-01 00:55:42 +00:00
"### Load Model"
2022-06-30 15:25:24 +00:00
]
2022-06-29 13:43:42 +00:00
},
{
"cell_type": "code",
2022-07-05 21:22:20 +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-05 21:22:20 +00:00
"outputId": "61c8b4f8-8a3d-4a97-f881-3b7e309e696f"
2022-06-29 13:43:42 +00:00
},
"outputs": [
{
2022-07-05 15:53:27 +00:00
"output_type": "stream",
2022-07-05 21:22:20 +00:00
"name": "stdout",
2022-06-29 13:43:42 +00:00
"text": [
2022-07-02 13:04:13 +00:00
"initializing MinDalle\n",
2022-07-05 21:22:20 +00:00
"downloading tokenizer params\n",
2022-07-01 21:34:23 +00:00
"intializing TextTokenizer\n",
2022-07-05 21:22:20 +00:00
"downloading encoder params\n",
2022-07-02 13:04:13 +00:00
"initializing DalleBartEncoder\n",
2022-07-05 21:22:20 +00:00
"downloading decoder params\n",
2022-07-02 13:04:13 +00:00
"initializing DalleBartDecoder\n",
2022-07-05 21:22:20 +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-05 15:53:27 +00:00
"from IPython.display import display, update_display\n",
2022-07-04 21:27:02 +00:00
"from math import log2\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-01 23:44:24 +00:00
"model = MinDalle(is_mega=True, is_reusable=True)"
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-05 13:37:52 +00:00
"- `grid_size` Size of the image grid. 3x3 works best when displaying intermediate outputs. 4x4 has been tested to work on T4 and P100 with intermediate outputs off\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-05 21:22:20 +00:00
"execution_count": 7,
2022-06-28 00:58:17 +00:00
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
2022-07-05 00:56:45 +00:00
"height": 819
2022-06-28 15:05:59 +00:00
},
"id": "nQ0UG05dA4p2",
2022-07-05 21:22:20 +00:00
"outputId": "7045cbde-7ebe-4305-b7a8-8a76d7c68251"
2022-06-28 00:58:17 +00:00
},
"outputs": [
{
2022-07-05 21:22:20 +00:00
"output_type": "display_data",
2022-06-28 00:58:17 +00:00
"data": {
"text/plain": [
2022-07-05 21:22:20 +00:00
"<PIL.Image.Image image mode=RGB size=768x768 at 0x7EFDA43F0710>"
],
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAwAAAAMACAIAAAAc45fZAAEAAElEQVR4nIz9adRk2Vnfif6eZw/nnBjeKYeaJ5VKKgkkBAJZQlgIAwab0RjLzJeml2nfxm6Mr/u2G9Meub4X29deLEPbmIY2xoAxNhgsjJnEJKHJmocqlWqeMiuzMvMdIuIMe3juh4hEYnnoez7kWhEZ74l3xbtj7//+T1v48X/O0z2jI1aisjnFC1KplSqIUpUiNJ6aqYYaDhIUB4rPOIcEckYVK7uXmWEFE2JDqainFqqgnuGM1lEyBq6lCChOyAVx2IgTTMgeQAuiSAQDAXCVsZAFTVjGRdSDI4EYTkk9DryQRrqWMeEqjIinZKhYQhyN0sP+gjGTC/46tn7TwTOfnx+TZ5/du/VlB+3y9gdfZ+rz0Jw71y5cSDwWZ3F9ZXV6fPnZx55/4pPPXVtf+fyvu/dVrz///Lue+tpvvQK89G/f2n7Gt3/0g2etH26Rssfxy/bLV73p4p3xxUceXT39scd+9nuffAJeDd/z53iy8Ld+nP/i9boL/KOfePCxG6dDXX/uq++2Mzm65c59u/snfuRH/9I/+BcP/cJvvunrflxbrgwQ+Jw/wjd/80u/7o/d+ehDex9/90d+/33Pv+yBxRe86Qvu++LvqTfKDbHV5rGSry8vdFdfODlLub/R/5t/+fMnzz6+FD76EU5vMBr7M6pyvIJb4IXIt/w57v0Mjo7IpywapsK6pxYoVKMIqgiYUSvqKRWDJJjhKiiqVKUKBmRqQQVXsUwSxIPDGyLgKRkVLJGNXMGQigkhYBVxWKYqzjGtaJScEaU41FMrzgBywQk5gQNFCk6YHFVBUcF7CrgGZyTP6o7Xf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"metadata": {}
2022-06-29 17:55:23 +00:00
},
{
2022-07-05 15:53:27 +00:00
"output_type": "stream",
2022-07-05 21:22:20 +00:00
"name": "stdout",
2022-06-29 17:55:23 +00:00
"text": [
2022-07-05 21:22:20 +00:00
"CPU times: user 34.1 s, sys: 448 ms, total: 34.6 s\n",
"Wall time: 34.4 s\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-04 20:06:14 +00:00
"grid_size = 3 #@param {type:\"integer\"}\n",
2022-07-05 19:07:32 +00:00
"supercondition_factor = 16 #@param [\"2\", \"4\", \"8\", \"16\", \"32\", \"64\"] {type:\"raw\"}\n",
2022-07-05 21:22:20 +00:00
"top_k = 64 #@param [\"2\", \"4\", \"8\", \"16\", \"32\", \"64\", \"128\", \"256\", \"512\", \"1024\"] {type:\"raw\"}\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-05 21:22:20 +00:00
" log2_k=int(log2(top_k)),\n",
2022-07-05 01:25:38 +00:00
" log2_supercondition_factor=log2(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-06-30 15:25:24 +00:00
"name": "min-dalle",
2022-07-05 21:22:20 +00:00
"provenance": [],
"include_colab_link": true
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-05 21:22:20 +00:00
}