{ "cells": [ { "cell_type": "markdown", "id": "b01332d1-1384-4405-8af6-335c768da6e2", "metadata": {}, "source": [ "## SDXL LoRA Trainer by TheLastBen https://github.com/TheLastBen/fast-stable-diffusion, if you encounter any issues, feel free to discuss them." ] }, { "cell_type": "markdown", "id": "8f82bb3b-76de-4e2c-9251-df918f8f2cbe", "metadata": {}, "source": [ "# Dependencies" ] }, { "cell_type": "code", "execution_count": 1, "id": "3d144e06-1f7a-467b-9cf1-452bf773f0ab", "metadata": { "tags": [] }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d1e84d74d92c46f8aa78c03f50a0d0d8", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Button(button_style='success', description='Done!', disabled=True, icon='check', style=ButtonStyle(), tooltip=…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Install the dependencies\n", "\n", "force_reinstall= False\n", "\n", "# Set to true only if you want to install the dependencies again.\n", "\n", "#--------------------\n", "with open('/dev/null', 'w') as devnull:import requests, os, time, importlib;open('/workspace/sdxllorarunpod.py', 'wb').write(requests.get('https://huggingface.co/datasets/TheLastBen/RNPD/raw/main/Scripts/sdxllorarunpod.py').content);os.chdir('/workspace');import sdxllorarunpod;importlib.reload(sdxllorarunpod);from sdxllorarunpod import *;restored=False;restoreda=False;Deps(force_reinstall)" ] }, { "cell_type": "markdown", "id": "461b7686-e4aa-4fa8-ab6f-5a6acbf4c601", "metadata": {}, "source": [ "# Download the model" ] }, { "cell_type": "code", "execution_count": 2, "id": "2f705bd1-35c9-49bd-84fd-03a1348cbe83", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;32mUsing SDXL model\n" ] } ], "source": [ "# Run the cell to download the model\n", "\n", "#-------------\n", "MODEL_NAMExl=dls_xlf(\"\", \"\", \"\")" ] }, { "cell_type": "markdown", "id": "8e22327b-e0c3-424c-82e1-fb7f8a815c0b", "metadata": {}, "source": [ "# Create/Load a Session" ] }, { "cell_type": "code", "execution_count": 3, "id": "ac69c221-205a-40d2-b42e-6c8d515a43cc", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;32mCreating session...\n", "\u001b[1;32mSession created, proceed to uploading instance images\n" ] } ], "source": [ "Session_Name = \"aether_skin_230808_SDXL_LoRA_128_dim_50_epochs\"\n", "\n", "# Enter the session name, it if it exists, it will load it, otherwise it'll create an new session.\n", "\n", "#-----------------\n", "[WORKSPACE, Session_Name, INSTANCE_NAME, OUTPUT_DIR, SESSION_DIR, INSTANCE_DIR, CAPTIONS_DIR, MDLPTH, MODEL_NAMExl]=sess_xl(Session_Name, MODEL_NAMExl if 'MODEL_NAMExl' in locals() else \"\")" ] }, { "cell_type": "markdown", "id": "5d239e77-f7fd-404b-8006-081f15326412", "metadata": {}, "source": [ "# Train LoRA" ] }, { "cell_type": "code", "execution_count": null, "id": "c54a7335-8402-42f2-9a71-9da99f6ea604", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[34m'########:'########:::::'###::::'####:'##::: ##:'####:'##::: ##::'######:::\n", "... ##..:: ##.... ##:::'## ##:::. ##:: ###:: ##:. ##:: ###:: ##:'##... ##::\n", "::: ##:::: ##:::: ##::'##:. ##::: ##:: ####: ##:: ##:: ####: ##: ##:::..:::\n", "::: ##:::: ########::'##:::. ##:: ##:: ## ## ##:: ##:: ## ## ##: ##::'####:\n", "::: ##:::: ##.. ##::: #########:: ##:: ##. ####:: ##:: ##. ####: ##::: ##::\n", "::: ##:::: ##::. ##:: ##.... ##:: ##:: ##:. ###:: ##:: ##:. ###: ##::: ##::\n", "::: ##:::: ##:::. ##: ##:::: ##:'####: ##::. ##:'####: ##::. ##:. ######:::\n", ":::..:::::..:::::..::..:::::..::....::..::::..::....::..::::..:::......::::\n", "\u001b[0m\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Progress: 71%|███████ | 676/950 [06:22<02:23, 1.91it/s, loss=0.245, lr=5.75e-7] " ] } ], "source": [ "Resume_Training= False\n", "\n", "# If you're not satisfied with the result, Set to True, run again the cell and it will continue training the current model.\n", "\n", "\n", "Training_Epochs= 50\n", "\n", "# Epoch = Number of steps/images.\n", "\n", "Learning_Rate= \"3e-6\"\n", "\n", "# keep it between 1e-6 and 6e-6\n", "\n", "\n", "External_Captions= True\n", "\n", "# Load the captions from a text file for each instance image.\n", "\n", "\n", "LoRA_Dim = 128\n", "\n", "# Dimension of the LoRa model, between 64 and 128 is good enough.\n", "\n", "\n", "Resolution= 1024\n", "\n", "# 1024 is the native resolution.\n", "\n", "\n", "Save_VRAM = False\n", "\n", "# Use as low as 9.7GB VRAM with Dim = 64, but slightly slower training.\n", "\n", "#-----------------\n", "dbtrainxl(Resume_Training, Training_Epochs, Learning_Rate, LoRA_Dim, False, Resolution, MODEL_NAMExl, SESSION_DIR, INSTANCE_DIR, CAPTIONS_DIR, External_Captions, INSTANCE_NAME, Session_Name, OUTPUT_DIR, 0.03, Save_VRAM)" ] }, { "cell_type": "markdown", "id": "e2751798-508e-47ad-8e54-95188bdab051", "metadata": { "jp-MarkdownHeadingCollapsed": true, "tags": [] }, "source": [ "# Test the Trained Model" ] }, { "cell_type": "markdown", "id": "d1bc48d6-1526-44c6-ab7c-cc1538c7f61c", "metadata": {}, "source": [ "# ComfyUI" ] }, { "cell_type": "code", "execution_count": null, "id": "26272665-16de-4042-a7a4-6b9205ff3309", "metadata": { "scrolled": true, "tags": [] }, "outputs": [], "source": [ "Args=\"--listen --port 3000\"\n", "\n", "\n", "Download_SDXL_Model= True\n", "\n", "\n", "Huggingface_token_optional= \"\"\n", "\n", "# Restore your backed-up Comfy folder by entering your huggingface token, leave it empty to start fresh or continue with the existing sd folder (if any).\n", "\n", "#--------------------\n", "restored=sdcmff(Huggingface_token_optional, MDLPTH, Download_SDXL_Model, restored)\n", "!python /workspace/ComfyUI/main.py $Args" ] }, { "cell_type": "markdown", "id": "410520ca-7352-4fc4-907b-cb53f661074e", "metadata": {}, "source": [ "# A1111" ] }, { "cell_type": "code", "execution_count": null, "id": "351f18d5-f723-4d25-b1ae-1296a22c6d8c", "metadata": { "tags": [] }, "outputs": [], "source": [ "User = \"\"\n", "\n", "Password= \"\"\n", "\n", "# Add credentials to your Gradio interface (optional).\n", "\n", "Download_SDXL_Model= True\n", "\n", "\n", "Huggingface_token_optional= \"\"\n", "\n", "# Restore your backed-up SD folder by entering your huggingface token, leave it empty to start fresh or continue with the existing sd folder (if any).\n", "\n", "#-----------------\n", "configf, restoreda=test(MDLPTH, User, Password, Huggingface_token_optional, Download_SDXL_Model, restoreda)\n", "!python /workspace/sd/stable-diffusion-webui/webui.py $configf" ] }, { "cell_type": "markdown", "id": "093d64a7-3d4e-4197-8075-4ed11c7f0ae8", "metadata": {}, "source": [ "# Free up space" ] }, { "cell_type": "code", "execution_count": null, "id": "370ba58a-d58d-4a80-9575-8c6e094e2626", "metadata": {}, "outputs": [], "source": [ "# Display a list of sessions from which you can remove any session you don't need anymore\n", "\n", "#-------------------------\n", "clean()" ] } ], "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 }