add: reduceMemory = true for ml-stable-diffusion v0.1.0.

main
Yasuhito Nagatomo 1 year ago
parent 853679a826
commit 102a6c79df

@ -5,8 +5,8 @@
A minimal iOS app that generates images using Stable Diffusion v2. A minimal iOS app that generates images using Stable Diffusion v2.
You can create images specifying any prompt (text) such as "a photo of an astronaut riding a horse on mars". You can create images specifying any prompt (text) such as "a photo of an astronaut riding a horse on mars".
- macOS 13.1 RC or newer, Xcode 14.2 or newer - macOS 13.1 or newer, Xcode 14.2 or newer
- iPhone 12+ / iOS 16.2 RC or newer, iPad Pro with M1/M2 / iPadOS 16.2 RC or newer - iPhone Pro 12+ / iOS 16.2 or newer, iPad Pro with M1/M2 / iPadOS 16.2 or newer
You can run the app on above mobile devices. You can run the app on above mobile devices.
And you can run the app on Mac, building as a Designed for iPad app. And you can run the app on Mac, building as a Designed for iPad app.
@ -26,6 +26,12 @@ You can see how it works through the simple sample code.
## Change Log ## Change Log
- [1.0.2 (3)] - 2022-12-16 `[Changed]`
- The apple/ml-stable-diffusion Swift Package v0.1.0 was released.
- At apple/ml-stable-diffusion Swift Package v0.1.0, `reduceMemory` option of StableDiffusionPipeline(resourcesAt:)
was added. And on iOS, the reduceMemory option should be set to true.
- This option was added and set to true, in `ImageGenerator.swift` when creating StableDiffusionPipeline.
- According to the new apple readme, iPhone requirement was changed to iPhone Pro 12+.
- [1.0.1 (2)] - 2022-12-08 `[Changed]` - [1.0.1 (2)] - 2022-12-08 `[Changed]`
- Changed to delay creation of `StableDiffusionPipeline` until the first image - Changed to delay creation of `StableDiffusionPipeline` until the first image
generation and execute it in a background task. generation and execute it in a background task.

