From 7aa903d252ecc77be8e073f3ec09249b0ba5083d Mon Sep 17 00:00:00 2001 From: Pedro Cuenca Date: Sun, 30 Apr 2023 13:02:33 +0200 Subject: [PATCH 1/2] Show error message when an old VAE encoder is used. --- swift/StableDiffusion/pipeline/Encoder.swift | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/swift/StableDiffusion/pipeline/Encoder.swift b/swift/StableDiffusion/pipeline/Encoder.swift index 45789e6c..16cf0d71 100644 --- a/swift/StableDiffusion/pipeline/Encoder.swift +++ b/swift/StableDiffusion/pipeline/Encoder.swift @@ -93,7 +93,20 @@ public struct Encoder: ResourceManaging { var inputDescription: MLFeatureDescription { try! model.perform { model in - model.modelDescription.inputDescriptionsByName["z"]! + guard let zInputDescription = model.modelDescription.inputDescriptionsByName["z"] else { + let modelVersion = model.modelDescription.metadata[MLModelMetadataKey.versionString] ?? "unknown version" + fatalError( + """ + + The VAE encoder of this model (\(modelVersion)) is not compatible \ + with this version of `ml-stable-diffusion`. Please, convert the VAE encoder again using the latest \ + version of this package and following the instructions here: \ + https://github.com/apple/ml-stable-diffusion#-converting-models-to-core-ml + We'd appreciate if you could then submit the new VAE as a PR to the repo from which this model \ + was downloaded. + """) + } + return zInputDescription } } From 6e75c893b4462e9c3b1b927565ec7ac97e216661 Mon Sep 17 00:00:00 2001 From: Pedro Cuenca Date: Sun, 30 Apr 2023 14:09:22 +0200 Subject: [PATCH 2/2] Update message --- swift/StableDiffusion/pipeline/Encoder.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swift/StableDiffusion/pipeline/Encoder.swift b/swift/StableDiffusion/pipeline/Encoder.swift index 16cf0d71..09b28d7f 100644 --- a/swift/StableDiffusion/pipeline/Encoder.swift +++ b/swift/StableDiffusion/pipeline/Encoder.swift @@ -102,7 +102,7 @@ public struct Encoder: ResourceManaging { with this version of `ml-stable-diffusion`. Please, convert the VAE encoder again using the latest \ version of this package and following the instructions here: \ https://github.com/apple/ml-stable-diffusion#-converting-models-to-core-ml - We'd appreciate if you could then submit the new VAE as a PR to the repo from which this model \ + We'd appreciate if you could then submit the new VAE encoder as a PR to the repo from which this model \ was downloaded. """) }