min-dalle-test/min_dalle.ipynb

253 lines
2.6 MiB
Plaintext
Raw Normal View History

2022-06-28 00:58:17 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
2022-07-17 11:32:32 +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-11 16:38:23 +00:00
"execution_count": 1,
2022-06-28 00:58:17 +00:00
"metadata": {
"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-17 11:32:32 +00:00
"outputId": "c72b1def-798b-401a-fad5-25e715f60dfe"
2022-06-28 00:58:17 +00:00
},
2022-07-04 20:30:39 +00:00
"outputs": [
{
2022-07-11 17:19:06 +00:00
"output_type": "stream",
2022-07-17 11:32:32 +00:00
"name": "stdout",
2022-07-04 20:30:39 +00:00
"text": [
2022-07-17 11:32:32 +00:00
"Sun Jul 17 11:27:12 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-17 11:32:32 +00:00
"| N/A 36C P0 26W / 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-17 11:32:32 +00:00
"Collecting min-dalle==0.3.15\n",
" Downloading min-dalle-0.3.15.tar.gz (10 kB)\n",
"Requirement already satisfied: torch>=1.11 in /usr/local/lib/python3.7/dist-packages (from min-dalle==0.3.15) (1.12.0+cu113)\n",
"Requirement already satisfied: typing_extensions>=4.1 in /usr/local/lib/python3.7/dist-packages (from min-dalle==0.3.15) (4.1.1)\n",
"Requirement already satisfied: numpy>=1.21 in /usr/local/lib/python3.7/dist-packages (from min-dalle==0.3.15) (1.21.6)\n",
"Requirement already satisfied: pillow>=7.1 in /usr/local/lib/python3.7/dist-packages (from min-dalle==0.3.15) (7.1.2)\n",
"Requirement already satisfied: requests>=2.23 in /usr/local/lib/python3.7/dist-packages (from min-dalle==0.3.15) (2.23.0)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests>=2.23->min-dalle==0.3.15) (2022.6.15)\n",
"Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2.23->min-dalle==0.3.15) (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.15) (3.0.4)\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.15) (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-17 11:32:32 +00:00
" Created wheel for min-dalle: filename=min_dalle-0.3.15-py3-none-any.whl size=10562 sha256=3fa7138ec8078d7442a6a0a4c02653759b255d5853bfaa1710c5746399111aea\n",
" Stored in directory: /root/.cache/pip/wheels/92/58/05/36292d8d8de42c1d8afa532a27cbd026daaeab31819ac2b3c8\n",
2022-07-09 14:30:12 +00:00
"Successfully built min-dalle\n",
"Installing collected packages: min-dalle\n",
2022-07-17 11:32:32 +00:00
"Successfully installed min-dalle-0.3.15\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
]
},
{
"cell_type": "markdown",
2022-06-30 15:25:24 +00:00
"metadata": {
"id": "kViq2dMbGDKt"
},
"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
]
},
{
"cell_type": "code",
2022-07-11 16:38:23 +00:00
"execution_count": 2,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
2022-06-30 15:25:24 +00:00
},
"id": "8W-L2ICFGFup",
2022-07-17 11:32:32 +00:00
"outputId": "9ae4d35c-52f8-4733-9972-e46755cba899"
},
"outputs": [
{
2022-07-11 17:19:06 +00:00
"output_type": "stream",
2022-07-17 11:32:32 +00:00
"name": "stdout",
"text": [
2022-07-17 11:32:32 +00:00
"using device cuda\n",
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",
"initializing DalleBartEncoder\n",
2022-07-11 16:38:23 +00:00
"downloading decoder params\n",
"initializing DalleBartDecoder\n",
2022-07-11 16:38:23 +00:00
"downloading detokenizer params\n",
"initializing VQGanDetokenizer\n"
]
}
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",
"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",
" device='cuda',\n",
2022-07-07 14:28:07 +00:00
" is_mega=True, \n",
" is_reusable=True\n",
")"
]
},
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-17 11:32:32 +00:00
"- `progressive_outputs` Whether to show intermediate output. Adds a small delay and increases memory usage.\n",
"\n",
"- `seamless` Tiles the images in token space instead of pixel space\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-17 11:32:32 +00:00
"height": 1000
2022-06-28 15:05:59 +00:00
},
"id": "nQ0UG05dA4p2",
2022-07-17 11:32:32 +00:00
"outputId": "7faf570a-3444-4e6a-d117-a4e1d0b09ce5"
2022-06-28 00:58:17 +00:00
},
"outputs": [
{
2022-07-17 11:32:32 +00:00
"output_type": "display_data",
2022-06-28 00:58:17 +00:00
"data": {
"text/plain": [
2022-07-17 11:32:32 +00:00
"<PIL.Image.Image image mode=RGB size=1024x1024 at 0x7FA55DFEEE50>"
],
"image/png": "iVBORw0KGgoAAAANSUhEUgAABAAAAAQACAIAAADwf7zUAAEAAElEQVR4nKT9Z9ht2VUeiL5jzLTC3vtL5zu5zjmVc5VKqSQkAUIESRbRYMw1Brsd4HHb0L7uxtltY3fTxjY0joBNNJgkkBCYqIRQRKWSyipVjufUyed8YYcVZhjj/qhSqSTUxvfe8Ws/a44159rPetec70hzEv/tfyArwajQgonHzj5I4QugsB5kERVsYQgloa5BCfMOvkE28AYYQARuUBK8QYrQhGSQCS6DMowFOQghA2zBBmOHSUAc0Ec7mTljShpiHAEDo+iXGCOaDRxex0rQrNXS1TndNbnylhvykaNPv/qNr3jvL73nus2N3/nZh3/xnWcOn8CnHsXzUt9x3Wu+4ptOycNPfvQDhvTwpiyX8fitt2zfdMfbf/pjDz30NBhoj+DgIXQt1g6jFZgKDGRFaOvG9wOwXOCswDOcwluYHmbAeLndaA66/WuuweWz5eEPfBJm+5rbj/vKlvWTr/yyax/5xNMP/tpHgLMAAAckvES2jtp//8PfcMO1b728y1132hY5f+HS06c/9Be+81u+4Q3/7JGd4fm7fvH+n7rn9rtp+dgf/cFv/fN/+BM33n3s3lff8h//1nueKC/tDM0p871/7U0/9H2/N+L/a/k7v/6fntlZf+7iam8Y2WhJmYzurXotuW2n+8t501aOqRsyGay3ze7+0FZ+WqNoWSUL5yWrIWFDOQ4MAmk2bGzoxjirapRxEGF2ETEJK3EXIaEx3kvMpkjwTBJHSakQAd61hlQMqW+vXp670G5Nq6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022-07-17 11:32:32 +00:00
"metadata": {}
2022-06-29 17:55:23 +00:00
},
{
2022-07-11 17:19:06 +00:00
"output_type": "stream",
2022-07-17 11:32:32 +00:00
"name": "stdout",
2022-06-29 17:55:23 +00:00
"text": [
2022-07-17 11:32:32 +00:00
"CPU times: user 55 s, sys: 771 ms, total: 55.8 s\n",
"Wall time: 1min 3s\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",
"progressive_outputs = True #@param {type:\"boolean\"}\n",
2022-07-17 11:32:32 +00:00
"seamless = True #@param {type:\"boolean\"}\n",
"grid_size = 4 #@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 = 128 #@param {type:\"integer\"}\n",
2022-07-04 20:06:14 +00:00
"\n",
"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",
" progressive_outputs=progressive_outputs,\n",
2022-07-17 11:32:32 +00:00
" is_seamless=seamless,\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",
")\n",
"\n",
2022-07-05 02:52:00 +00:00
"is_first = True\n",
"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-17 11:32:32 +00:00
"provenance": [],
"include_colab_link": true
2022-06-28 00:58:17 +00:00
},
"gpuClass": "standard",
"kernelspec": {
"display_name": "Python 3.9.13 64-bit",
"language": "python",
2022-06-28 00:58:17 +00:00
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.9.13"
},
"vscode": {
"interpreter": {
"hash": "b0fa6594d8f4cbf19f97940f81e996739fb7646882a419484c72d19e05852a7e"
}
2022-06-28 00:58:17 +00:00
}
},
"nbformat": 4,
"nbformat_minor": 0
2022-07-17 11:32:32 +00:00
}