@ -7,12 +7,12 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
BA01CAE9294C92FC00C89D87 /* StableDiffusion in Frameworks */ = {isa = PBXBuildFile; productRef = BA01CAE8294C92FC00C89D87 /* StableDiffusion */; };
BA03C378293D785C001426DE /* imggensd2App.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA03C377293D785C001426DE /* imggensd2App.swift */; }; BA03C378293D785C001426DE /* imggensd2App.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA03C377293D785C001426DE /* imggensd2App.swift */; };
BA03C37A293D785C001426DE /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA03C379293D785C001426DE /* ContentView.swift */; }; BA03C37A293D785C001426DE /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA03C379293D785C001426DE /* ContentView.swift */; };
BA03C37C293D785D001426DE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BA03C37B293D785D001426DE /* Assets.xcassets */; }; BA03C37C293D785D001426DE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BA03C37B293D785D001426DE /* Assets.xcassets */; };
BA03C37F293D785D001426DE /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BA03C37E293D785D001426DE /* Preview Assets.xcassets */; }; BA03C37F293D785D001426DE /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BA03C37E293D785D001426DE /* Preview Assets.xcassets */; };
BA03C388293D80A4001426DE /* CoreMLModels in Resources */ = {isa = PBXBuildFile; fileRef = BA03C387293D80A4001426DE /* CoreMLModels */; }; BA03C388293D80A4001426DE /* CoreMLModels in Resources */ = {isa = PBXBuildFile; fileRef = BA03C387293D80A4001426DE /* CoreMLModels */; };
BA03C38B293D8362001426DE /* StableDiffusion in Frameworks */ = {isa = PBXBuildFile; productRef = BA03C38A293D8362001426DE /* StableDiffusion */; };
BA03C38D293D8773001426DE /* ImageGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA03C38C293D8773001426DE /* ImageGenerator.swift */; }; BA03C38D293D8773001426DE /* ImageGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA03C38C293D8773001426DE /* ImageGenerator.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
@ -32,7 +32,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
BA03C38B293D8362001426DE /* StableDiffusion in Frameworks */, BA01CAE9294C92FC00C89D87 /* StableDiffusion in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -95,7 +95,7 @@
); );
name = imggensd2; name = imggensd2;
packageProductDependencies = ( packageProductDependencies = (
BA03C38A293D8362001426DE /* StableDiffusion */, BA01CAE8294C92FC00C89D87 /* StableDiffusion */,
); );
productName = imggensd2; productName = imggensd2;
productReference = BA03C374293D785C001426DE /* imggensd2.app */; productReference = BA03C374293D785C001426DE /* imggensd2.app */;
@ -126,7 +126,7 @@
); );
mainGroup = BA03C36B293D785C001426DE; mainGroup = BA03C36B293D785C001426DE;
packageReferences = ( packageReferences = (
BA03C389293D8362001426DE /* XCRemoteSwiftPackageReference "ml-stable-diffusion" */, BA01CAE7294C92FB00C89D87 /* XCRemoteSwiftPackageReference "ml-stable-diffusion" */,
); );
productRefGroup = BA03C375293D785C001426DE /* Products */; productRefGroup = BA03C375293D785C001426DE /* Products */;
projectDirPath = ""; projectDirPath = "";
@ -305,7 +305,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2; CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_ASSET_PATHS = "\"imggensd2/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"imggensd2/Preview Content\"";
DEVELOPMENT_TEAM = J5CY9Q9UP5; DEVELOPMENT_TEAM = J5CY9Q9UP5;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
@ -316,11 +316,12 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 16.2;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.0.1; MARKETING_VERSION = 1.0.2;
PRODUCT_BUNDLE_IDENTIFIER = com.atarayosd.imggensd2; PRODUCT_BUNDLE_IDENTIFIER = com.atarayosd.imggensd2;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_EMIT_LOC_STRINGS = YES;
@ -335,7 +336,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2; CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_ASSET_PATHS = "\"imggensd2/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"imggensd2/Preview Content\"";
DEVELOPMENT_TEAM = J5CY9Q9UP5; DEVELOPMENT_TEAM = J5CY9Q9UP5;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
@ -346,11 +347,12 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 16.2;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.0.1; MARKETING_VERSION = 1.0.2;
PRODUCT_BUNDLE_IDENTIFIER = com.atarayosd.imggensd2; PRODUCT_BUNDLE_IDENTIFIER = com.atarayosd.imggensd2;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_EMIT_LOC_STRINGS = YES;
@ -383,7 +385,7 @@
/* End XCConfigurationList section */ /* End XCConfigurationList section */
/* Begin XCRemoteSwiftPackageReference section */ /* Begin XCRemoteSwiftPackageReference section */
BA03C389293D8362001426DE /* XCRemoteSwiftPackageReference "ml-stable-diffusion" */ = { BA01CAE7294C92FB00C89D87 /* XCRemoteSwiftPackageReference "ml-stable-diffusion" */ = {
isa = XCRemoteSwiftPackageReference; isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/apple/ml-stable-diffusion#swift-requirements"; repositoryURL = "https://github.com/apple/ml-stable-diffusion#swift-requirements";
requirement = { requirement = {
@ -394,9 +396,9 @@
/* End XCRemoteSwiftPackageReference section */ /* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */ /* Begin XCSwiftPackageProductDependency section */
BA03C38A293D8362001426DE /* StableDiffusion */ = { BA01CAE8294C92FC00C89D87 /* StableDiffusion */ = {
isa = XCSwiftPackageProductDependency; isa = XCSwiftPackageProductDependency;
package = BA03C389293D8362001426DE /* XCRemoteSwiftPackageReference "ml-stable-diffusion" */; package = BA01CAE7294C92FB00C89D87 /* XCRemoteSwiftPackageReference "ml-stable-diffusion" */;
productName = StableDiffusion; productName = StableDiffusion;
}; };
/* End XCSwiftPackageProductDependency section */ /* End XCSwiftPackageProductDependency section */

@ -6,7 +6,7 @@
"location" : "https://github.com/apple/ml-stable-diffusion#swift-requirements", "location" : "https://github.com/apple/ml-stable-diffusion#swift-requirements",
"state" : { "state" : {
"branch" : "main", "branch" : "main",
"revision" : "583cc04ece3dce9e1e8d44449f58d2eb7edef11c" "revision" : "66dde8da135593eccef7bbb3a329ccf7bb1724d3"
} }
}, },
{ {

@ -77,7 +77,10 @@ final class ImageGenerator: ObservableObject {
} }
let resourceURL = URL(fileURLWithPath: path) let resourceURL = URL(fileURLWithPath: path)
if let pipeline = try? StableDiffusionPipeline(resourcesAt: resourceURL) { // reduceMemory option was added at v0.1.0
// On iOS, the reduceMemory option should be set to true
if let pipeline = try? StableDiffusionPipeline(resourcesAt: resourceURL,
reduceMemory: true) {
await self.setPipeline(pipeline) await self.setPipeline(pipeline)
} else { } else {
fatalError("Fatal error: failed to create the Stable-Diffusion-Pipeline.") fatalError("Fatal error: failed to create the Stable-Diffusion-Pipeline.")

Loading…
Cancel
Save