{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "bdc7e24f-7e12-409f-80df-f4f8d28b89fc", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Mon Aug 12 03:24:36 2024 \n", "+---------------------------------------------------------------------------------------+\n", "| NVIDIA-SMI 535.129.03 Driver Version: 535.129.03 CUDA Version: 12.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 NVIDIA A10 On | 00000000:07:00.0 Off | 0 |\n", "| 0% 38C P8 16W / 150W | 4MiB / 23028MiB | 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": [ "1sizels!nvidia-smi" ] }, { "cell_type": "code", "execution_count": 2, "id": "a3056eab-187c-43ef-ac90-6eb62a2f61e7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "fatal: destination path 'diffusers' already exists and is not an empty directory.\n" ] } ], "source": [ "!git clone https://github.com/huggingface/diffusers" ] }, { "cell_type": "code", "execution_count": 3, "id": "3911dd4d-2683-4ddf-924d-194f789c4293", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/home/ubuntu/diffusers\n" ] } ], "source": [ "cd diffusers" ] }, { "cell_type": "code", "execution_count": 4, "id": "819a4fd9-0d3d-401b-aa04-3c3b9b29b8c3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Defaulting to user installation because normal site-packages is not writeable\n", "Processing /home/ubuntu/diffusers\n", " Installing build dependencies ... \u001b[?25ldone\n", "\u001b[?25h Getting requirements to build wheel ... \u001b[?25ldone\n", "\u001b[?25h Preparing metadata (pyproject.toml) ... \u001b[?25ldone\n", "\u001b[?25hRequirement already satisfied: importlib-metadata in /usr/lib/python3/dist-packages (from diffusers==0.30.0.dev0) (4.6.4)\n", "Requirement already satisfied: filelock in /usr/lib/python3/dist-packages (from diffusers==0.30.0.dev0) (3.6.0)\n", "Requirement already satisfied: huggingface-hub>=0.23.2 in /home/ubuntu/.local/lib/python3.10/site-packages (from diffusers==0.30.0.dev0) (0.24.5)\n", "Requirement already satisfied: numpy in /home/ubuntu/.local/lib/python3.10/site-packages (from diffusers==0.30.0.dev0) (1.25.2)\n", "Requirement already satisfied: regex!=2019.12.17 in /home/ubuntu/.local/lib/python3.10/site-packages (from diffusers==0.30.0.dev0) (2024.7.24)\n", "Requirement already satisfied: requests in /home/ubuntu/.local/lib/python3.10/site-packages (from diffusers==0.30.0.dev0) (2.32.3)\n", "Requirement already satisfied: safetensors>=0.3.1 in /home/ubuntu/.local/lib/python3.10/site-packages (from diffusers==0.30.0.dev0) (0.4.4)\n", "Requirement already satisfied: Pillow in /usr/lib/python3/dist-packages (from diffusers==0.30.0.dev0) (9.0.1)\n", "Requirement already satisfied: fsspec>=2023.5.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from huggingface-hub>=0.23.2->diffusers==0.30.0.dev0) (2024.5.0)\n", "Requirement already satisfied: packaging>=20.9 in /usr/lib/python3/dist-packages (from huggingface-hub>=0.23.2->diffusers==0.30.0.dev0) (21.3)\n", "Requirement already satisfied: pyyaml>=5.1 in /usr/lib/python3/dist-packages (from huggingface-hub>=0.23.2->diffusers==0.30.0.dev0) (5.4.1)\n", "Requirement already satisfied: tqdm>=4.42.1 in /home/ubuntu/.local/lib/python3.10/site-packages (from huggingface-hub>=0.23.2->diffusers==0.30.0.dev0) (4.66.5)\n", "Requirement already satisfied: typing-extensions>=3.7.4.3 in /home/ubuntu/.local/lib/python3.10/site-packages (from huggingface-hub>=0.23.2->diffusers==0.30.0.dev0) (4.8.0)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /home/ubuntu/.local/lib/python3.10/site-packages (from requests->diffusers==0.30.0.dev0) (3.3.2)\n", "Requirement already satisfied: idna<4,>=2.5 in /usr/lib/python3/dist-packages (from requests->diffusers==0.30.0.dev0) (3.3)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/lib/python3/dist-packages (from requests->diffusers==0.30.0.dev0) (1.26.5)\n", "Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3/dist-packages (from requests->diffusers==0.30.0.dev0) (2020.6.20)\n", "Building wheels for collected packages: diffusers\n", " Building wheel for diffusers (pyproject.toml) ... \u001b[?25ldone\n", "\u001b[?25h Created wheel for diffusers: filename=diffusers-0.30.0.dev0-py3-none-any.whl size=2630249 sha256=0d6f8387133f101d08a3bb08f2645af12be07a96c25377af103ebb347d540a96\n", " Stored in directory: /tmp/pip-ephem-wheel-cache-h9wyufuh/wheels/81/55/09/065302f27e254e9ed451e13b5bf5b01397905ccc8b837312b6\n", "Successfully built diffusers\n", "\u001b[33mDEPRECATION: flatbuffers 1.12.1-git20200711.33e2d80-dfsg1-0.6 has a non-standard version number. pip 24.0 will enforce this behaviour change. A possible replacement is to upgrade to a newer version of flatbuffers or contact the author to suggest that they release a version with a conforming version number. Discussion can be found at https://github.com/pypa/pip/issues/12063\u001b[0m\u001b[33m\n", "\u001b[0mInstalling collected packages: diffusers\n", " Attempting uninstall: diffusers\n", " Found existing installation: diffusers 0.30.0.dev0\n", " Uninstalling diffusers-0.30.0.dev0:\n", " Successfully uninstalled diffusers-0.30.0.dev0\n", "Successfully installed diffusers-0.30.0.dev0\n", "\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython3 -m pip install --upgrade pip\u001b[0m\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "pip install ." ] }, { "cell_type": "code", "execution_count": 5, "id": "cfdc9ca8-858d-4383-81bf-5d30a88c1db6", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/home/ubuntu/diffusers/examples/text_to_image\n" ] } ], "source": [ "cd examples/text_to_image" ] }, { "cell_type": "code", "execution_count": 6, "id": "d6c0adca-b6e3-4ad2-b1d9-6eb0678aea4a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Defaulting to user installation because normal site-packages is not writeable\n", "Requirement already satisfied: accelerate>=0.16.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from -r requirements.txt (line 1)) (0.33.0)\n", "Requirement already satisfied: torchvision in /usr/lib/python3/dist-packages (from -r requirements.txt (line 2)) (0.15.2)\n", "Requirement already satisfied: transformers>=4.25.1 in /home/ubuntu/.local/lib/python3.10/site-packages (from -r requirements.txt (line 3)) (4.44.0)\n", "Requirement already satisfied: datasets>=2.19.1 in /home/ubuntu/.local/lib/python3.10/site-packages (from -r requirements.txt (line 4)) (2.20.0)\n", "Requirement already satisfied: ftfy in /home/ubuntu/.local/lib/python3.10/site-packages (from -r requirements.txt (line 5)) (6.2.3)\n", "Requirement already satisfied: tensorboard in /usr/lib/python3/dist-packages (from -r requirements.txt (line 6)) (2.13.0)\n", "Requirement already satisfied: Jinja2 in /usr/lib/python3/dist-packages (from -r requirements.txt (line 7)) (3.0.3)\n", "Requirement already satisfied: peft==0.7.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from -r requirements.txt (line 8)) (0.7.0)\n", "Requirement already satisfied: numpy>=1.17 in /home/ubuntu/.local/lib/python3.10/site-packages (from peft==0.7.0->-r requirements.txt (line 8)) (1.25.2)\n", "Requirement already satisfied: packaging>=20.0 in /usr/lib/python3/dist-packages (from peft==0.7.0->-r requirements.txt (line 8)) (21.3)\n", "Requirement already satisfied: psutil in /usr/lib/python3/dist-packages (from peft==0.7.0->-r requirements.txt (line 8)) (5.9.0)\n", "Requirement already satisfied: pyyaml in /usr/lib/python3/dist-packages (from peft==0.7.0->-r requirements.txt (line 8)) (5.4.1)\n", "Requirement already satisfied: torch>=1.13.0 in /usr/lib/python3/dist-packages (from peft==0.7.0->-r requirements.txt (line 8)) (2.0.1)\n", "Requirement already satisfied: tqdm in /home/ubuntu/.local/lib/python3.10/site-packages (from peft==0.7.0->-r requirements.txt (line 8)) (4.66.5)\n", "Requirement already satisfied: safetensors in /home/ubuntu/.local/lib/python3.10/site-packages (from peft==0.7.0->-r requirements.txt (line 8)) (0.4.4)\n", "Requirement already satisfied: huggingface-hub>=0.17.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from peft==0.7.0->-r requirements.txt (line 8)) (0.24.5)\n", "Requirement already satisfied: filelock in /usr/lib/python3/dist-packages (from transformers>=4.25.1->-r requirements.txt (line 3)) (3.6.0)\n", "Requirement already satisfied: regex!=2019.12.17 in /home/ubuntu/.local/lib/python3.10/site-packages (from transformers>=4.25.1->-r requirements.txt (line 3)) (2024.7.24)\n", "Requirement already satisfied: requests in /home/ubuntu/.local/lib/python3.10/site-packages (from transformers>=4.25.1->-r requirements.txt (line 3)) (2.32.3)\n", "Requirement already satisfied: tokenizers<0.20,>=0.19 in /home/ubuntu/.local/lib/python3.10/site-packages (from transformers>=4.25.1->-r requirements.txt (line 3)) (0.19.1)\n", "Requirement already satisfied: pyarrow>=15.0.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from datasets>=2.19.1->-r requirements.txt (line 4)) (17.0.0)\n", "Requirement already satisfied: pyarrow-hotfix in /home/ubuntu/.local/lib/python3.10/site-packages (from datasets>=2.19.1->-r requirements.txt (line 4)) (0.6)\n", "Requirement already satisfied: dill<0.3.9,>=0.3.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from datasets>=2.19.1->-r requirements.txt (line 4)) (0.3.8)\n", "Requirement already satisfied: pandas in /usr/lib/python3/dist-packages (from datasets>=2.19.1->-r requirements.txt (line 4)) (1.3.5)\n", "Requirement already satisfied: xxhash in /home/ubuntu/.local/lib/python3.10/site-packages (from datasets>=2.19.1->-r requirements.txt (line 4)) (3.4.1)\n", "Requirement already satisfied: multiprocess in /home/ubuntu/.local/lib/python3.10/site-packages (from datasets>=2.19.1->-r requirements.txt (line 4)) (0.70.16)\n", "Requirement already satisfied: fsspec<=2024.5.0,>=2023.1.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from fsspec[http]<=2024.5.0,>=2023.1.0->datasets>=2.19.1->-r requirements.txt (line 4)) (2024.5.0)\n", "Requirement already satisfied: aiohttp in /home/ubuntu/.local/lib/python3.10/site-packages (from datasets>=2.19.1->-r requirements.txt (line 4)) (3.10.3)\n", "Requirement already satisfied: wcwidth<0.3.0,>=0.2.12 in /home/ubuntu/.local/lib/python3.10/site-packages (from ftfy->-r requirements.txt (line 5)) (0.2.13)\n", "Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from aiohttp->datasets>=2.19.1->-r requirements.txt (line 4)) (2.3.5)\n", "Requirement already satisfied: aiosignal>=1.1.2 in /home/ubuntu/.local/lib/python3.10/site-packages (from aiohttp->datasets>=2.19.1->-r requirements.txt (line 4)) (1.3.1)\n", "Requirement already satisfied: attrs>=17.3.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from aiohttp->datasets>=2.19.1->-r requirements.txt (line 4)) (23.1.0)\n", "Requirement already satisfied: frozenlist>=1.1.1 in /home/ubuntu/.local/lib/python3.10/site-packages (from aiohttp->datasets>=2.19.1->-r requirements.txt (line 4)) (1.4.1)\n", "Requirement already satisfied: multidict<7.0,>=4.5 in /home/ubuntu/.local/lib/python3.10/site-packages (from aiohttp->datasets>=2.19.1->-r requirements.txt (line 4)) (6.0.5)\n", "Requirement already satisfied: yarl<2.0,>=1.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from aiohttp->datasets>=2.19.1->-r requirements.txt (line 4)) (1.9.4)\n", "Requirement already satisfied: async-timeout<5.0,>=4.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from aiohttp->datasets>=2.19.1->-r requirements.txt (line 4)) (4.0.3)\n", "Requirement already satisfied: typing-extensions>=3.7.4.3 in /home/ubuntu/.local/lib/python3.10/site-packages (from huggingface-hub>=0.17.0->peft==0.7.0->-r requirements.txt (line 8)) (4.8.0)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /home/ubuntu/.local/lib/python3.10/site-packages (from requests->transformers>=4.25.1->-r requirements.txt (line 3)) (3.3.2)\n", "Requirement already satisfied: idna<4,>=2.5 in /usr/lib/python3/dist-packages (from requests->transformers>=4.25.1->-r requirements.txt (line 3)) (3.3)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/lib/python3/dist-packages (from requests->transformers>=4.25.1->-r requirements.txt (line 3)) (1.26.5)\n", "Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3/dist-packages (from requests->transformers>=4.25.1->-r requirements.txt (line 3)) (2020.6.20)\n", "\u001b[33mDEPRECATION: flatbuffers 1.12.1-git20200711.33e2d80-dfsg1-0.6 has a non-standard version number. pip 24.0 will enforce this behaviour change. A possible replacement is to upgrade to a newer version of flatbuffers or contact the author to suggest that they release a version with a conforming version number. Discussion can be found at https://github.com/pypa/pip/issues/12063\u001b[0m\u001b[33m\n", "\u001b[0m\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython3 -m pip install --upgrade pip\u001b[0m\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "pip install -r requirements.txt" ] }, { "cell_type": "code", "execution_count": 9, "id": "587fc3f6-54ee-4baa-b1d3-6ae394307a60", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Configuration already exists at /home/ubuntu/.cache/huggingface/accelerate/default_config.yaml, will not override. Run `accelerate config` manually or pass a different `save_location`.\n" ] } ], "source": [ "!accelerate config default --mixed_precision=\"fp16\"" ] }, { "cell_type": "code", "execution_count": 16, "id": "1f956864-4d03-404b-a5f4-33474a9fdc7c", "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "os.environ[\"MODEL_NAME\"] = \"runwayml/stable-diffusion-v1-5\"\n", "os.environ[\"DATASET_NAME\"] = \"rohith2812/stability-finetune-datascience\"\n", "os.environ[\"OUTPUT_DIR\"] = \"sd-naruto-model\"" ] }, { "cell_type": "code", "execution_count": 52, "id": "81f19aa5-cb01-40fd-9c8f-a8dfa68008f8", "metadata": {}, "outputs": [], "source": [ "#checking the model before finetuning\n", "#asked to display some datascience related images and it generated an output which is not at all related to logistic regression" ] }, { "cell_type": "code", "execution_count": 47, "id": "cfcbb19e-9ef8-4172-9892-acd4cc391cd2", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "879d053e29fd422e9585daf92922f3b0", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/50 [00:00" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "image1 = pipe(prompt = \"A picture to understand logistic regression in data science\").images[0]\n", "image1.save(\"DSSample1.png\")\n", "\n", "\n", "def image_grid(imgs, rows, cols):\n", " assert len(imgs) == rows*cols\n", "\n", " w , h = imgs[0].size\n", " grid = Image.new('RGB' , size=(cols*w , rows*h))\n", " grid_w, grid_h = grid.size\n", "\n", " for i, img in enumerate(imgs):\n", " grid.paste(img,box = (i%cols*w , i//cols*h))\n", " return grid\n", "\n", "all_images = [image1]\n", "grid = image_grid(all_images,rows=1,cols=1)\n", "grid" ] }, { "cell_type": "code", "execution_count": 18, "id": "88a83f87-4f70-4702-ba07-0489ad31b23e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Defaulting to user installation because normal site-packages is not writeable\n", "Collecting xformers\n", " Downloading xformers-0.0.27.post2-cp310-cp310-manylinux2014_x86_64.whl.metadata (1.0 kB)\n", "Requirement already satisfied: numpy in /home/ubuntu/.local/lib/python3.10/site-packages (from xformers) (1.25.2)\n", "Collecting torch==2.4.0 (from xformers)\n", " Downloading torch-2.4.0-cp310-cp310-manylinux1_x86_64.whl.metadata (26 kB)\n", "Requirement already satisfied: filelock in /usr/lib/python3/dist-packages (from torch==2.4.0->xformers) (3.6.0)\n", "Requirement already satisfied: typing-extensions>=4.8.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch==2.4.0->xformers) (4.8.0)\n", "Requirement already satisfied: sympy in /usr/lib/python3/dist-packages (from torch==2.4.0->xformers) (1.9)\n", "Requirement already satisfied: networkx in /usr/lib/python3/dist-packages (from torch==2.4.0->xformers) (2.4)\n", "Requirement already satisfied: jinja2 in /usr/lib/python3/dist-packages (from torch==2.4.0->xformers) (3.0.3)\n", "Requirement already satisfied: fsspec in /home/ubuntu/.local/lib/python3.10/site-packages (from torch==2.4.0->xformers) (2024.5.0)\n", "Collecting nvidia-cuda-nvrtc-cu12==12.1.105 (from torch==2.4.0->xformers)\n", " Downloading nvidia_cuda_nvrtc_cu12-12.1.105-py3-none-manylinux1_x86_64.whl.metadata (1.5 kB)\n", "Collecting nvidia-cuda-runtime-cu12==12.1.105 (from torch==2.4.0->xformers)\n", " Downloading nvidia_cuda_runtime_cu12-12.1.105-py3-none-manylinux1_x86_64.whl.metadata (1.5 kB)\n", "Collecting nvidia-cuda-cupti-cu12==12.1.105 (from torch==2.4.0->xformers)\n", " Downloading nvidia_cuda_cupti_cu12-12.1.105-py3-none-manylinux1_x86_64.whl.metadata (1.6 kB)\n", "Collecting nvidia-cudnn-cu12==9.1.0.70 (from torch==2.4.0->xformers)\n", " Downloading nvidia_cudnn_cu12-9.1.0.70-py3-none-manylinux2014_x86_64.whl.metadata (1.6 kB)\n", "Collecting nvidia-cublas-cu12==12.1.3.1 (from torch==2.4.0->xformers)\n", " Downloading nvidia_cublas_cu12-12.1.3.1-py3-none-manylinux1_x86_64.whl.metadata (1.5 kB)\n", "Collecting nvidia-cufft-cu12==11.0.2.54 (from torch==2.4.0->xformers)\n", " Downloading nvidia_cufft_cu12-11.0.2.54-py3-none-manylinux1_x86_64.whl.metadata (1.5 kB)\n", "Collecting nvidia-curand-cu12==10.3.2.106 (from torch==2.4.0->xformers)\n", " Downloading nvidia_curand_cu12-10.3.2.106-py3-none-manylinux1_x86_64.whl.metadata (1.5 kB)\n", "Collecting nvidia-cusolver-cu12==11.4.5.107 (from torch==2.4.0->xformers)\n", " Downloading nvidia_cusolver_cu12-11.4.5.107-py3-none-manylinux1_x86_64.whl.metadata (1.6 kB)\n", "Collecting nvidia-cusparse-cu12==12.1.0.106 (from torch==2.4.0->xformers)\n", " Downloading nvidia_cusparse_cu12-12.1.0.106-py3-none-manylinux1_x86_64.whl.metadata (1.6 kB)\n", "Collecting nvidia-nccl-cu12==2.20.5 (from torch==2.4.0->xformers)\n", " Downloading nvidia_nccl_cu12-2.20.5-py3-none-manylinux2014_x86_64.whl.metadata (1.8 kB)\n", "Collecting nvidia-nvtx-cu12==12.1.105 (from torch==2.4.0->xformers)\n", " Downloading nvidia_nvtx_cu12-12.1.105-py3-none-manylinux1_x86_64.whl.metadata (1.7 kB)\n", "Collecting triton==3.0.0 (from torch==2.4.0->xformers)\n", " Downloading triton-3.0.0-1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.metadata (1.3 kB)\n", "Collecting nvidia-nvjitlink-cu12 (from nvidia-cusolver-cu12==11.4.5.107->torch==2.4.0->xformers)\n", " Downloading nvidia_nvjitlink_cu12-12.6.20-py3-none-manylinux2014_x86_64.whl.metadata (1.5 kB)\n", "Downloading xformers-0.0.27.post2-cp310-cp310-manylinux2014_x86_64.whl (20.8 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m20.8/20.8 MB\u001b[0m \u001b[31m186.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m0:01\u001b[0m\n", "\u001b[?25hDownloading torch-2.4.0-cp310-cp310-manylinux1_x86_64.whl (797.2 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m797.2/797.2 MB\u001b[0m \u001b[31m11.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hDownloading nvidia_cublas_cu12-12.1.3.1-py3-none-manylinux1_x86_64.whl (410.6 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m410.6/410.6 MB\u001b[0m \u001b[31m21.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hDownloading nvidia_cuda_cupti_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (14.1 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m14.1/14.1 MB\u001b[0m \u001b[31m171.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m0:01\u001b[0m\n", "\u001b[?25hDownloading nvidia_cuda_nvrtc_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (23.7 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m23.7/23.7 MB\u001b[0m \u001b[31m124.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hDownloading nvidia_cuda_runtime_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (823 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m823.6/823.6 kB\u001b[0m \u001b[31m41.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading nvidia_cudnn_cu12-9.1.0.70-py3-none-manylinux2014_x86_64.whl (664.8 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m664.8/664.8 MB\u001b[0m \u001b[31m13.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hDownloading nvidia_cufft_cu12-11.0.2.54-py3-none-manylinux1_x86_64.whl (121.6 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m121.6/121.6 MB\u001b[0m \u001b[31m53.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hDownloading nvidia_curand_cu12-10.3.2.106-py3-none-manylinux1_x86_64.whl (56.5 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m56.5/56.5 MB\u001b[0m \u001b[31m89.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hDownloading nvidia_cusolver_cu12-11.4.5.107-py3-none-manylinux1_x86_64.whl (124.2 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m124.2/124.2 MB\u001b[0m \u001b[31m50.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hDownloading nvidia_cusparse_cu12-12.1.0.106-py3-none-manylinux1_x86_64.whl (196.0 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m196.0/196.0 MB\u001b[0m \u001b[31m36.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hDownloading nvidia_nccl_cu12-2.20.5-py3-none-manylinux2014_x86_64.whl (176.2 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m176.2/176.2 MB\u001b[0m \u001b[31m38.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hDownloading nvidia_nvtx_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (99 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m99.1/99.1 kB\u001b[0m \u001b[31m18.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading triton-3.0.0-1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (209.4 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m209.4/209.4 MB\u001b[0m \u001b[31m35.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hDownloading nvidia_nvjitlink_cu12-12.6.20-py3-none-manylinux2014_x86_64.whl (19.7 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m19.7/19.7 MB\u001b[0m \u001b[31m150.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25h\u001b[33mDEPRECATION: flatbuffers 1.12.1-git20200711.33e2d80-dfsg1-0.6 has a non-standard version number. pip 24.0 will enforce this behaviour change. A possible replacement is to upgrade to a newer version of flatbuffers or contact the author to suggest that they release a version with a conforming version number. Discussion can be found at https://github.com/pypa/pip/issues/12063\u001b[0m\u001b[33m\n", "\u001b[0mInstalling collected packages: triton, nvidia-nvtx-cu12, nvidia-nvjitlink-cu12, nvidia-nccl-cu12, nvidia-curand-cu12, nvidia-cufft-cu12, nvidia-cuda-runtime-cu12, nvidia-cuda-nvrtc-cu12, nvidia-cuda-cupti-cu12, nvidia-cublas-cu12, nvidia-cusparse-cu12, nvidia-cudnn-cu12, nvidia-cusolver-cu12, torch, xformers\n", "Successfully installed nvidia-cublas-cu12-12.1.3.1 nvidia-cuda-cupti-cu12-12.1.105 nvidia-cuda-nvrtc-cu12-12.1.105 nvidia-cuda-runtime-cu12-12.1.105 nvidia-cudnn-cu12-9.1.0.70 nvidia-cufft-cu12-11.0.2.54 nvidia-curand-cu12-10.3.2.106 nvidia-cusolver-cu12-11.4.5.107 nvidia-cusparse-cu12-12.1.0.106 nvidia-nccl-cu12-2.20.5 nvidia-nvjitlink-cu12-12.6.20 nvidia-nvtx-cu12-12.1.105 torch-2.4.0 triton-3.0.0 xformers-0.0.27.post2\n", "\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython3 -m pip install --upgrade pip\u001b[0m\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "pip install xformers" ] }, { "cell_type": "code", "execution_count": 19, "id": "f17b15c4-4ab9-409d-9ee2-c338e2912aa6", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/usr/lib/python3/dist-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: '/usr/lib/python3/dist-packages/torchvision/image.so: undefined symbol: _ZN3c1017RegisterOperatorsD1Ev'If you don't plan on using image functionality from `torchvision.io`, you can ignore this warning. Otherwise, there might be something wrong with your environment. Did you have `libjpeg` or `libpng` installed before building `torchvision` from source?\n", " warn(\n", "/usr/lib/python3/dist-packages/scipy/__init__.py:146: UserWarning: A NumPy version >=1.17.3 and <1.25.0 is required for this version of SciPy (detected version 1.25.2\n", " warnings.warn(f\"A NumPy version >={np_minversion} and <{np_maxversion}\"\n", "/home/ubuntu/.local/lib/python3.10/site-packages/xformers/ops/fmha/flash.py:211: FutureWarning: `torch.library.impl_abstract` was renamed to `torch.library.register_fake`. Please use that instead; we will remove `torch.library.impl_abstract` in a future version of PyTorch.\n", " @torch.library.impl_abstract(\"xformers_flash::flash_fwd\")\n", "/home/ubuntu/.local/lib/python3.10/site-packages/xformers/ops/fmha/flash.py:344: FutureWarning: `torch.library.impl_abstract` was renamed to `torch.library.register_fake`. Please use that instead; we will remove `torch.library.impl_abstract` in a future version of PyTorch.\n", " @torch.library.impl_abstract(\"xformers_flash::flash_bwd\")\n", "2024-08-12 03:40:48.423227: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.\n", "2024-08-12 03:40:48.465032: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n", "To enable the following instructions: AVX512F AVX512_VNNI, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n", "/home/ubuntu/.local/lib/python3.10/site-packages/accelerate/accelerator.py:488: FutureWarning: `torch.cuda.amp.GradScaler(args...)` is deprecated. Please use `torch.amp.GradScaler('cuda', args...)` instead.\n", " self.scaler = torch.cuda.amp.GradScaler(**kwargs)\n", "08/12/2024 03:40:49 - INFO - __main__ - Distributed environment: NO\n", "Num processes: 1\n", "Process index: 0\n", "Local process index: 0\n", "Device: cuda\n", "\n", "Mixed precision type: fp16\n", "\n", "{'thresholding', 'dynamic_thresholding_ratio', 'rescale_betas_zero_snr', 'sample_max_value', 'clip_sample_range', 'variance_type', 'prediction_type', 'timestep_spacing'} was not found in config. Values will be initialized to default values.\n", "/home/ubuntu/.local/lib/python3.10/site-packages/transformers/tokenization_utils_base.py:1601: FutureWarning: `clean_up_tokenization_spaces` was not set. It will be set to `True` by default. This behavior will be depracted in transformers v4.45, and will be then set to `False` by default. For more details check this issue: https://github.com/huggingface/transformers/issues/31884\n", " warnings.warn(\n", "{'scaling_factor', 'shift_factor', 'use_quant_conv', 'mid_block_add_attention', 'latents_mean', 'use_post_quant_conv', 'latents_std', 'force_upcast'} was not found in config. Values will be initialized to default values.\n", "{'dual_cross_attention', 'class_embed_type', 'class_embeddings_concat', 'timestep_post_act', 'time_embedding_dim', 'time_cond_proj_dim', 'resnet_time_scale_shift', 'attention_type', 'conv_out_kernel', 'use_linear_projection', 'mid_block_only_cross_attention', 'cross_attention_norm', 'resnet_out_scale_factor', 'time_embedding_act_fn', 'resnet_skip_time_act', 'num_class_embeds', 'addition_embed_type_num_heads', 'encoder_hid_dim_type', 'addition_embed_type', 'addition_time_embed_dim', 'num_attention_heads', 'transformer_layers_per_block', 'upcast_attention', 'conv_in_kernel', 'encoder_hid_dim', 'dropout', 'reverse_transformer_layers_per_block', 'time_embedding_type', 'projection_class_embeddings_input_dim', 'only_cross_attention', 'mid_block_type'} was not found in config. Values will be initialized to default values.\n", "{'dual_cross_attention', 'class_embed_type', 'class_embeddings_concat', 'timestep_post_act', 'time_embedding_dim', 'time_cond_proj_dim', 'resnet_time_scale_shift', 'attention_type', 'conv_out_kernel', 'use_linear_projection', 'mid_block_only_cross_attention', 'cross_attention_norm', 'resnet_out_scale_factor', 'time_embedding_act_fn', 'resnet_skip_time_act', 'num_class_embeds', 'addition_embed_type_num_heads', 'encoder_hid_dim_type', 'addition_embed_type', 'addition_time_embed_dim', 'num_attention_heads', 'transformer_layers_per_block', 'upcast_attention', 'conv_in_kernel', 'encoder_hid_dim', 'dropout', 'reverse_transformer_layers_per_block', 'time_embedding_type', 'projection_class_embeddings_input_dim', 'only_cross_attention', 'mid_block_type'} was not found in config. Values will be initialized to default values.\n", "Downloading readme: 100%|██████████████████| 1.02k/1.02k [00:00<00:00, 8.93MB/s]\n", "Repo card metadata block was not found. Setting CardData to empty.\n", "08/12/2024 03:40:53 - WARNING - huggingface_hub.repocard - Repo card metadata block was not found. Setting CardData to empty.\n", "Downloading metadata: 100%|████████████████████| 897/897 [00:00<00:00, 8.53MB/s]\n", "Downloading data: 100%|██████████████████████| 344M/344M [00:03<00:00, 91.9MB/s]\n", "Downloading data: 100%|██████████████████████| 357M/357M [00:03<00:00, 96.6MB/s]\n", "Generating train split: 100%|███████| 1221/1221 [00:01<00:00, 639.81 examples/s]\n", "08/12/2024 03:41:05 - INFO - __main__ - ***** Running training *****\n", "08/12/2024 03:41:05 - INFO - __main__ - Num examples = 1221\n", "08/12/2024 03:41:05 - INFO - __main__ - Num Epochs = 2\n", "08/12/2024 03:41:05 - INFO - __main__ - Instantaneous batch size per device = 1\n", "08/12/2024 03:41:05 - INFO - __main__ - Total train batch size (w. parallel, distributed & accumulation) = 4\n", "08/12/2024 03:41:05 - INFO - __main__ - Gradient Accumulation steps = 4\n", "08/12/2024 03:41:05 - INFO - __main__ - Total optimization steps = 400\n", "Steps: 0%| | 0/400 [00:00\n", " main()\n", " File \"/home/ubuntu/diffusers/examples/text_to_image/train_text_to_image.py\", line 949, in main\n", " for step, batch in enumerate(train_dataloader):\n", " File \"/home/ubuntu/.local/lib/python3.10/site-packages/accelerate/data_loader.py\", line 454, in __iter__\n", " current_batch = next(dataloader_iter)\n", " File \"/home/ubuntu/.local/lib/python3.10/site-packages/torch/utils/data/dataloader.py\", line 630, in __next__\n", " data = self._next_data()\n", " File \"/home/ubuntu/.local/lib/python3.10/site-packages/torch/utils/data/dataloader.py\", line 673, in _next_data\n", " data = self._dataset_fetcher.fetch(index) # may raise StopIteration\n", " File \"/home/ubuntu/.local/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py\", line 50, in fetch\n", " data = self.dataset.__getitems__(possibly_batched_index)\n", " File \"/home/ubuntu/.local/lib/python3.10/site-packages/datasets/arrow_dataset.py\", line 2870, in __getitems__\n", " batch = self.__getitem__(keys)\n", " File \"/home/ubuntu/.local/lib/python3.10/site-packages/datasets/arrow_dataset.py\", line 2866, in __getitem__\n", " return self._getitem(key)\n", " File \"/home/ubuntu/.local/lib/python3.10/site-packages/datasets/arrow_dataset.py\", line 2851, in _getitem\n", " formatted_output = format_table(\n", " File \"/home/ubuntu/.local/lib/python3.10/site-packages/datasets/formatting/formatting.py\", line 633, in format_table\n", " return formatter(pa_table, query_type=query_type)\n", " File \"/home/ubuntu/.local/lib/python3.10/site-packages/datasets/formatting/formatting.py\", line 401, in __call__\n", " return self.format_batch(pa_table)\n", " File \"/home/ubuntu/.local/lib/python3.10/site-packages/datasets/formatting/formatting.py\", line 515, in format_batch\n", " batch = self.python_features_decoder.decode_batch(batch)\n", " File \"/home/ubuntu/.local/lib/python3.10/site-packages/datasets/formatting/formatting.py\", line 222, in decode_batch\n", " return self.features.decode_batch(batch) if self.features else batch\n", " File \"/home/ubuntu/.local/lib/python3.10/site-packages/datasets/features/features.py\", line 2029, in decode_batch\n", " [\n", " File \"/home/ubuntu/.local/lib/python3.10/site-packages/datasets/features/features.py\", line 2030, in \n", " decode_nested_example(self[column_name], value, token_per_repo_id=token_per_repo_id)\n", " File \"/home/ubuntu/.local/lib/python3.10/site-packages/datasets/features/features.py\", line 1351, in decode_nested_example\n", " return schema.decode_example(obj, token_per_repo_id=token_per_repo_id)\n", " File \"/home/ubuntu/.local/lib/python3.10/site-packages/datasets/features/image.py\", line 189, in decode_example\n", " if image.getexif().get(PIL.Image.ExifTags.Base.Orientation) is not None:\n", " File \"/usr/lib/python3/dist-packages/PIL/Image.py\", line 65, in __getattr__\n", " raise AttributeError(f\"module '{__name__}' has no attribute '{name}'\")\n", "AttributeError: module 'PIL.Image' has no attribute 'ExifTags'. Did you mean: 'TiffTags'?\n", "Steps: 0%| | 0/400 [00:00\n", " sys.exit(main())\n", " File \"/home/ubuntu/.local/lib/python3.10/site-packages/accelerate/commands/accelerate_cli.py\", line 48, in main\n", " args.func(args)\n", " File \"/home/ubuntu/.local/lib/python3.10/site-packages/accelerate/commands/launch.py\", line 1106, in launch_command\n", " simple_launcher(args)\n", " File \"/home/ubuntu/.local/lib/python3.10/site-packages/accelerate/commands/launch.py\", line 704, in simple_launcher\n", " raise subprocess.CalledProcessError(returncode=process.returncode, cmd=cmd)\n", "subprocess.CalledProcessError: Command '['/usr/bin/python3', 'train_text_to_image.py', '--pretrained_model_name_or_path=runwayml/stable-diffusion-v1-5', '--dataset_name=lambdalabs/naruto-blip-captions', '--use_ema', '--resolution=512', '--center_crop', '--random_flip', '--train_batch_size=1', '--gradient_accumulation_steps=4', '--gradient_checkpointing', '--max_train_steps=400', '--learning_rate=1e-05', '--max_grad_norm=1', '--enable_xformers_memory_efficient_attention', '--lr_scheduler=constant', '--lr_warmup_steps=0', '--output_dir=sd-naruto-model', '--push_to_hub']' returned non-zero exit status 1.\n" ] } ], "source": [ "!accelerate launch --mixed_precision=\"fp16\" train_text_to_image.py \\\n", " --pretrained_model_name_or_path=$MODEL_NAME \\\n", " --dataset_name=$DATASET_NAME \\\n", " --use_ema \\\n", " --resolution=512 --center_crop --random_flip \\\n", " --train_batch_size=1 \\\n", " --gradient_accumulation_steps=4 \\\n", " --gradient_checkpointing \\\n", " --max_train_steps=400 \\\n", " --learning_rate=1e-05 \\\n", " --max_grad_norm=1 \\\n", " --enable_xformers_memory_efficient_attention \\\n", " --lr_scheduler=\"constant\" --lr_warmup_steps=0 \\\n", " --output_dir=$OUTPUT_DIR \\\n", " --push_to_hub" ] }, { "cell_type": "code", "execution_count": 20, "id": "db12d5f5-905c-40c5-bc89-00980eff446c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Defaulting to user installation because normal site-packages is not writeable\n", "Requirement already satisfied: Pillow in /usr/lib/python3/dist-packages (9.0.1)\n", "Collecting Pillow\n", " Downloading pillow-10.4.0-cp310-cp310-manylinux_2_28_x86_64.whl.metadata (9.2 kB)\n", "Downloading pillow-10.4.0-cp310-cp310-manylinux_2_28_x86_64.whl (4.5 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m4.5/4.5 MB\u001b[0m \u001b[31m84.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n", "\u001b[?25h\u001b[33mDEPRECATION: flatbuffers 1.12.1-git20200711.33e2d80-dfsg1-0.6 has a non-standard version number. pip 24.0 will enforce this behaviour change. A possible replacement is to upgrade to a newer version of flatbuffers or contact the author to suggest that they release a version with a conforming version number. Discussion can be found at https://github.com/pypa/pip/issues/12063\u001b[0m\u001b[33m\n", "\u001b[0mInstalling collected packages: Pillow\n", "Successfully installed Pillow-10.4.0\n", "\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython3 -m pip install --upgrade pip\u001b[0m\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "pip install --upgrade Pillow\n" ] }, { "cell_type": "code", "execution_count": 21, "id": "e04fdefc-f832-4b8e-9fec-26430f264209", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Defaulting to user installation because normal site-packages is not writeable\n", "Requirement already satisfied: torchvision in /usr/lib/python3/dist-packages (0.15.2)\n", "Collecting torchvision\n", " Downloading torchvision-0.19.0-cp310-cp310-manylinux1_x86_64.whl.metadata (6.0 kB)\n", "Requirement already satisfied: numpy in /home/ubuntu/.local/lib/python3.10/site-packages (from torchvision) (1.25.2)\n", "Requirement already satisfied: torch==2.4.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from torchvision) (2.4.0)\n", "Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from torchvision) (10.4.0)\n", "Requirement already satisfied: filelock in /usr/lib/python3/dist-packages (from torch==2.4.0->torchvision) (3.6.0)\n", "Requirement already satisfied: typing-extensions>=4.8.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch==2.4.0->torchvision) (4.8.0)\n", "Requirement already satisfied: sympy in /usr/lib/python3/dist-packages (from torch==2.4.0->torchvision) (1.9)\n", "Requirement already satisfied: networkx in /usr/lib/python3/dist-packages (from torch==2.4.0->torchvision) (2.4)\n", "Requirement already satisfied: jinja2 in /usr/lib/python3/dist-packages (from torch==2.4.0->torchvision) (3.0.3)\n", "Requirement already satisfied: fsspec in /home/ubuntu/.local/lib/python3.10/site-packages (from torch==2.4.0->torchvision) (2024.5.0)\n", "Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.1.105 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch==2.4.0->torchvision) (12.1.105)\n", "Requirement already satisfied: nvidia-cuda-runtime-cu12==12.1.105 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch==2.4.0->torchvision) (12.1.105)\n", "Requirement already satisfied: nvidia-cuda-cupti-cu12==12.1.105 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch==2.4.0->torchvision) (12.1.105)\n", "Requirement already satisfied: nvidia-cudnn-cu12==9.1.0.70 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch==2.4.0->torchvision) (9.1.0.70)\n", "Requirement already satisfied: nvidia-cublas-cu12==12.1.3.1 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch==2.4.0->torchvision) (12.1.3.1)\n", "Requirement already satisfied: nvidia-cufft-cu12==11.0.2.54 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch==2.4.0->torchvision) (11.0.2.54)\n", "Requirement already satisfied: nvidia-curand-cu12==10.3.2.106 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch==2.4.0->torchvision) (10.3.2.106)\n", "Requirement already satisfied: nvidia-cusolver-cu12==11.4.5.107 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch==2.4.0->torchvision) (11.4.5.107)\n", "Requirement already satisfied: nvidia-cusparse-cu12==12.1.0.106 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch==2.4.0->torchvision) (12.1.0.106)\n", "Requirement already satisfied: nvidia-nccl-cu12==2.20.5 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch==2.4.0->torchvision) (2.20.5)\n", "Requirement already satisfied: nvidia-nvtx-cu12==12.1.105 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch==2.4.0->torchvision) (12.1.105)\n", "Requirement already satisfied: triton==3.0.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch==2.4.0->torchvision) (3.0.0)\n", "Requirement already satisfied: nvidia-nvjitlink-cu12 in /home/ubuntu/.local/lib/python3.10/site-packages (from nvidia-cusolver-cu12==11.4.5.107->torch==2.4.0->torchvision) (12.6.20)\n", "Downloading torchvision-0.19.0-cp310-cp310-manylinux1_x86_64.whl (7.0 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m7.0/7.0 MB\u001b[0m \u001b[31m113.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m \u001b[36m0:00:01\u001b[0m\n", "\u001b[?25h\u001b[33mDEPRECATION: flatbuffers 1.12.1-git20200711.33e2d80-dfsg1-0.6 has a non-standard version number. pip 24.0 will enforce this behaviour change. A possible replacement is to upgrade to a newer version of flatbuffers or contact the author to suggest that they release a version with a conforming version number. Discussion can be found at https://github.com/pypa/pip/issues/12063\u001b[0m\u001b[33m\n", "\u001b[0mInstalling collected packages: torchvision\n", "Successfully installed torchvision-0.19.0\n", "\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython3 -m pip install --upgrade pip\u001b[0m\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "pip install --upgrade torchvision\n" ] }, { "cell_type": "code", "execution_count": 22, "id": "1e689648-42d0-4f8e-9fb9-fca175d00072", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Defaulting to user installation because normal site-packages is not writeable\n", "Collecting numpy==1.24.3\n", " Downloading numpy-1.24.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (5.6 kB)\n", "Downloading numpy-1.24.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.3 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m17.3/17.3 MB\u001b[0m \u001b[31m150.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25h\u001b[33mDEPRECATION: flatbuffers 1.12.1-git20200711.33e2d80-dfsg1-0.6 has a non-standard version number. pip 24.0 will enforce this behaviour change. A possible replacement is to upgrade to a newer version of flatbuffers or contact the author to suggest that they release a version with a conforming version number. Discussion can be found at https://github.com/pypa/pip/issues/12063\u001b[0m\u001b[33m\n", "\u001b[0mInstalling collected packages: numpy\n", " Attempting uninstall: numpy\n", " Found existing installation: numpy 1.25.2\n", " Uninstalling numpy-1.25.2:\n", " Successfully uninstalled numpy-1.25.2\n", "Successfully installed numpy-1.24.3\n", "\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython3 -m pip install --upgrade pip\u001b[0m\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "pip install numpy==1.24.3\n" ] }, { "cell_type": "code", "execution_count": 23, "id": "091255da-aa3a-4841-9450-1bad0a9ef912", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Defaulting to user installation because normal site-packages is not writeable\n", "Requirement already satisfied: torch in /home/ubuntu/.local/lib/python3.10/site-packages (2.4.0)\n", "Requirement already satisfied: filelock in /usr/lib/python3/dist-packages (from torch) (3.6.0)\n", "Requirement already satisfied: typing-extensions>=4.8.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch) (4.8.0)\n", "Requirement already satisfied: sympy in /usr/lib/python3/dist-packages (from torch) (1.9)\n", "Requirement already satisfied: networkx in /usr/lib/python3/dist-packages (from torch) (2.4)\n", "Requirement already satisfied: jinja2 in /usr/lib/python3/dist-packages (from torch) (3.0.3)\n", "Requirement already satisfied: fsspec in /home/ubuntu/.local/lib/python3.10/site-packages (from torch) (2024.5.0)\n", "Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.1.105 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch) (12.1.105)\n", "Requirement already satisfied: nvidia-cuda-runtime-cu12==12.1.105 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch) (12.1.105)\n", "Requirement already satisfied: nvidia-cuda-cupti-cu12==12.1.105 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch) (12.1.105)\n", "Requirement already satisfied: nvidia-cudnn-cu12==9.1.0.70 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch) (9.1.0.70)\n", "Requirement already satisfied: nvidia-cublas-cu12==12.1.3.1 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch) (12.1.3.1)\n", "Requirement already satisfied: nvidia-cufft-cu12==11.0.2.54 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch) (11.0.2.54)\n", "Requirement already satisfied: nvidia-curand-cu12==10.3.2.106 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch) (10.3.2.106)\n", "Requirement already satisfied: nvidia-cusolver-cu12==11.4.5.107 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch) (11.4.5.107)\n", "Requirement already satisfied: nvidia-cusparse-cu12==12.1.0.106 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch) (12.1.0.106)\n", "Requirement already satisfied: nvidia-nccl-cu12==2.20.5 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch) (2.20.5)\n", "Requirement already satisfied: nvidia-nvtx-cu12==12.1.105 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch) (12.1.105)\n", "Requirement already satisfied: triton==3.0.0 in /home/ubuntu/.local/lib/python3.10/site-packages (from torch) (3.0.0)\n", "Requirement already satisfied: nvidia-nvjitlink-cu12 in /home/ubuntu/.local/lib/python3.10/site-packages (from nvidia-cusolver-cu12==11.4.5.107->torch) (12.6.20)\n", "\u001b[33mDEPRECATION: flatbuffers 1.12.1-git20200711.33e2d80-dfsg1-0.6 has a non-standard version number. pip 24.0 will enforce this behaviour change. A possible replacement is to upgrade to a newer version of flatbuffers or contact the author to suggest that they release a version with a conforming version number. Discussion can be found at https://github.com/pypa/pip/issues/12063\u001b[0m\u001b[33m\n", "\u001b[0m\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython3 -m pip install --upgrade pip\u001b[0m\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "pip install --upgrade torch\n" ] }, { "cell_type": "code", "execution_count": 51, "id": "c91fcd06-3942-451c-b1b3-7cb65d695ae8", "metadata": {}, "outputs": [], "source": [ "#Fine-tuning the model with the below parameters" ] }, { "cell_type": "code", "execution_count": 24, "id": "4d61a6cb-900d-4fec-bfbb-01cbf4e537e0", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/home/ubuntu/.local/lib/python3.10/site-packages/xformers/ops/fmha/flash.py:211: FutureWarning: `torch.library.impl_abstract` was renamed to `torch.library.register_fake`. Please use that instead; we will remove `torch.library.impl_abstract` in a future version of PyTorch.\n", " @torch.library.impl_abstract(\"xformers_flash::flash_fwd\")\n", "/home/ubuntu/.local/lib/python3.10/site-packages/xformers/ops/fmha/flash.py:344: FutureWarning: `torch.library.impl_abstract` was renamed to `torch.library.register_fake`. Please use that instead; we will remove `torch.library.impl_abstract` in a future version of PyTorch.\n", " @torch.library.impl_abstract(\"xformers_flash::flash_bwd\")\n", "2024-08-12 03:43:02.380276: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.\n", "2024-08-12 03:43:02.422698: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n", "To enable the following instructions: AVX512F AVX512_VNNI, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n", "/home/ubuntu/.local/lib/python3.10/site-packages/accelerate/accelerator.py:488: FutureWarning: `torch.cuda.amp.GradScaler(args...)` is deprecated. Please use `torch.amp.GradScaler('cuda', args...)` instead.\n", " self.scaler = torch.cuda.amp.GradScaler(**kwargs)\n", "08/12/2024 03:43:03 - INFO - __main__ - Distributed environment: NO\n", "Num processes: 1\n", "Process index: 0\n", "Local process index: 0\n", "Device: cuda\n", "\n", "Mixed precision type: fp16\n", "\n", "{'rescale_betas_zero_snr', 'prediction_type', 'dynamic_thresholding_ratio', 'variance_type', 'timestep_spacing', 'clip_sample_range', 'sample_max_value', 'thresholding'} was not found in config. Values will be initialized to default values.\n", "/home/ubuntu/.local/lib/python3.10/site-packages/transformers/tokenization_utils_base.py:1601: FutureWarning: `clean_up_tokenization_spaces` was not set. It will be set to `True` by default. This behavior will be depracted in transformers v4.45, and will be then set to `False` by default. For more details check this issue: https://github.com/huggingface/transformers/issues/31884\n", " warnings.warn(\n", "{'use_post_quant_conv', 'force_upcast', 'mid_block_add_attention', 'use_quant_conv', 'scaling_factor', 'shift_factor', 'latents_std', 'latents_mean'} was not found in config. Values will be initialized to default values.\n", "{'reverse_transformer_layers_per_block', 'encoder_hid_dim_type', 'projection_class_embeddings_input_dim', 'attention_type', 'addition_embed_type_num_heads', 'upcast_attention', 'dropout', 'num_class_embeds', 'time_embedding_dim', 'addition_embed_type', 'addition_time_embed_dim', 'mid_block_only_cross_attention', 'mid_block_type', 'transformer_layers_per_block', 'time_embedding_type', 'encoder_hid_dim', 'resnet_out_scale_factor', 'timestep_post_act', 'resnet_time_scale_shift', 'time_embedding_act_fn', 'conv_in_kernel', 'class_embed_type', 'class_embeddings_concat', 'use_linear_projection', 'resnet_skip_time_act', 'dual_cross_attention', 'num_attention_heads', 'time_cond_proj_dim', 'cross_attention_norm', 'conv_out_kernel', 'only_cross_attention'} was not found in config. Values will be initialized to default values.\n", "{'reverse_transformer_layers_per_block', 'encoder_hid_dim_type', 'projection_class_embeddings_input_dim', 'attention_type', 'addition_embed_type_num_heads', 'upcast_attention', 'dropout', 'num_class_embeds', 'time_embedding_dim', 'addition_embed_type', 'addition_time_embed_dim', 'mid_block_only_cross_attention', 'mid_block_type', 'transformer_layers_per_block', 'time_embedding_type', 'encoder_hid_dim', 'resnet_out_scale_factor', 'timestep_post_act', 'resnet_time_scale_shift', 'time_embedding_act_fn', 'conv_in_kernel', 'class_embed_type', 'class_embeddings_concat', 'use_linear_projection', 'resnet_skip_time_act', 'dual_cross_attention', 'num_attention_heads', 'time_cond_proj_dim', 'cross_attention_norm', 'conv_out_kernel', 'only_cross_attention'} was not found in config. Values will be initialized to default values.\n", "Repo card metadata block was not found. Setting CardData to empty.\n", "08/12/2024 03:43:06 - WARNING - huggingface_hub.repocard - Repo card metadata block was not found. Setting CardData to empty.\n", "08/12/2024 03:43:09 - INFO - __main__ - ***** Running training *****\n", "08/12/2024 03:43:09 - INFO - __main__ - Num examples = 1221\n", "08/12/2024 03:43:09 - INFO - __main__ - Num Epochs = 2\n", "08/12/2024 03:43:09 - INFO - __main__ - Instantaneous batch size per device = 1\n", "08/12/2024 03:43:09 - INFO - __main__ - Total train batch size (w. parallel, distributed & accumulation) = 4\n", "08/12/2024 03:43:09 - INFO - __main__ - Gradient Accumulation steps = 4\n", "08/12/2024 03:43:09 - INFO - __main__ - Total optimization steps = 400\n", "Steps: 0%| | 0/400 [00:00\n", " main()\n", " File \"/home/ubuntu/diffusers/examples/text_to_image/train_text_to_image.py\", line 1141, in main\n", " save_model_card(args, repo_id, images, repo_folder=args.output_dir)\n", " File \"/home/ubuntu/diffusers/examples/text_to_image/train_text_to_image.py\", line 96, in save_model_card\n", " prompt = \"{args.validation_prompts[0]}\"\n", "TypeError: 'NoneType' object is not subscriptable\n", "Steps: 100%|██████| 400/400 [09:07<00:00, 1.37s/it, lr=1e-5, step_loss=0.00541]\n", "Traceback (most recent call last):\n", " File \"/home/ubuntu/.local/bin/accelerate\", line 8, in \n", " sys.exit(main())\n", " File \"/home/ubuntu/.local/lib/python3.10/site-packages/accelerate/commands/accelerate_cli.py\", line 48, in main\n", " args.func(args)\n", " File \"/home/ubuntu/.local/lib/python3.10/site-packages/accelerate/commands/launch.py\", line 1106, in launch_command\n", " simple_launcher(args)\n", " File \"/home/ubuntu/.local/lib/python3.10/site-packages/accelerate/commands/launch.py\", line 704, in simple_launcher\n", " raise subprocess.CalledProcessError(returncode=process.returncode, cmd=cmd)\n", "subprocess.CalledProcessError: Command '['/usr/bin/python3', 'train_text_to_image.py', '--pretrained_model_name_or_path=runwayml/stable-diffusion-v1-5', '--dataset_name=lambdalabs/naruto-blip-captions', '--use_ema', '--resolution=512', '--center_crop', '--random_flip', '--train_batch_size=1', '--gradient_accumulation_steps=4', '--gradient_checkpointing', '--max_train_steps=400', '--learning_rate=1e-05', '--max_grad_norm=1', '--enable_xformers_memory_efficient_attention', '--lr_scheduler=constant', '--lr_warmup_steps=0', '--output_dir=sd-naruto-model', '--push_to_hub']' returned non-zero exit status 1.\n" ] } ], "source": [ "!accelerate launch --mixed_precision=\"fp16\" train_text_to_image.py \\\n", " --pretrained_model_name_or_path=$MODEL_NAME \\\n", " --dataset_name=$DATASET_NAME \\\n", " --use_ema \\\n", " --resolution=512 --center_crop --random_flip \\\n", " --train_batch_size=1 \\\n", " --gradient_accumulation_steps=4 \\\n", " --gradient_checkpointing \\\n", " --max_train_steps=400 \\\n", " --learning_rate=1e-05 \\\n", " --max_grad_norm=1 \\\n", " --enable_xformers_memory_efficient_attention \\\n", " --lr_scheduler=\"constant\" --lr_warmup_steps=0 \\\n", " --output_dir=$OUTPUT_DIR \\\n", " --validation_prompts \"A description of the prompt you want to validate against.\"\n", " --push_to_hub" ] }, { "cell_type": "code", "execution_count": 28, "id": "9ad2c05f-d408-4fe8-805c-200adfc4ebed", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "19bf98a7d4f447958a27b9d1ce433b9a", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(HTML(value='
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from diffusers import StableDiffusionPipeline\n", "import torch\n", "from PIL import Image\n", "\n", "model_path2 = \"rohith2812/sd-naruto-model\"\n", "pipe = StableDiffusionPipeline.from_pretrained(model_path, torch_dtype=torch.float16)\n", "pipe.to(\"cuda\")\n", "\n", "\n", "\n", "image1 = pipe(prompt = \"A picture to understand logistic regression in data science\").images[0]\n", "image1.save(\"DSSample1.png\")\n", "\n", "\n", "def image_grid(imgs, rows, cols):\n", " assert len(imgs) == rows*cols\n", "\n", " w , h = imgs[0].size\n", " grid = Image.new('RGB' , size=(cols*w , rows*h))\n", " grid_w, grid_h = grid.size\n", "\n", " for i, img in enumerate(imgs):\n", " grid.paste(img,box = (i%cols*w , i//cols*h))\n", " return grid\n", "\n", "all_images = [image1]\n", "grid = image_grid(all_images,rows=1,cols=1)\n", "grid" ] }, { "cell_type": "code", "execution_count": null, "id": "d335ede1-47a9-421f-b9c2-06016bd66c0d", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 5 }