From 221e97090c40a3529f98198da7985ea97d2c52ca Mon Sep 17 00:00:00 2001 From: Jeff Ward Date: Sat, 6 Jan 2024 15:44:30 +0700 Subject: [PATCH 1/7] added readme for example projects --- OnnxStack.Console/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 OnnxStack.Console/README.md diff --git a/OnnxStack.Console/README.md b/OnnxStack.Console/README.md new file mode 100644 index 00000000..0d215d9a --- /dev/null +++ b/OnnxStack.Console/README.md @@ -0,0 +1 @@ +Example - Console App \ No newline at end of file From fd795dfd98cd9b45450f15c69497fb5c2cdbf77e Mon Sep 17 00:00:00 2001 From: Jeff Ward Date: Sat, 6 Jan 2024 15:50:15 +0700 Subject: [PATCH 2/7] fixed batch example --- OnnxStack.Console/Examples/StableDiffusionBatch.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/OnnxStack.Console/Examples/StableDiffusionBatch.cs b/OnnxStack.Console/Examples/StableDiffusionBatch.cs index 5fbcf785..ade26325 100644 --- a/OnnxStack.Console/Examples/StableDiffusionBatch.cs +++ b/OnnxStack.Console/Examples/StableDiffusionBatch.cs @@ -8,6 +8,8 @@ namespace OnnxStack.Console.Runner { + using StableDiffusion; + public sealed class StableDiffusionBatch : IExampleRunner { private readonly string _outputDirectory; @@ -56,6 +58,8 @@ public async Task RunAsync() foreach (var model in _configuration.ModelSets) { + _setSchedulerTypeForPipeline(); + OutputHelpers.WriteConsole($"Loading Model `{model.Name}`...", ConsoleColor.Green); await _stableDiffusionService.LoadModelAsync(model); @@ -76,6 +80,13 @@ public async Task RunAsync() OutputHelpers.WriteConsole($"Unloading Model `{model.Name}`...", ConsoleColor.Green); await _stableDiffusionService.UnloadModelAsync(model); + continue; + + void _setSchedulerTypeForPipeline() + { + SchedulerType[] scheduleTypes = model.PipelineType.GetSchedulerTypes(); + schedulerOptions.SchedulerType = scheduleTypes.Length == 1 ? scheduleTypes[0] : scheduleTypes[Random.Shared.Next(scheduleTypes.Length)]; + } } } } From 5bdd4ce0e22132e367b1e0fe246b2c4e6cf439fe Mon Sep 17 00:00:00 2001 From: Jeff Ward Date: Sat, 6 Jan 2024 16:06:20 +0700 Subject: [PATCH 3/7] added to readme file in example project --- OnnxStack.Console/README.md | 40 ++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/OnnxStack.Console/README.md b/OnnxStack.Console/README.md index 0d215d9a..dc107829 100644 --- a/OnnxStack.Console/README.md +++ b/OnnxStack.Console/README.md @@ -1 +1,39 @@ -Example - Console App \ No newline at end of file +# Example - Console App + +## Getting Started + +### 1.) Download the required `.onnx` models: + + + * https://huggingface.co/rocca/swin-ir-onnx + * This is the upscaler model. + * https://huggingface.co/runwayml/stable-diffusion-v1-5 + * https://huggingface.co/softwareweaver/InstaFlow-0.9B-Olive-Onnx + * https://huggingface.co/SimianLuo/LCM_Dreamshaper_v7 + * https://huggingface.co/softwareweaver/stable-diffusion-xl-base-1.0-Olive-Onnx + +Note: Ensure you run ```git lfs install``` before cloning the repository to ensure the models are downloaded correctly. + + +### 2.) Update the paths in the `appsettings.json` within the `/OnnxStack.Console/` project: + + +* Update the paths in `appsettings.json` to point to the downloaded models + * If the downloaded model repository does not contain a `Tokenizer` or `Tokenizer2` `.onnx` file, leave the path empty. + * Note: When the path is empty, OnnxStack will use it's own 'built-in' tokenizer called `cliptokenizer.onnx` + * Example with empty path: +```json + { + "Type": "Tokenizer", + "OnnxModelPath": "" + } +``` + + +### FAQ + +* **Q:** My `.GIF` is flashing, is it supposed to do this? +* **A:** The `.GIF` area has been deprecated in favor of the 'video' features that are being added. Please ignore this example for now. + + + \ No newline at end of file From 9efd91988761c1562ae131bb115e75d4588b4003 Mon Sep 17 00:00:00 2001 From: Jeff Ward Date: Sat, 6 Jan 2024 16:06:50 +0700 Subject: [PATCH 4/7] fixed typo in appsettings.json --- OnnxStack.Console/appsettings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OnnxStack.Console/appsettings.json b/OnnxStack.Console/appsettings.json index 09bb6916..1649f25d 100644 --- a/OnnxStack.Console/appsettings.json +++ b/OnnxStack.Console/appsettings.json @@ -205,7 +205,7 @@ "ExecutionProvider": "DirectML", "ModelConfigurations": [ { - "Type": "Unet", + "Type": "Upscaler", "OnnxModelPath": "D:\\Repositories\\upscaler\\SwinIR\\003_realSR_BSRGAN_DFO_s64w8_SwinIR-M_x4_GAN.onnx" } ] From b2bafe455ad45bc7be510a952b6f8b963688f08f Mon Sep 17 00:00:00 2001 From: Jeff Ward Date: Sat, 6 Jan 2024 16:09:52 +0700 Subject: [PATCH 5/7] added .bat file for downloading models --- OnnxStack.Console/download-models.bat | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 OnnxStack.Console/download-models.bat diff --git a/OnnxStack.Console/download-models.bat b/OnnxStack.Console/download-models.bat new file mode 100644 index 00000000..7da4a682 --- /dev/null +++ b/OnnxStack.Console/download-models.bat @@ -0,0 +1,9 @@ +mkdir onnx-models +cd onnx-models +git lfs install +git clone https://huggingface.co/rocca/swin-ir-onnx +git clone https://huggingface.co/runwayml/stable-diffusion-v1-5 +git clone https://huggingface.co/softwareweaver/InstaFlow-0.9B-Olive-Onnx +git clone https://huggingface.co/SimianLuo/LCM_Dreamshaper_v7 +git clone https://huggingface.co/softwareweaver/stable-diffusion-xl-base-1.0-Olive-Onnx + From fd692e97dcaf67f7df24f331963fa1e1793344e8 Mon Sep 17 00:00:00 2001 From: Jeff Ward Date: Sat, 6 Jan 2024 17:53:29 +0700 Subject: [PATCH 6/7] added onnx-models directory to the ignore list and worked on the readme file --- .gitignore | 3 ++ OnnxStack.Console/README.md | 60 ++++++++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index bf4ff561..9a9b1619 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,9 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs +# Downloaded .onnx files +onnx-models/ + # Build results [Dd]ebug/ [Dd]ebugPublic/ diff --git a/OnnxStack.Console/README.md b/OnnxStack.Console/README.md index dc107829..a5296f43 100644 --- a/OnnxStack.Console/README.md +++ b/OnnxStack.Console/README.md @@ -4,6 +4,9 @@ ### 1.) Download the required `.onnx` models: +**Method 1** + + Download the required models from the following repositories: * https://huggingface.co/rocca/swin-ir-onnx * This is the upscaler model. @@ -12,21 +15,62 @@ * https://huggingface.co/SimianLuo/LCM_Dreamshaper_v7 * https://huggingface.co/softwareweaver/stable-diffusion-xl-base-1.0-Olive-Onnx -Note: Ensure you run ```git lfs install``` before cloning the repository to ensure the models are downloaded correctly. + + Note: Ensure you run ```git lfs install``` before cloning the repository to ensure the models are downloaded correctly. + + + + + + + +**Method 2** + + Download Files + +Use the included 'download-models.bat' file to download the required models. +* If your on mac or linux, you can open the `download-models.bat` file and run each command manually if you are unable to run the `.bat` file. + * The `download-models.bat` will create a `onnx-models/` folder in current directory. Then it will download the required models into the `onnx-models/` folder. + * If you are unable to run the `.bat` file or have issues, you can open the `download-models.bat` file and run each command manually. + * The `.bat` file will not attempt to 're-download' or continue if the file already exists. If you need to re-download the models, delete the `onnx-models/` folder and run the `.bat` file again. + + +### 2.) If necessary, switch to the correct Stable Diffusion 1.5 branch + +**Stable Diffusion 1.5 - Get the .onnx files after download.** + +* After you download the `Stable Diffusion 1.5` model at: https://huggingface.co/runwayml/stable-diffusion-v1-5, check to see if any of the folders contain `.onnx` files. + * If none contain `.onnx` files, you will need to switch to the `.onnx` branch. + * If you have already checked out the `onnx` branch and have the `.onnx` files from the `Stable Diffusion 1.5` repository, you can skip this step. + + +We need to switch to the `onnx` branch to get the `.onnx` files. +You can do this anyway you would like, or just run the following commands: +* Open a new command prompt in `onnx-models/stable-diffusion-v1-5/` +```bash +git fetch origin +git checkout origin/onnx +``` +_It might take some time to switch branches and download all of the `.onnx` files pending your internet speed._ + -### 2.) Update the paths in the `appsettings.json` within the `/OnnxStack.Console/` project: +### 3.) Update the paths in the `appsettings.json` within the `/OnnxStack.Console/` project: -* Update the paths in `appsettings.json` to point to the downloaded models +* Update the paths in `appsettings.json` to point to the downloaded models. Update all the paths to point to the correct location of the downloaded models. * If the downloaded model repository does not contain a `Tokenizer` or `Tokenizer2` `.onnx` file, leave the path empty. - * Note: When the path is empty, OnnxStack will use it's own 'built-in' tokenizer called `cliptokenizer.onnx` + * Note: When the path is empty, OnnxStack will use it's own 'built-in' _default_ tokenizer called `cliptokenizer.onnx` * Example with empty path: ```json - { - "Type": "Tokenizer", - "OnnxModelPath": "" - } + { + "Type": "Tokenizer", + "OnnxModelPath": "" + }, + { + "Type": "Tokenizer2", + "OnnxModelPath": "" + } ``` From 860f0db7ed65956273b62bb3eef7b85635306232 Mon Sep 17 00:00:00 2001 From: Jeff Ward Date: Sat, 6 Jan 2024 18:00:27 +0700 Subject: [PATCH 7/7] updated readme --- OnnxStack.Console/README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/OnnxStack.Console/README.md b/OnnxStack.Console/README.md index a5296f43..9660b9c6 100644 --- a/OnnxStack.Console/README.md +++ b/OnnxStack.Console/README.md @@ -28,8 +28,14 @@ Download Files -Use the included 'download-models.bat' file to download the required models. -* If your on mac or linux, you can open the `download-models.bat` file and run each command manually if you are unable to run the `.bat` file. +**Experimental script** + +_Note: The `download-models.bat` file is not smart enough to know if you have already downloaded the models. If you need to re-download the models, please run the commands manually within `git` to pull the latest changes from the target repository._ + +> If your on mac or linux, you can open the `download-models.bat` file and run each command manually if you are unable to run the `.bat` file. + +Use the included `download-models.bat` file to download the required models. + * The `download-models.bat` will create a `onnx-models/` folder in current directory. Then it will download the required models into the `onnx-models/` folder. * If you are unable to run the `.bat` file or have issues, you can open the `download-models.bat` file and run each command manually. * The `.bat` file will not attempt to 're-download' or continue if the file already exists. If you need to re-download the models, delete the `onnx-models/` folder and run the `.bat` file again. @@ -79,5 +85,10 @@ _It might take some time to switch branches and download all of the `.onnx` file * **Q:** My `.GIF` is flashing, is it supposed to do this? * **A:** The `.GIF` area has been deprecated in favor of the 'video' features that are being added. Please ignore this example for now. +* **Q:** I am getting an error: `138 are out of bounds or can not be read in full` +* **A:** usually means the model is corrupt or has not been fully downloaded, make sure if you clone the repo you have git LFS installed, or you will just get small pointer files not the large GB files + + + \ No newline at end of file