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

Switch to GuernikaCore #403

Open
wants to merge 51 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
fb463dc
Switch to GuernikaCore
czkoko Feb 17, 2024
04633a3
The final version
czkoko Feb 23, 2024
1cef239
Revert exec bit
godly-devotion Feb 23, 2024
05d8f4a
Update Mochi Diffusion/Views/SettingsView.swift
godly-devotion Feb 23, 2024
49d963b
Update Mochi Diffusion/Views/InspectorView.swift
godly-devotion Feb 23, 2024
8bf539f
Update Mochi Diffusion/Support/Functions.swift
godly-devotion Feb 23, 2024
27d56a9
Update Mochi Diffusion/Support/ImageGenerator.swift
czkoko Feb 25, 2024
ca0c527
Update Mochi Diffusion/Views/JobQueueView.swift
czkoko Feb 25, 2024
a380b74
Preview image quality switching
czkoko Feb 25, 2024
8b14263
Fixed some display problems in the drawing interface.
czkoko Feb 25, 2024
7a40cea
Better match with ControlNet, T2IAdapter
czkoko Feb 25, 2024
953ac7e
Convenient width and height switching
czkoko Feb 25, 2024
2eda3c6
GuernikaKit return to the old version.
czkoko Feb 25, 2024
14ae1a6
Use the correct version of GuernikaKit
czkoko Feb 25, 2024
7baf236
Force to enable reduceMemory
czkoko Feb 25, 2024
5a42c4f
update GuernikaKit to v1.6.1
czkoko Feb 26, 2024
6117ef0
Gallery Item Optimize
czkoko Feb 27, 2024
b79964e
Better model recognition
czkoko Feb 27, 2024
19e35ed
Fixed various size mismatches.
czkoko Feb 27, 2024
8ce120f
Fix the problem of the model path with spaces
czkoko Feb 27, 2024
661ccc6
Fix compatibility with previous pictures of Metadata information
czkoko Feb 27, 2024
6ad1ee1
Infrequently used samplers have been added to prevent anyone from wan…
czkoko Feb 27, 2024
4eaf90b
Fix the scaling of the drawing interface
czkoko Feb 27, 2024
570d716
Guard unwrap controltype
gdbing Feb 27, 2024
939bb5e
Better drawing interface scaling
czkoko Feb 27, 2024
31b3aa9
Merge branch 'GuernikaCore' of https://github.com/czkoko/MochiDiffusi…
czkoko Feb 27, 2024
0ff2b3a
Solved a problem left over from the drawing interface
czkoko Feb 28, 2024
ea589b4
Optimize hack VAE
czkoko Feb 29, 2024
eee8912
Fix ControlNet and T2IAdapter
czkoko Mar 1, 2024
867a415
Filter incompatible old models
czkoko Mar 2, 2024
c6ee7a6
add style prompt presets
czkoko Mar 5, 2024
61d2990
Use guard statements to unwrap metadata
gdbing Mar 5, 2024
b35143e
Fix typo ancenstral -> ancestral
gdbing Mar 5, 2024
c6ec820
Don't force unwrap strength
gdbing Mar 5, 2024
0956749
Clean up duplicate maskImage
gdbing Mar 6, 2024
79dde98
Remove references to ImageController.shared within ImageController
gdbing Mar 6, 2024
ba76fe4
Update Mochi Diffusion/Support/ImageController.swift
czkoko Mar 6, 2024
b828b88
Restore typo
gdbing Mar 7, 2024
d392145
Move pipeline caching logic out of ImageGenerator
gdbing Mar 5, 2024
8809a6c
Move modifyInputSize call to ImageController
gdbing Mar 7, 2024
7df1f07
Revert project codesigning
gdbing Feb 26, 2024
8bdf470
Revert "add style prompt presets"
gdbing Mar 9, 2024
032c1df
Revert removal of SwiftLint
gdbing Mar 9, 2024
82a5bd2
Run SwiftLint
gdbing Mar 9, 2024
d442216
Refactor
gdbing Mar 11, 2024
a52a90e
Revert change to xcscheme
gdbing Mar 11, 2024
c24f0fe
Revert changes to GalleryView appearance
gdbing Mar 11, 2024
6b64a92
Simplify pipeline cache logic
gdbing Mar 12, 2024
5ffdcc2
Refactor resizing logic
gdbing Mar 12, 2024
c844661
Copy variable size models to temp folder
gdbing Mar 13, 2024
1219b1d
Merge pull request #4 from gdbing/GuernikaCore+fixes
czkoko Mar 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
83 changes: 46 additions & 37 deletions Mochi Diffusion.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
03173C132999E2B500B03456 /* SDModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03173C122999E2B500B03456 /* SDModel.swift */; };
03173C152999F5C700B03456 /* ImageController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03173C142999F5C700B03456 /* ImageController.swift */; };
03173C18299B3C1300B03456 /* ImageStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03173C17299B3C1300B03456 /* ImageStore.swift */; };
0352E2A5294E2591003FBF25 /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = 0352E2A4294E2591003FBF25 /* Sparkle */; };
0352E2A7294E3148003FBF25 /* HelpCommands.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0352E2A6294E3148003FBF25 /* HelpCommands.swift */; };
0352E2AA294EA0E1003FBF25 /* AppView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0352E2A9294EA0E1003FBF25 /* AppView.swift */; };
0352E2AE294EA2B4003FBF25 /* MessageBanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0352E2AD294EA2B4003FBF25 /* MessageBanner.swift */; };
Expand All @@ -40,7 +39,6 @@
0386DF8D2950F25500CA4CEB /* GalleryToolbarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0386DF8C2950F25500CA4CEB /* GalleryToolbarView.swift */; };
0388DEB0297B00FC008B1C1C /* CompactSlider in Frameworks */ = {isa = PBXBuildFile; productRef = 0388DEAF297B00FC008B1C1C /* CompactSlider */; };
0395B3112995C70400465B73 /* Scheduler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0395B3102995C70400465B73 /* Scheduler.swift */; };
03ADC8B9299581AF00B2843F /* StableDiffusion in Frameworks */ = {isa = PBXBuildFile; productRef = 03ADC8B8299581AF00B2843F /* StableDiffusion */; };
03B1ACA8295167B900302F54 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03B1ACA7295167B900302F54 /* SettingsView.swift */; };
03CB9D18297399AE0041A4FA /* ImageCommands.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CB9D17297399AE0041A4FA /* ImageCommands.swift */; };
03D280F2294FD60E00C7D184 /* PromptView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D280F1294FD60E00C7D184 /* PromptView.swift */; };
Expand All @@ -61,6 +59,10 @@
C1220FC02AFB122F007E5055 /* ImageWellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1220FBF2AFB122F007E5055 /* ImageWellView.swift */; };
C1ADEC2C2B16957800E142CA /* FolderMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1ADEC2B2B16957800E142CA /* FolderMonitor.swift */; };
D7B03F2029D42F9900DF89DD /* SDModelAttentionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7B03F1F29D42F9900DF89DD /* SDModelAttentionType.swift */; };
E45FA5822B7F7E4B009E90F0 /* GuernikaKit in Frameworks */ = {isa = PBXBuildFile; productRef = E45FA5812B7F7E4B009E90F0 /* GuernikaKit */; };
E4EC46322B890B6D00351E8C /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = E4EC46312B890B6D00351E8C /* Sparkle */; };
E4F15B1D2B86720F00E1EC3C /* de-coremldata.bin in Resources */ = {isa = PBXBuildFile; fileRef = E4F15B1C2B86720F00E1EC3C /* de-coremldata.bin */; };
E4F15B1F2B8673DB00E1EC3C /* en-coremldata.bin in Resources */ = {isa = PBXBuildFile; fileRef = E4F15B1E2B8673DB00E1EC3C /* en-coremldata.bin */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -132,6 +134,8 @@
C1220FBF2AFB122F007E5055 /* ImageWellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageWellView.swift; sourceTree = "<group>"; };
C1ADEC2B2B16957800E142CA /* FolderMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FolderMonitor.swift; sourceTree = "<group>"; };
D7B03F1F29D42F9900DF89DD /* SDModelAttentionType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SDModelAttentionType.swift; sourceTree = "<group>"; };
E4F15B1C2B86720F00E1EC3C /* de-coremldata.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; path = "de-coremldata.bin"; sourceTree = "<group>"; };
E4F15B1E2B8673DB00E1EC3C /* en-coremldata.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; path = "en-coremldata.bin"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -140,8 +144,8 @@
buildActionMask = 2147483647;
files = (
036BFC4E294B9FDB00D8AD04 /* Path in Frameworks */,
03ADC8B9299581AF00B2843F /* StableDiffusion in Frameworks */,
0352E2A5294E2591003FBF25 /* Sparkle in Frameworks */,
E4EC46322B890B6D00351E8C /* Sparkle in Frameworks */,
E45FA5822B7F7E4B009E90F0 /* GuernikaKit in Frameworks */,
0388DEB0297B00FC008B1C1C /* CompactSlider in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -275,6 +279,8 @@
isa = PBXGroup;
children = (
036BFC25294B9F7600D8AD04 /* Assets.xcassets */,
E4F15B1E2B8673DB00E1EC3C /* en-coremldata.bin */,
E4F15B1C2B86720F00E1EC3C /* de-coremldata.bin */,
03FD2318295F74B6006EEEE2 /* RealESRGAN.mlmodel */,
);
path = Resources;
Expand All @@ -299,9 +305,9 @@
name = "Mochi Diffusion";
packageProductDependencies = (
036BFC4D294B9FDB00D8AD04 /* Path */,
0352E2A4294E2591003FBF25 /* Sparkle */,
0388DEAF297B00FC008B1C1C /* CompactSlider */,
03ADC8B8299581AF00B2843F /* StableDiffusion */,
E45FA5812B7F7E4B009E90F0 /* GuernikaKit */,
E4EC46312B890B6D00351E8C /* Sparkle */,
);
productName = "Mochi Diffusion";
productReference = 036BFC1E294B9F7500D8AD04 /* Mochi Diffusion.app */;
Expand All @@ -315,7 +321,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1420;
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
TargetAttributes = {
036BFC1D294B9F7500D8AD04 = {
CreatedOnToolsVersion = 14.2;
Expand Down Expand Up @@ -368,9 +374,9 @@
mainGroup = 036BFC15294B9F7500D8AD04;
packageReferences = (
036BFC4C294B9FDB00D8AD04 /* XCRemoteSwiftPackageReference "Path.swift" */,
0352E2A3294E2591003FBF25 /* XCRemoteSwiftPackageReference "Sparkle" */,
0388DEAE297B00FC008B1C1C /* XCRemoteSwiftPackageReference "CompactSlider" */,
03ADC8B7299581AF00B2843F /* XCRemoteSwiftPackageReference "ml-stable-diffusion" */,
E45FA5802B7F7E4B009E90F0 /* XCRemoteSwiftPackageReference "GuernikaKit" */,
E4EC46302B890B6D00351E8C /* XCRemoteSwiftPackageReference "Sparkle" */,
);
productRefGroup = 036BFC1F294B9F7500D8AD04 /* Products */;
projectDirPath = "";
Expand All @@ -390,6 +396,8 @@
03F578642967CE9A003A815F /* Localizable.strings in Resources */,
0311C6BD2989E3EF0074BCAE /* Localizable.stringsdict in Resources */,
036BFC26294B9F7600D8AD04 /* Assets.xcassets in Resources */,
E4F15B1F2B8673DB00E1EC3C /* en-coremldata.bin in Resources */,
E4F15B1D2B86720F00E1EC3C /* de-coremldata.bin in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -512,7 +520,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = arm64;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
Expand Down Expand Up @@ -547,6 +554,7 @@
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -576,7 +584,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = arm64;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
Expand Down Expand Up @@ -611,6 +618,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand All @@ -622,6 +630,7 @@
MACOSX_DEPLOYMENT_TARGET = 14.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -638,10 +647,10 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5.0;
CURRENT_PROJECT_VERSION = 6.0;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Mochi Diffusion/Preview Content\"";
DEVELOPMENT_TEAM = TCQ6328PP6;
DEVELOPMENT_TEAM = "TCQ6328PP6";
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -653,7 +662,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 5.0;
MARKETING_VERSION = 6.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.joshua-park.Mochi-Diffusion";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -671,10 +680,10 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5.0;
CURRENT_PROJECT_VERSION = 6.0;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Mochi Diffusion/Preview Content\"";
DEVELOPMENT_TEAM = TCQ6328PP6;
DEVELOPMENT_TEAM = "TCQ6328PP6";
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -686,7 +695,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 5.0;
MARKETING_VERSION = 6.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.joshua-park.Mochi-Diffusion";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -719,14 +728,6 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
0352E2A3294E2591003FBF25 /* XCRemoteSwiftPackageReference "Sparkle" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/sparkle-project/Sparkle";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 2.0.0;
};
};
036BFC4C294B9FDB00D8AD04 /* XCRemoteSwiftPackageReference "Path.swift" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/mxcl/Path.swift.git";
Expand All @@ -743,22 +744,25 @@
minimumVersion = 1.0.0;
};
};
03ADC8B7299581AF00B2843F /* XCRemoteSwiftPackageReference "ml-stable-diffusion" */ = {
E45FA5802B7F7E4B009E90F0 /* XCRemoteSwiftPackageReference "GuernikaKit" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/apple/ml-stable-diffusion";
repositoryURL = "https://github.com/GuernikaCore/GuernikaKit.git";
requirement = {
branch = main;
kind = branch;
kind = exactVersion;
version = 1.6.1;
};
};
E4EC46302B890B6D00351E8C /* XCRemoteSwiftPackageReference "Sparkle" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/sparkle-project/Sparkle.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 2.5.2;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
0352E2A4294E2591003FBF25 /* Sparkle */ = {
isa = XCSwiftPackageProductDependency;
package = 0352E2A3294E2591003FBF25 /* XCRemoteSwiftPackageReference "Sparkle" */;
productName = Sparkle;
};
036BFC4D294B9FDB00D8AD04 /* Path */ = {
isa = XCSwiftPackageProductDependency;
package = 036BFC4C294B9FDB00D8AD04 /* XCRemoteSwiftPackageReference "Path.swift" */;
Expand All @@ -769,10 +773,15 @@
package = 0388DEAE297B00FC008B1C1C /* XCRemoteSwiftPackageReference "CompactSlider" */;
productName = CompactSlider;
};
03ADC8B8299581AF00B2843F /* StableDiffusion */ = {
E45FA5812B7F7E4B009E90F0 /* GuernikaKit */ = {
isa = XCSwiftPackageProductDependency;
package = E45FA5802B7F7E4B009E90F0 /* XCRemoteSwiftPackageReference "GuernikaKit" */;
productName = GuernikaKit;
};
E4EC46312B890B6D00351E8C /* Sparkle */ = {
isa = XCSwiftPackageProductDependency;
package = 03ADC8B7299581AF00B2843F /* XCRemoteSwiftPackageReference "ml-stable-diffusion" */;
productName = StableDiffusion;
package = E4EC46302B890B6D00351E8C /* XCRemoteSwiftPackageReference "Sparkle" */;
productName = Sparkle;
};
/* End XCSwiftPackageProductDependency section */
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
}
},
{
"identity" : "ml-stable-diffusion",
"identity" : "guernikakit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/ml-stable-diffusion",
"location" : "https://github.com/GuernikaCore/GuernikaKit.git",
"state" : {
"branch" : "main",
"revision" : "d456a972cd7d84cab2ec353a29896d59b8602248"
"revision" : "500b1f80ca14159afe7a9d14b7ce100413a568fc",
"version" : "1.6.1"
}
},
{
Expand All @@ -28,21 +28,30 @@
}
},
{
"identity" : "sparkle",
"identity" : "randomgenerator",
"kind" : "remoteSourceControl",
"location" : "https://github.com/sparkle-project/Sparkle",
"location" : "https://github.com/GuernikaCore/RandomGenerator.git",
"state" : {
"revision" : "47d3d90aee3c52b6f61d04ceae426e607df62347",
"version" : "2.5.2"
"revision" : "7c91e2f454ecc753075a526cf5ffc34d3c4a10c5",
"version" : "1.0.0"
}
},
{
"identity" : "swift-argument-parser",
"identity" : "schedulers",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"location" : "https://github.com/GuernikaCore/Schedulers.git",
"state" : {
"revision" : "fddd1c00396eed152c45a46bea9f47b98e59301d",
"version" : "1.2.0"
"revision" : "1f517514d679e38bb9915c3a74bf04f75d5b5875",
"version" : "1.4.0"
}
},
{
"identity" : "sparkle",
"kind" : "remoteSourceControl",
"location" : "https://github.com/sparkle-project/Sparkle.git",
"state" : {
"revision" : "47d3d90aee3c52b6f61d04ceae426e607df62347",
"version" : "2.5.2"
}
}
],
Expand Down
4 changes: 4 additions & 0 deletions Mochi Diffusion/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ struct MochiDiffusionApp: App {
/// cleanup MPS temp folder
let mpsURL = FileManager.default.temporaryDirectory.appendingPathComponent("com.apple.MetalPerformanceShadersGraph", isDirectory: true)
try? FileManager.default.removeItem(at: mpsURL)
/// cleanup modified variable size models
if let variableSizeModelDir = controller.variableSizeModelDir {
try? FileManager.default.removeItem(at: variableSizeModelDir)
}
}
}
.commands {
Expand Down
43 changes: 40 additions & 3 deletions Mochi Diffusion/Model/SDControlNet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,28 @@
import CoreGraphics
import Foundation

enum ControlType {
case controlNet
case t2IAdapter
case all
}

struct SDControlNet {
let name: String
let url: URL
let size: CGSize
let attention: SDModelAttentionType
let controltype: ControlType

init?(url: URL) {
guard let size = identifyControlNetSize(url), let attention = identifyControlNetAttentionType(url) else {
guard let size = identifyControlNetSize(url), let attention = identifyControlNetAttentionType(url), let type = identifyControlNetType(url) else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to get some clarification on how ControlNets work now

  • Are ControlNets still fixed size or variable?
  • If they are fixed size, how do they work (do they work?) with variable size models?
  • There is logic in SDModel which filters the available ControlNets by size, is this still a reasonable thing to do? Should they be filtered by the model's "input size" or by the generation dimensions?
  • how do T2IAdapters differ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ControlNet and T2IAdapter can be compatible with any shape in the conversion using variable resolution.

return nil
}

self.name = url.deletingPathExtension().lastPathComponent
self.url = url
self.size = size
self.attention = attention
self.controltype = type
}
}

Expand All @@ -49,7 +56,7 @@ private func identifyControlNetSize(_ url: URL) -> CGSize? {
return nil
}

guard let controlnetCond = inputSchema.first(where: { ($0["name"] as? String) == "controlnet_cond" }) else {
guard let controlnetCond = inputSchema.first(where: { ($0["name"] as? String) == "controlnet_cond" }) ?? inputSchema.first(where: { ($0["name"] as? String) == "input" }) else {
gdbing marked this conversation as resolved.
Show resolved Hide resolved
print("Error: 'controlnet_cond' not found in 'inputSchema'")
return nil
}
Expand Down Expand Up @@ -96,3 +103,33 @@ private func identifyControlNetAttentionType(_ url: URL) -> SDModelAttentionType
return nil
}
}

private func identifyControlNetType(_ url: URL) -> ControlType? {
let metadataURL = url.appendingPathComponent("metadata.json")

guard let jsonData = try? Data(contentsOf: metadataURL) else {
print("Error: Could not read data from \(metadataURL)")
return nil
}

guard let jsonArray = (try? JSONSerialization.jsonObject(with: jsonData)) as? [[String: Any]] else {
print("Error: Could not parse JSON data")
return nil
}

guard let jsonItem = jsonArray.first else {
print("Error: JSON array is empty")
return nil
}

guard let inputSchema = jsonItem["inputSchema"] as? [[String: Any]] else {
print("Error: Missing 'inputSchema' in JSON")
return nil
}

if inputSchema.first(where: { ($0["name"] as? String) == "controlnet_cond" }) != nil {
return .controlNet
} else {
return .t2IAdapter
}
}