From d35f515413c2d9cd66ae2d1ab9352661d34fe340 Mon Sep 17 00:00:00 2001 From: smk-e Date: Tue, 3 Sep 2024 18:04:29 +0000 Subject: [PATCH 01/11] translationBot(ui): update translation (Spanish) Currently translated at 33.0% (452 of 1369 strings) Co-authored-by: smk-e Translate-URL: https://hosted.weblate.org/projects/invokeai/web-ui/es/ Translation: InvokeAI/Web UI --- invokeai/frontend/web/public/locales/es.json | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/invokeai/frontend/web/public/locales/es.json b/invokeai/frontend/web/public/locales/es.json index 237ec7a9054..82315118333 100644 --- a/invokeai/frontend/web/public/locales/es.json +++ b/invokeai/frontend/web/public/locales/es.json @@ -86,15 +86,15 @@ "loadMore": "Cargar más", "noImagesInGallery": "No hay imágenes para mostrar", "deleteImage_one": "Eliminar Imagen", - "deleteImage_many": "", - "deleteImage_other": "", + "deleteImage_many": "Eliminar {{count}} Imágenes", + "deleteImage_other": "Eliminar {{count}} Imágenes", "deleteImagePermanent": "Las imágenes eliminadas no se pueden restaurar.", "assets": "Activos", "autoAssignBoardOnClick": "Asignación automática de tableros al hacer clic" }, "hotkeys": { "keyboardShortcuts": "Atajos de teclado", - "appHotkeys": "Atajos de applicación", + "appHotkeys": "Atajos de aplicación", "generalHotkeys": "Atajos generales", "galleryHotkeys": "Atajos de galería", "unifiedCanvasHotkeys": "Atajos de lienzo unificado", @@ -535,7 +535,7 @@ "bottomMessage": "Al eliminar este panel y las imágenes que contiene, se restablecerán las funciones que los estén utilizando actualmente.", "deleteBoardAndImages": "Borrar el panel y las imágenes", "loading": "Cargando...", - "deletedBoardsCannotbeRestored": "Los paneles eliminados no se pueden restaurar", + "deletedBoardsCannotbeRestored": "Los paneles eliminados no se pueden restaurar. Al Seleccionar 'Borrar Solo el Panel' transferirá las imágenes a un estado sin categorizar.", "move": "Mover", "menuItemAutoAdd": "Agregar automáticamente a este panel", "searchBoard": "Buscando paneles…", @@ -549,7 +549,13 @@ "imagesWithCount_other": "{{count}} imágenes", "assetsWithCount_one": "{{count}} activo", "assetsWithCount_many": "{{count}} activos", - "assetsWithCount_other": "{{count}} activos" + "assetsWithCount_other": "{{count}} activos", + "hideBoards": "Ocultar Paneles", + "addPrivateBoard": "Agregar un tablero privado", + "addSharedBoard": "Agregar Panel Compartido", + "boards": "Paneles", + "archiveBoard": "Archivar Panel", + "archived": "Archivado" }, "accordions": { "compositing": { From f01f1033acc0434631fa61c400c3405d6dcfe91f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D1=8F=D0=BD=D0=B0=D1=82=D0=BE=D1=80?= Date: Tue, 3 Sep 2024 18:04:31 +0000 Subject: [PATCH 02/11] translationBot(ui): update translation (Russian) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently translated at 100.0% (1370 of 1370 strings) translationBot(ui): update translation (Russian) Currently translated at 100.0% (1369 of 1369 strings) Co-authored-by: Васянатор Translate-URL: https://hosted.weblate.org/projects/invokeai/web-ui/ru/ Translation: InvokeAI/Web UI --- invokeai/frontend/web/public/locales/ru.json | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/invokeai/frontend/web/public/locales/ru.json b/invokeai/frontend/web/public/locales/ru.json index c459c26d4c2..d63bfdaaba8 100644 --- a/invokeai/frontend/web/public/locales/ru.json +++ b/invokeai/frontend/web/public/locales/ru.json @@ -501,7 +501,8 @@ "noModelsInstalled": "Нет установленных моделей", "noModelsInstalledDesc1": "Установите модели с помощью", "noMatchingModels": "Нет подходящих моделей", - "ipAdapters": "IP адаптеры" + "ipAdapters": "IP адаптеры", + "starterModelsInModelManager": "Стартовые модели можно найти в Менеджере моделей" }, "parameters": { "images": "Изображения", @@ -1758,7 +1759,8 @@ "postProcessingModel": "Модель постобработки", "tileControlNetModelDesc": "Модель ControlNet для выбранной архитектуры основной модели", "missingModelsWarning": "Зайдите в Менеджер моделей чтоб установить необходимые модели:", - "postProcessingMissingModelWarning": "Посетите Менеджер моделей, чтобы установить модель постобработки (img2img)." + "postProcessingMissingModelWarning": "Посетите Менеджер моделей, чтобы установить модель постобработки (img2img).", + "upscale": "Увеличить" }, "stylePresets": { "noMatchingTemplates": "Нет подходящих шаблонов", @@ -1804,7 +1806,8 @@ "noTemplates": "Нет шаблонов", "promptTemplatesDesc2": "Используйте строку-заполнитель
{{placeholder}}
, чтобы указать место, куда должен быть включен ваш запрос в шаблоне.", "searchByName": "Поиск по имени", - "shared": "Общий" + "shared": "Общий", + "promptTemplateCleared": "Шаблон запроса создан" }, "upsell": { "inviteTeammates": "Пригласите членов команды", From 24a7ed467c31ea9bc2e73c4bc3f8d7f46c06ad7d Mon Sep 17 00:00:00 2001 From: Riccardo Giovanetti Date: Tue, 3 Sep 2024 18:04:32 +0000 Subject: [PATCH 03/11] translationBot(ui): update translation (Italian) Currently translated at 98.2% (1350 of 1374 strings) translationBot(ui): update translation (Italian) Currently translated at 98.2% (1350 of 1374 strings) translationBot(ui): update translation (Italian) Currently translated at 98.2% (1350 of 1374 strings) translationBot(ui): update translation (Italian) Currently translated at 98.4% (1349 of 1370 strings) translationBot(ui): update translation (Italian) Currently translated at 98.4% (1348 of 1369 strings) Co-authored-by: Riccardo Giovanetti Translate-URL: https://hosted.weblate.org/projects/invokeai/web-ui/it/ Translation: InvokeAI/Web UI --- invokeai/frontend/web/public/locales/it.json | 24 ++++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/invokeai/frontend/web/public/locales/it.json b/invokeai/frontend/web/public/locales/it.json index a7b7df1a820..230affd2e50 100644 --- a/invokeai/frontend/web/public/locales/it.json +++ b/invokeai/frontend/web/public/locales/it.json @@ -496,7 +496,9 @@ "main": "Principali", "noModelsInstalledDesc1": "Installa i modelli con", "ipAdapters": "Adattatori IP", - "noMatchingModels": "Nessun modello corrispondente" + "noMatchingModels": "Nessun modello corrispondente", + "starterModelsInModelManager": "I modelli iniziali possono essere trovati in Gestione Modelli", + "spandrelImageToImage": "Immagine a immagine (Spandrel)" }, "parameters": { "images": "Immagini", @@ -510,7 +512,7 @@ "perlinNoise": "Rumore Perlin", "type": "Tipo", "strength": "Forza", - "upscaling": "Ampliamento", + "upscaling": "Amplia", "scale": "Scala", "imageFit": "Adatta l'immagine iniziale alle dimensioni di output", "scaleBeforeProcessing": "Scala prima dell'elaborazione", @@ -593,7 +595,7 @@ "globalPositivePromptPlaceholder": "Prompt positivo globale", "globalNegativePromptPlaceholder": "Prompt negativo globale", "processImage": "Elabora Immagine", - "sendToUpscale": "Invia a Ampliare", + "sendToUpscale": "Invia a Amplia", "postProcessing": "Post-elaborazione (Shift + U)" }, "settings": { @@ -1420,7 +1422,7 @@ "paramUpscaleMethod": { "heading": "Metodo di ampliamento", "paragraphs": [ - "Metodo utilizzato per eseguire l'ampliamento dell'immagine per la correzione ad alta risoluzione." + "Metodo utilizzato per ampliare l'immagine per la correzione ad alta risoluzione." ] }, "patchmatchDownScaleSize": { @@ -1528,7 +1530,7 @@ }, "upscaleModel": { "paragraphs": [ - "Il modello di ampliamento (Upscale), scala l'immagine alle dimensioni di uscita prima di aggiungere i dettagli. È possibile utilizzare qualsiasi modello di ampliamento supportato, ma alcuni sono specializzati per diversi tipi di immagini, come foto o disegni al tratto." + "Il modello di ampliamento, scala l'immagine alle dimensioni di uscita prima di aggiungere i dettagli. È possibile utilizzare qualsiasi modello di ampliamento supportato, ma alcuni sono specializzati per diversi tipi di immagini, come foto o disegni al tratto." ], "heading": "Modello di ampliamento" }, @@ -1720,26 +1722,27 @@ "modelsTab": "$t(ui.tabs.models) $t(common.tab)", "queue": "Coda", "queueTab": "$t(ui.tabs.queue) $t(common.tab)", - "upscaling": "Ampliamento", + "upscaling": "Amplia", "upscalingTab": "$t(ui.tabs.upscaling) $t(common.tab)" } }, "upscaling": { "creativity": "Creatività", "structure": "Struttura", - "upscaleModel": "Modello di Ampliamento", + "upscaleModel": "Modello di ampliamento", "scale": "Scala", "missingModelsWarning": "Visita Gestione modelli per installare i modelli richiesti:", "mainModelDesc": "Modello principale (architettura SD1.5 o SDXL)", "tileControlNetModelDesc": "Modello Tile ControlNet per l'architettura del modello principale scelto", - "upscaleModelDesc": "Modello per l'ampliamento (da immagine a immagine)", + "upscaleModelDesc": "Modello per l'ampliamento (immagine a immagine)", "missingUpscaleInitialImage": "Immagine iniziale mancante per l'ampliamento", "missingUpscaleModel": "Modello per l’ampliamento mancante", "missingTileControlNetModel": "Nessun modello ControlNet Tile valido installato", "postProcessingModel": "Modello di post-elaborazione", "postProcessingMissingModelWarning": "Visita Gestione modelli per installare un modello di post-elaborazione (da immagine a immagine).", "exceedsMaxSize": "Le impostazioni di ampliamento superano il limite massimo delle dimensioni", - "exceedsMaxSizeDetails": "Il limite massimo di ampliamento è {{maxUpscaleDimension}}x{{maxUpscaleDimension}} pixel. Prova un'immagine più piccola o diminuisci la scala selezionata." + "exceedsMaxSizeDetails": "Il limite massimo di ampliamento è {{maxUpscaleDimension}}x{{maxUpscaleDimension}} pixel. Prova un'immagine più piccola o diminuisci la scala selezionata.", + "upscale": "Amplia" }, "upsell": { "inviteTeammates": "Invita collaboratori", @@ -1789,6 +1792,7 @@ "positivePromptColumn": "'prompt' o 'positive_prompt'", "noTemplates": "Nessun modello", "acceptedColumnsKeys": "Colonne/chiavi accettate:", - "templateActions": "Azioni modello" + "templateActions": "Azioni modello", + "promptTemplateCleared": "Modello di prompt cancellato" } } From e59b6bb971ec002963ec3245705919205c15e267 Mon Sep 17 00:00:00 2001 From: Tobias Lechner Date: Tue, 3 Sep 2024 18:04:33 +0000 Subject: [PATCH 04/11] translationBot(ui): update translation (German) Currently translated at 63.3% (870 of 1374 strings) Co-authored-by: Tobias Lechner Translate-URL: https://hosted.weblate.org/projects/invokeai/web-ui/de/ Translation: InvokeAI/Web UI --- invokeai/frontend/web/public/locales/de.json | 21 +++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/invokeai/frontend/web/public/locales/de.json b/invokeai/frontend/web/public/locales/de.json index 7633c70ca85..23cfd72b48c 100644 --- a/invokeai/frontend/web/public/locales/de.json +++ b/invokeai/frontend/web/public/locales/de.json @@ -127,7 +127,14 @@ "bulkDownloadRequestedDesc": "Dein Download wird vorbereitet. Dies kann ein paar Momente dauern.", "bulkDownloadRequestFailed": "Problem beim Download vorbereiten", "bulkDownloadFailed": "Download fehlgeschlagen", - "alwaysShowImageSizeBadge": "Zeige immer Bilder Größe Abzeichen" + "alwaysShowImageSizeBadge": "Zeige immer Bilder Größe Abzeichen", + "selectForCompare": "Zum Vergleichen auswählen", + "compareImage": "Bilder vergleichen", + "exitSearch": "Suche beenden", + "newestFirst": "Neueste zuerst", + "oldestFirst": "Älteste zuerst", + "openInViewer": "Im Viewer öffnen", + "swapImages": "Bilder tauschen" }, "hotkeys": { "keyboardShortcuts": "Tastenkürzel", @@ -631,7 +638,8 @@ "archived": "Archiviert", "noBoards": "Kein {boardType}} Ordner", "hideBoards": "Ordner verstecken", - "viewBoards": "Ordner ansehen" + "viewBoards": "Ordner ansehen", + "deletedPrivateBoardsCannotbeRestored": "Gelöschte Boards können nicht wiederhergestellt werden. Wenn Sie „Nur Board löschen“ wählen, werden die Bilder in einen privaten, nicht kategorisierten Status für den Ersteller des Bildes versetzt." }, "controlnet": { "showAdvanced": "Zeige Erweitert", @@ -781,7 +789,9 @@ "batchFieldValues": "Stapelverarbeitungswerte", "batchQueued": "Stapelverarbeitung eingereiht", "graphQueued": "Graph eingereiht", - "graphFailedToQueue": "Fehler beim Einreihen des Graphen" + "graphFailedToQueue": "Fehler beim Einreihen des Graphen", + "generations_one": "Generation", + "generations_other": "Generationen" }, "metadata": { "negativePrompt": "Negativ Beschreibung", @@ -1146,5 +1156,10 @@ "noMatchingTriggers": "Keine passenden Trigger", "addPromptTrigger": "Prompt-Trigger hinzufügen", "compatibleEmbeddings": "Kompatible Einbettungen" + }, + "ui": { + "tabs": { + "queue": "Warteschlange" + } } } From 8b03b39aa877d42bc0c222a2243be3d900fdb940 Mon Sep 17 00:00:00 2001 From: Phrixus2023 <920414016@qq.com> Date: Tue, 3 Sep 2024 18:04:35 +0000 Subject: [PATCH 05/11] translationBot(ui): update translation (Chinese (Simplified Han script)) Currently translated at 97.6% (1342 of 1374 strings) Co-authored-by: Phrixus2023 <920414016@qq.com> Translate-URL: https://hosted.weblate.org/projects/invokeai/web-ui/zh_Hans/ Translation: InvokeAI/Web UI --- .../frontend/web/public/locales/zh_CN.json | 56 +++++++++++++++++-- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/invokeai/frontend/web/public/locales/zh_CN.json b/invokeai/frontend/web/public/locales/zh_CN.json index dad9ad1c21d..d1e46d6a76a 100644 --- a/invokeai/frontend/web/public/locales/zh_CN.json +++ b/invokeai/frontend/web/public/locales/zh_CN.json @@ -154,7 +154,8 @@ "displaySearch": "显示搜索", "stretchToFit": "拉伸以适应", "exitCompare": "退出对比", - "compareHelp1": "在点击图库中的图片或使用箭头键切换比较图片时,请按住Alt 键。" + "compareHelp1": "在点击图库中的图片或使用箭头键切换比较图片时,请按住Alt 键。", + "go": "运行" }, "hotkeys": { "keyboardShortcuts": "快捷键", @@ -494,7 +495,9 @@ "huggingFacePlaceholder": "所有者或模型名称", "huggingFaceRepoID": "HuggingFace仓库ID", "loraTriggerPhrases": "LoRA 触发词", - "ipAdapters": "IP适配器" + "ipAdapters": "IP适配器", + "spandrelImageToImage": "图生图(Spandrel)", + "starterModelsInModelManager": "您可以在模型管理器中找到初始模型" }, "parameters": { "images": "图像", @@ -695,7 +698,9 @@ "outOfMemoryErrorDesc": "您当前的生成设置已超出系统处理能力.请调整设置后再次尝试.", "parametersSet": "参数已恢复", "errorCopied": "错误信息已复制", - "modelImportCanceled": "模型导入已取消" + "modelImportCanceled": "模型导入已取消", + "importFailed": "导入失败", + "importSuccessful": "导入成功" }, "unifiedCanvas": { "layer": "图层", @@ -1705,12 +1710,55 @@ "missingModelsWarning": "请访问模型管理器 安装所需的模型:", "mainModelDesc": "主模型(SD1.5或SDXL架构)", "exceedsMaxSize": "放大设置超出了最大尺寸限制", - "exceedsMaxSizeDetails": "最大放大限制是 {{maxUpscaleDimension}}x{{maxUpscaleDimension}} 像素.请尝试一个较小的图像或减少您的缩放选择." + "exceedsMaxSizeDetails": "最大放大限制是 {{maxUpscaleDimension}}x{{maxUpscaleDimension}} 像素.请尝试一个较小的图像或减少您的缩放选择.", + "upscale": "放大" }, "upsell": { "inviteTeammates": "邀请团队成员", "professional": "专业", "professionalUpsell": "可在 Invoke 的专业版中使用.点击此处或访问 invoke.com/pricing 了解更多详情.", "shareAccess": "共享访问权限" + }, + "stylePresets": { + "positivePrompt": "正向提示词", + "preview": "预览", + "deleteImage": "删除图像", + "deleteTemplate": "删除模版", + "deleteTemplate2": "您确定要删除这个模板吗?请注意,删除后无法恢复.", + "importTemplates": "导入提示模板,支持CSV或JSON格式", + "insertPlaceholder": "插入一个占位符", + "myTemplates": "我的模版", + "name": "名称", + "type": "类型", + "unableToDeleteTemplate": "无法删除提示模板", + "updatePromptTemplate": "更新提示词模版", + "exportPromptTemplates": "导出我的提示模板为CSV格式", + "exportDownloaded": "导出已下载", + "noMatchingTemplates": "无匹配的模版", + "promptTemplatesDesc1": "提示模板可以帮助您在编写提示时添加预设的文本内容.", + "promptTemplatesDesc3": "如果您没有使用占位符,那么模板的内容将会被添加到您提示的末尾.", + "searchByName": "按名称搜索", + "shared": "已分享", + "sharedTemplates": "已分享的模版", + "templateActions": "模版操作", + "templateDeleted": "提示模版已删除", + "toggleViewMode": "切换显示模式", + "uploadImage": "上传图像", + "active": "激活", + "choosePromptTemplate": "选择提示词模板", + "clearTemplateSelection": "清除模版选择", + "copyTemplate": "拷贝模版", + "createPromptTemplate": "创建提示词模版", + "defaultTemplates": "默认模版", + "editTemplate": "编辑模版", + "exportFailed": "无法生成并下载CSV文件", + "flatten": "将选定的模板内容合并到当前提示中", + "negativePrompt": "反向提示词", + "promptTemplateCleared": "提示模板已清除", + "useForTemplate": "用于提示词模版", + "viewList": "预览模版列表", + "viewModeTooltip": "这是您的提示在当前选定的模板下的预览效果。如需编辑提示,请直接在文本框中点击进行修改.", + "noTemplates": "无模版", + "private": "私密" } } From 87f9e59cfbcd7ad7fb426429ee7dac5e503482fd Mon Sep 17 00:00:00 2001 From: Brandon Rising Date: Wed, 4 Sep 2024 14:27:47 -0400 Subject: [PATCH 06/11] Cast tensors in unquantized flux models to bfloat16 during loading --- invokeai/backend/model_manager/load/model_loaders/flux.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/invokeai/backend/model_manager/load/model_loaders/flux.py b/invokeai/backend/model_manager/load/model_loaders/flux.py index dcceda5ad21..2d54911753d 100644 --- a/invokeai/backend/model_manager/load/model_loaders/flux.py +++ b/invokeai/backend/model_manager/load/model_loaders/flux.py @@ -193,6 +193,10 @@ def _load_from_singlefile( sd = load_file(model_path) if "model.diffusion_model.double_blocks.0.img_attn.norm.key_norm.scale" in sd: sd = convert_bundle_to_flux_transformer_checkpoint(sd) + for k, v in sd.items(): + if v.dtype == torch.bfloat16: + continue + sd[k] = v.to(dtype=torch.bfloat16) model.load_state_dict(sd, assign=True) return model From 445f813fb9592bcc64b9dc10999ce8166ee9ec8f Mon Sep 17 00:00:00 2001 From: Brandon Rising Date: Thu, 5 Sep 2024 13:06:07 -0400 Subject: [PATCH 07/11] Update flux transformer loader to more efficiently use and release memory during upcasting --- .../model_manager/load/model_loaders/flux.py | 31 ++++++++++++++++--- .../backend/model_manager/util/model_util.py | 5 +++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/invokeai/backend/model_manager/load/model_loaders/flux.py b/invokeai/backend/model_manager/load/model_loaders/flux.py index 2d54911753d..cd48cefb803 100644 --- a/invokeai/backend/model_manager/load/model_loaders/flux.py +++ b/invokeai/backend/model_manager/load/model_loaders/flux.py @@ -1,11 +1,13 @@ # Copyright (c) 2024, Brandon W. Rising and the InvokeAI Development Team """Class for Flux model loading in InvokeAI.""" +import gc from pathlib import Path from typing import Optional import accelerate import torch +from pympler import asizeof from safetensors.torch import load_file from transformers import AutoConfig, AutoModelForTextEncoding, CLIPTextModel, CLIPTokenizer, T5EncoderModel, T5Tokenizer @@ -32,7 +34,10 @@ ) from invokeai.backend.model_manager.load.load_default import ModelLoader from invokeai.backend.model_manager.load.model_loader_registry import ModelLoaderRegistry -from invokeai.backend.model_manager.util.model_util import convert_bundle_to_flux_transformer_checkpoint +from invokeai.backend.model_manager.util.model_util import ( + convert_bundle_to_flux_transformer_checkpoint, + convert_sd_entry_to_bfloat16, +) from invokeai.backend.util.silence_warnings import SilenceWarnings try: @@ -193,11 +198,27 @@ def _load_from_singlefile( sd = load_file(model_path) if "model.diffusion_model.double_blocks.0.img_attn.norm.key_norm.scale" in sd: sd = convert_bundle_to_flux_transformer_checkpoint(sd) - for k, v in sd.items(): - if v.dtype == torch.bfloat16: - continue - sd[k] = v.to(dtype=torch.bfloat16) + futures: list[torch.jit.Future[tuple[str, torch.Tensor]]] = [] + sd_size = asizeof.asizeof(sd) + cache_updated = False + for k in sd.keys(): + v = sd[k] + if v.dtype != torch.bfloat16: + if not cache_updated: + self._ram_cache.make_room(sd_size) + cache_updated = True + futures.append(torch.jit.fork(convert_sd_entry_to_bfloat16, k, v)) + # Clean up unused variables + del v + gc.collect() # Force garbage collection to free memory + for future in futures: + k, v = torch.jit.wait(future) + sd[k] = v + del k, v + del futures + gc.collect() # Force garbage collection to free memory model.load_state_dict(sd, assign=True) + return model diff --git a/invokeai/backend/model_manager/util/model_util.py b/invokeai/backend/model_manager/util/model_util.py index fd904ac3358..353ebec1c9c 100644 --- a/invokeai/backend/model_manager/util/model_util.py +++ b/invokeai/backend/model_manager/util/model_util.py @@ -159,3 +159,8 @@ def convert_bundle_to_flux_transformer_checkpoint( del transformer_state_dict[k] return original_state_dict + + +@torch.jit.script +def convert_sd_entry_to_bfloat16(key: str, tensor: torch.Tensor) -> tuple[str, torch.Tensor]: + return key, tensor.to(torch.bfloat16, copy=False) From 5219ac12a6a056f9c5151f81fbc871595ddd1cce Mon Sep 17 00:00:00 2001 From: Brandon Rising Date: Thu, 5 Sep 2024 13:12:25 -0400 Subject: [PATCH 08/11] Add comment explaining the cache make room call --- invokeai/backend/model_manager/load/model_loaders/flux.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/invokeai/backend/model_manager/load/model_loaders/flux.py b/invokeai/backend/model_manager/load/model_loaders/flux.py index cd48cefb803..934fffbbf3e 100644 --- a/invokeai/backend/model_manager/load/model_loaders/flux.py +++ b/invokeai/backend/model_manager/load/model_loaders/flux.py @@ -199,6 +199,9 @@ def _load_from_singlefile( if "model.diffusion_model.double_blocks.0.img_attn.norm.key_norm.scale" in sd: sd = convert_bundle_to_flux_transformer_checkpoint(sd) futures: list[torch.jit.Future[tuple[str, torch.Tensor]]] = [] + # For the first iteration we are just requesting the current size of the state dict + # This is due to an expected doubling of the tensor sizes in memory after converting float8 -> float16 + # This should be refined in the future if not removed entirely when we support more data types sd_size = asizeof.asizeof(sd) cache_updated = False for k in sd.keys(): From 6667c39c736b118ad5dad6955b91e4150bd7bbab Mon Sep 17 00:00:00 2001 From: Brandon Rising Date: Thu, 5 Sep 2024 14:44:42 -0400 Subject: [PATCH 09/11] Remove dependency of asizeof --- .../backend/model_manager/load/model_loaders/flux.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/invokeai/backend/model_manager/load/model_loaders/flux.py b/invokeai/backend/model_manager/load/model_loaders/flux.py index 934fffbbf3e..fb732a48da0 100644 --- a/invokeai/backend/model_manager/load/model_loaders/flux.py +++ b/invokeai/backend/model_manager/load/model_loaders/flux.py @@ -7,7 +7,6 @@ import accelerate import torch -from pympler import asizeof from safetensors.torch import load_file from transformers import AutoConfig, AutoModelForTextEncoding, CLIPTextModel, CLIPTokenizer, T5EncoderModel, T5Tokenizer @@ -199,15 +198,15 @@ def _load_from_singlefile( if "model.diffusion_model.double_blocks.0.img_attn.norm.key_norm.scale" in sd: sd = convert_bundle_to_flux_transformer_checkpoint(sd) futures: list[torch.jit.Future[tuple[str, torch.Tensor]]] = [] - # For the first iteration we are just requesting the current size of the state dict - # This is due to an expected doubling of the tensor sizes in memory after converting float8 -> float16 - # This should be refined in the future if not removed entirely when we support more data types - sd_size = asizeof.asizeof(sd) cache_updated = False for k in sd.keys(): v = sd[k] if v.dtype != torch.bfloat16: if not cache_updated: + # For the first iteration we are just requesting the current size of the state dict + # This is due to an expected doubling of the tensor sizes in memory after converting float8 -> float16 + # This should be refined in the future if not removed entirely when we support more data types + sd_size = sum([ten.nelement() * ten.element_size() for ten in sd.values()]) self._ram_cache.make_room(sd_size) cache_updated = True futures.append(torch.jit.fork(convert_sd_entry_to_bfloat16, k, v)) From a16b555d476f6064c72d4a36244f0d0298dbbb2f Mon Sep 17 00:00:00 2001 From: Brandon Rising Date: Thu, 5 Sep 2024 15:29:41 -0400 Subject: [PATCH 10/11] Simplify flux model dtype conversion in model loader --- .../model_manager/load/model_loaders/flux.py | 28 +++---------------- .../backend/model_manager/util/model_util.py | 5 ---- 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/invokeai/backend/model_manager/load/model_loaders/flux.py b/invokeai/backend/model_manager/load/model_loaders/flux.py index fb732a48da0..c7563c2c203 100644 --- a/invokeai/backend/model_manager/load/model_loaders/flux.py +++ b/invokeai/backend/model_manager/load/model_loaders/flux.py @@ -1,7 +1,6 @@ # Copyright (c) 2024, Brandon W. Rising and the InvokeAI Development Team """Class for Flux model loading in InvokeAI.""" -import gc from pathlib import Path from typing import Optional @@ -35,7 +34,6 @@ from invokeai.backend.model_manager.load.model_loader_registry import ModelLoaderRegistry from invokeai.backend.model_manager.util.model_util import ( convert_bundle_to_flux_transformer_checkpoint, - convert_sd_entry_to_bfloat16, ) from invokeai.backend.util.silence_warnings import SilenceWarnings @@ -197,30 +195,12 @@ def _load_from_singlefile( sd = load_file(model_path) if "model.diffusion_model.double_blocks.0.img_attn.norm.key_norm.scale" in sd: sd = convert_bundle_to_flux_transformer_checkpoint(sd) - futures: list[torch.jit.Future[tuple[str, torch.Tensor]]] = [] - cache_updated = False + new_sd_size = sum([ten.nelement() * torch.bfloat16.itemsize for ten in sd.values()]) + self._ram_cache.make_room(new_sd_size) for k in sd.keys(): - v = sd[k] - if v.dtype != torch.bfloat16: - if not cache_updated: - # For the first iteration we are just requesting the current size of the state dict - # This is due to an expected doubling of the tensor sizes in memory after converting float8 -> float16 - # This should be refined in the future if not removed entirely when we support more data types - sd_size = sum([ten.nelement() * ten.element_size() for ten in sd.values()]) - self._ram_cache.make_room(sd_size) - cache_updated = True - futures.append(torch.jit.fork(convert_sd_entry_to_bfloat16, k, v)) - # Clean up unused variables - del v - gc.collect() # Force garbage collection to free memory - for future in futures: - k, v = torch.jit.wait(future) - sd[k] = v - del k, v - del futures - gc.collect() # Force garbage collection to free memory + # We need to cast to bfloat16 due to it being the only currently supported dtype for inference + sd[k] = sd[k].to(torch.bfloat16) model.load_state_dict(sd, assign=True) - return model diff --git a/invokeai/backend/model_manager/util/model_util.py b/invokeai/backend/model_manager/util/model_util.py index 353ebec1c9c..fd904ac3358 100644 --- a/invokeai/backend/model_manager/util/model_util.py +++ b/invokeai/backend/model_manager/util/model_util.py @@ -159,8 +159,3 @@ def convert_bundle_to_flux_transformer_checkpoint( del transformer_state_dict[k] return original_state_dict - - -@torch.jit.script -def convert_sd_entry_to_bfloat16(key: str, tensor: torch.Tensor) -> tuple[str, torch.Tensor]: - return key, tensor.to(torch.bfloat16, copy=False) From bda579577c460a8fdf550cf08e8b9a269c0203de Mon Sep 17 00:00:00 2001 From: Brandon Rising Date: Thu, 5 Sep 2024 15:56:16 -0400 Subject: [PATCH 11/11] chore: 4.2.9 version bump --- invokeai/version/invokeai_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/invokeai/version/invokeai_version.py b/invokeai/version/invokeai_version.py index 230c671312f..d386f167fd8 100644 --- a/invokeai/version/invokeai_version.py +++ b/invokeai/version/invokeai_version.py @@ -1 +1 @@ -__version__ = "4.2.9rc2" +__version__ = "4.2.9"