Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Example project fixes and readme additions #93

Merged
merged 7 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Downloaded .onnx files
onnx-models/

# Build results
[Dd]ebug/
[Dd]ebugPublic/
Expand Down
11 changes: 11 additions & 0 deletions OnnxStack.Console/Examples/StableDiffusionBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace OnnxStack.Console.Runner
{
using StableDiffusion;

public sealed class StableDiffusionBatch : IExampleRunner
{
private readonly string _outputDirectory;
Expand Down Expand Up @@ -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);

Expand All @@ -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)];
}
}
}
}
Expand Down
94 changes: 94 additions & 0 deletions OnnxStack.Console/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Example - Console App

## Getting Started

### 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.
* 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.







**Method 2**

Download Files

**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.


### 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._



### 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 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' _default_ tokenizer called `cliptokenizer.onnx`
* Example with empty path:
```json
{
"Type": "Tokenizer",
"OnnxModelPath": ""
},
{
"Type": "Tokenizer2",
"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.

* **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





2 changes: 1 addition & 1 deletion OnnxStack.Console/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
Expand Down
9 changes: 9 additions & 0 deletions OnnxStack.Console/download-models.bat
Original file line number Diff line number Diff line change
@@ -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