Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile and run with Apple M1, M2 silicon. CoreML support. #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@

<ItemGroup>
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
<PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.16.0" />
<PackageReference Include="Microsoft.ML.OnnxTransformer" Version="2.0.1" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.Extensions" Version="0.8.1-alpha" />
<PackageReference Include="NumSharp" Version="0.30.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3" />
<PackageReference Include="Microsoft.ML" Version="2.0.1" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.Gpu" Version="1.15.0" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.Managed" Version="1.15.0" />

</ItemGroup>
<ItemGroup Label="FilesToCopy">
<Content Include="StableDiffusion.ML.OnnxRuntime.targets" PackagePath="build/StableDiffusion.ML.OnnxRuntime.targets" />
Expand Down
6 changes: 5 additions & 1 deletion StableDiffusion.ML.OnnxRuntime/StableDiffusionConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public enum ExecutionProvider
{
DirectML = 0,
Cuda = 1,
Cpu = 2
Cpu = 2,
CoreML = 3
}
// default props
public int NumInferenceSteps = 15;
Expand Down Expand Up @@ -45,6 +46,9 @@ public SessionOptions GetSessionOptionsForEp()
case ExecutionProvider.Cpu:
sessionOptions.AppendExecutionProvider_CPU();
return sessionOptions;
case ExecutionProvider.CoreML:
sessionOptions.AppendExecutionProvider_CoreML();
return sessionOptions;
default:
case ExecutionProvider.Cuda:
sessionOptions.GraphOptimizationLevel = GraphOptimizationLevel.ORT_ENABLE_ALL;
Expand Down
4 changes: 2 additions & 2 deletions StableDiffusion/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ static void Main(string[] args)
NumInferenceSteps = 15,
// Scale for classifier-free guidance
GuidanceScale = 7.5,
// Set your preferred Execution Provider. Currently (GPU, DirectML, CPU) are supported in this project.
// Set your preferred Execution Provider. Currently (GPU, DirectML, CPU, CoreML) are supported in this project.
// ONNX Runtime supports many more than this. Learn more here: https://onnxruntime.ai/docs/execution-providers/
// The config is defaulted to CUDA. You can override it here if needed.
// To use DirectML EP intall the Microsoft.ML.OnnxRuntime.DirectML and uninstall Microsoft.ML.OnnxRuntime.GPU
ExecutionProviderTarget = StableDiffusionConfig.ExecutionProvider.Cuda,
ExecutionProviderTarget = StableDiffusionConfig.ExecutionProvider.CoreML,
// Set GPU Device ID.
DeviceId = 0,
// Update paths to your models
Expand Down
3 changes: 1 addition & 2 deletions StableDiffusion/StableDiffusion.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

<ItemGroup>
<ProjectReference Include="..\StableDiffusion.ML.OnnxRuntime\StableDiffusion.ML.OnnxRuntime.csproj" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.Gpu" Version="1.15.0" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.Managed" Version="1.15.0" />

</ItemGroup>

</Project>