bleam 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai.cjs +1872 -1182
- package/dist/ai.d.cts +267 -234
- package/dist/ai.d.ts +267 -234
- package/dist/ai.js +1859 -1167
- package/dist/cli.cjs +3 -183
- package/dist/cli.d.cts +3 -47
- package/dist/cli.d.ts +3 -47
- package/dist/cli.js +3 -183
- package/dist/config.d.cts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/{files-Ds1wT8C2.js → files-BXVkPrPN.js} +6 -1
- package/dist/{files-Bo7h9fik.cjs → files-DxaQ-Nv0.cjs} +11 -0
- package/dist/files.cjs +1 -1
- package/dist/files.js +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/platform.cjs +1 -13
- package/dist/platform.d.cts +1 -28
- package/dist/platform.d.ts +1 -28
- package/dist/platform.js +1 -10
- package/dist/schema-B5BfdswF.js +226 -0
- package/dist/schema-BnVZOXfu.cjs +286 -0
- package/dist/schema-D5eImHxu.d.cts +125 -0
- package/dist/schema-SSjokbtw.d.ts +125 -0
- package/dist/schema.cjs +10 -2
- package/dist/schema.d.cts +2 -2
- package/dist/schema.d.ts +2 -2
- package/dist/schema.js +2 -2
- package/dist/state-Dh3HLixb.js +874 -0
- package/dist/state-LssDgpff.cjs +973 -0
- package/dist/state.cjs +16 -12
- package/dist/state.d.cts +144 -140
- package/dist/state.d.ts +145 -140
- package/dist/state.js +3 -3
- package/dist/{ui-Bg11tvlc.d.ts → ui-1WepaMS4.d.cts} +1 -1
- package/dist/{ui-Dd7SXdbg.d.cts → ui-D7bRLYee.d.ts} +7 -7
- package/dist/ui.d.cts +1 -1
- package/dist/ui.d.ts +1 -1
- package/dist/window.d.cts +1 -1
- package/dist/window.d.ts +1 -1
- package/package.json +3 -1
- package/templates/foundation-models/app/index.tsx +77 -15
- package/templates/image-generation/app/index.tsx +4 -2
- package/templates/native/ios/Bleam/AI/Flux2/Configuration/ModelRegistry.swift +1 -1
- package/templates/native/ios/Bleam/AI/Flux2/Pipeline/FluxImageRunner.swift +7 -2
- package/templates/native/ios/Bleam/AI/TextGeneration/Bonsai/BonsaiTextGenerator.swift +46 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Bonsai/BonsaiTextModel.swift +107 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Bonsai/BonsaiTextSnapshotValidator.swift +201 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Core/GenerationTypes.swift +85 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Core/ModelCapabilities.swift +21 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Core/TextKVCache.swift +23 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Core/TokenSampler.swift +79 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Qwen3/Qwen3CheckpointLoader.swift +161 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Qwen3/Qwen3Configuration.swift +119 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Qwen3/Qwen3InferenceSession.swift +84 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Qwen3/Qwen3Layers.swift +197 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Qwen3/Qwen3Model.swift +130 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Qwen35/Qwen35Checkpoint.swift +102 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Qwen35/Qwen35Configuration.swift +140 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Qwen35/Qwen35Model.swift +112 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/Qwen35/Qwen35Session.swift +121 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/QwenHybrid/QwenHybridCache.swift +42 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/QwenHybrid/QwenHybridFullAttention.swift +57 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/QwenHybrid/QwenHybridLayers.swift +58 -0
- package/templates/native/ios/Bleam/AI/TextGeneration/QwenHybrid/QwenHybridLinearAttention.swift +111 -0
- package/templates/native/ios/Bleam/AppDelegate.swift +0 -206
- package/templates/native/ios/Bleam.xcodeproj/project.pbxproj +135 -129
- package/templates/native/ios/GenerationService/BonsaiTextGenerationRunner.swift +103 -0
- package/templates/native/ios/GenerationService/ImageGenerationRunner.swift +19 -7
- package/templates/native/ios/GenerationService/main.swift +174 -48
- package/templates/native/ios/Podfile.lock +173 -173
- package/templates/native/ios/Shared/Generation/GenerationServiceProtocol.swift +3 -0
- package/templates/native/ios/Shared/Generation/GenerationWorkerProtocol.swift +44 -0
- package/templates/native/modules/bleam-runtime/ios/AIModule.swift +239 -341
- package/templates/native/modules/bleam-runtime/ios/GenerationContracts.swift +47 -0
- package/templates/native/modules/bleam-runtime/ios/PlatformModule.swift +0 -191
- package/templates/text-generation/app/index.tsx +124 -0
- package/templates/text-generation/app.config.ts +5 -0
- package/templates/updates/README.md +43 -199
- package/templates/updates/src/index.ts +5 -98
- package/templates/updates/src/schema.ts +18 -173
- package/dist/schema-Bo5Jvqus.js +0 -90
- package/dist/schema-DOOjfXvs.d.ts +0 -58
- package/dist/schema-ENSMX_1t.d.cts +0 -58
- package/dist/schema-rQ13mrpD.cjs +0 -102
- package/dist/state-Bx0VlTlO.cjs +0 -852
- package/dist/state-CAwe-Vw1.js +0 -767
- package/templates/native/ios/PlatformHelper/main.swift +0 -726
- /package/dist/{config-Cms0rvqg.d.ts → config-COcRnn5a.d.cts} +0 -0
- /package/dist/{config-CufOVJV3.d.cts → config-Chi-flpJ.d.ts} +0 -0
|
@@ -57,12 +57,31 @@
|
|
|
57
57
|
B957694592E7EBD326D03A2F /* FlowMatchEulerScheduler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D1000102F00000000000010 /* FlowMatchEulerScheduler.swift */; };
|
|
58
58
|
BB2F792D24A3F905000567C9 /* Expo.plist in Resources */ = {isa = PBXBuildFile; fileRef = BB2F792C24A3F905000567C9 /* Expo.plist */; };
|
|
59
59
|
C0E15CD5E6F368701D5653B0 /* Flux2SingleBlock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D1000212F00000000000021 /* Flux2SingleBlock.swift */; };
|
|
60
|
+
C30000000000000000000001 /* ModelCapabilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = C20000000000000000000001 /* ModelCapabilities.swift */; };
|
|
61
|
+
C30000000000000000000002 /* GenerationTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = C20000000000000000000002 /* GenerationTypes.swift */; };
|
|
62
|
+
C30000000000000000000003 /* TokenSampler.swift in Sources */ = {isa = PBXBuildFile; fileRef = C20000000000000000000003 /* TokenSampler.swift */; };
|
|
63
|
+
C30000000000000000000004 /* TextKVCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = C20000000000000000000004 /* TextKVCache.swift */; };
|
|
64
|
+
C30000000000000000000005 /* Qwen3CheckpointLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = C20000000000000000000005 /* Qwen3CheckpointLoader.swift */; };
|
|
65
|
+
C30000000000000000000006 /* Qwen3Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = C20000000000000000000006 /* Qwen3Configuration.swift */; };
|
|
66
|
+
C30000000000000000000007 /* Qwen3Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = C20000000000000000000007 /* Qwen3Model.swift */; };
|
|
67
|
+
C30000000000000000000008 /* Qwen3InferenceSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = C20000000000000000000008 /* Qwen3InferenceSession.swift */; };
|
|
68
|
+
C30000000000000000000009 /* Qwen3Layers.swift in Sources */ = {isa = PBXBuildFile; fileRef = C20000000000000000000009 /* Qwen3Layers.swift */; };
|
|
69
|
+
C3000000000000000000000A /* QwenHybridFullAttention.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2000000000000000000000A /* QwenHybridFullAttention.swift */; };
|
|
70
|
+
C3000000000000000000000B /* QwenHybridLayers.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2000000000000000000000B /* QwenHybridLayers.swift */; };
|
|
71
|
+
C3000000000000000000000C /* QwenHybridLinearAttention.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2000000000000000000000C /* QwenHybridLinearAttention.swift */; };
|
|
72
|
+
C3000000000000000000000D /* QwenHybridCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2000000000000000000000D /* QwenHybridCache.swift */; };
|
|
73
|
+
C3000000000000000000000E /* Qwen35Session.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2000000000000000000000E /* Qwen35Session.swift */; };
|
|
74
|
+
C3000000000000000000000F /* Qwen35Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2000000000000000000000F /* Qwen35Configuration.swift */; };
|
|
75
|
+
C30000000000000000000010 /* Qwen35Checkpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = C20000000000000000000010 /* Qwen35Checkpoint.swift */; };
|
|
76
|
+
C30000000000000000000011 /* Qwen35Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = C20000000000000000000011 /* Qwen35Model.swift */; };
|
|
77
|
+
C30000000000000000000012 /* BonsaiTextSnapshotValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = C20000000000000000000012 /* BonsaiTextSnapshotValidator.swift */; };
|
|
78
|
+
C30000000000000000000013 /* BonsaiTextModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C20000000000000000000013 /* BonsaiTextModel.swift */; };
|
|
79
|
+
C30000000000000000000014 /* BonsaiTextGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = C20000000000000000000014 /* BonsaiTextGenerator.swift */; };
|
|
80
|
+
C30000000000000000000015 /* BonsaiTextGenerationRunner.swift in Sources */ = {isa = PBXBuildFile; fileRef = C20000000000000000000015 /* BonsaiTextGenerationRunner.swift */; };
|
|
60
81
|
CA976FF294D23C5C0D1BCB6A /* MemoryManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D1000242F00000000000024 /* MemoryManager.swift */; };
|
|
61
82
|
D63D5719C5F6BEF2642A0627 /* GenerationWorkerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C1C083A847A6F08154A7655 /* GenerationWorkerProtocol.swift */; };
|
|
62
83
|
F11748422D0307B40044C1D9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F11748412D0307B40044C1D9 /* AppDelegate.swift */; };
|
|
63
84
|
F3E19B0AABF791129F5C2531 /* Flux2KVCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D1000122F00000000000012 /* Flux2KVCache.swift */; };
|
|
64
|
-
A10000000000000000000001 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10000000000000000000005 /* main.swift */; };
|
|
65
|
-
A10000000000000000000002 /* PlatformHelper in Embed Platform Helper */ = {isa = PBXBuildFile; fileRef = A10000000000000000000006 /* PlatformHelper */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
|
|
66
85
|
/* End PBXBuildFile section */
|
|
67
86
|
|
|
68
87
|
/* Begin PBXContainerItemProxy section */
|
|
@@ -73,13 +92,6 @@
|
|
|
73
92
|
remoteGlobalIDString = 8F04CB76A01E93A4B73D67A5;
|
|
74
93
|
remoteInfo = GenerationService;
|
|
75
94
|
};
|
|
76
|
-
A10000000000000000000003 /* PBXContainerItemProxy */ = {
|
|
77
|
-
isa = PBXContainerItemProxy;
|
|
78
|
-
containerPortal = 83CBB9F71A601CBA00E9B192 /* Project object */;
|
|
79
|
-
proxyType = 1;
|
|
80
|
-
remoteGlobalIDString = A1000000000000000000000A;
|
|
81
|
-
remoteInfo = PlatformHelper;
|
|
82
|
-
};
|
|
83
95
|
/* End PBXContainerItemProxy section */
|
|
84
96
|
|
|
85
97
|
/* Begin PBXCopyFilesBuildPhase section */
|
|
@@ -108,17 +120,6 @@
|
|
|
108
120
|
name = "Embed XPC Services";
|
|
109
121
|
runOnlyForDeploymentPostprocessing = 0;
|
|
110
122
|
};
|
|
111
|
-
A10000000000000000000010 /* Embed Platform Helper */ = {
|
|
112
|
-
isa = PBXCopyFilesBuildPhase;
|
|
113
|
-
buildActionMask = 2147483647;
|
|
114
|
-
dstPath = "$(CONTENTS_FOLDER_PATH)/Helpers";
|
|
115
|
-
dstSubfolderSpec = 16;
|
|
116
|
-
files = (
|
|
117
|
-
A10000000000000000000002 /* PlatformHelper in Embed Platform Helper */,
|
|
118
|
-
);
|
|
119
|
-
name = "Embed Platform Helper";
|
|
120
|
-
runOnlyForDeploymentPostprocessing = 0;
|
|
121
|
-
};
|
|
122
123
|
/* End PBXCopyFilesBuildPhase section */
|
|
123
124
|
|
|
124
125
|
/* Begin PBXFileReference section */
|
|
@@ -176,24 +177,36 @@
|
|
|
176
177
|
B102179524A8B237805F5FD2 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Cocoa.framework; sourceTree = DEVELOPER_DIR; };
|
|
177
178
|
BB2F792C24A3F905000567C9 /* Expo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Expo.plist; sourceTree = "<group>"; };
|
|
178
179
|
C0C08FBC319FFA07AF3EB93F /* Cmlx.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cmlx.framework; path = "Vendor/MLXSwift/0.31.6-macos/Cmlx.framework"; sourceTree = "<group>"; };
|
|
180
|
+
C20000000000000000000001 /* ModelCapabilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelCapabilities.swift; sourceTree = "<group>"; };
|
|
181
|
+
C20000000000000000000002 /* GenerationTypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenerationTypes.swift; sourceTree = "<group>"; };
|
|
182
|
+
C20000000000000000000003 /* TokenSampler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenSampler.swift; sourceTree = "<group>"; };
|
|
183
|
+
C20000000000000000000004 /* TextKVCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextKVCache.swift; sourceTree = "<group>"; };
|
|
184
|
+
C20000000000000000000005 /* Qwen3CheckpointLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Qwen3CheckpointLoader.swift; sourceTree = "<group>"; };
|
|
185
|
+
C20000000000000000000006 /* Qwen3Configuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Qwen3Configuration.swift; sourceTree = "<group>"; };
|
|
186
|
+
C20000000000000000000007 /* Qwen3Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Qwen3Model.swift; sourceTree = "<group>"; };
|
|
187
|
+
C20000000000000000000008 /* Qwen3InferenceSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Qwen3InferenceSession.swift; sourceTree = "<group>"; };
|
|
188
|
+
C20000000000000000000009 /* Qwen3Layers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Qwen3Layers.swift; sourceTree = "<group>"; };
|
|
189
|
+
C2000000000000000000000A /* QwenHybridFullAttention.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QwenHybridFullAttention.swift; sourceTree = "<group>"; };
|
|
190
|
+
C2000000000000000000000B /* QwenHybridLayers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QwenHybridLayers.swift; sourceTree = "<group>"; };
|
|
191
|
+
C2000000000000000000000C /* QwenHybridLinearAttention.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QwenHybridLinearAttention.swift; sourceTree = "<group>"; };
|
|
192
|
+
C2000000000000000000000D /* QwenHybridCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QwenHybridCache.swift; sourceTree = "<group>"; };
|
|
193
|
+
C2000000000000000000000E /* Qwen35Session.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Qwen35Session.swift; sourceTree = "<group>"; };
|
|
194
|
+
C2000000000000000000000F /* Qwen35Configuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Qwen35Configuration.swift; sourceTree = "<group>"; };
|
|
195
|
+
C20000000000000000000010 /* Qwen35Checkpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Qwen35Checkpoint.swift; sourceTree = "<group>"; };
|
|
196
|
+
C20000000000000000000011 /* Qwen35Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Qwen35Model.swift; sourceTree = "<group>"; };
|
|
197
|
+
C20000000000000000000012 /* BonsaiTextSnapshotValidator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BonsaiTextSnapshotValidator.swift; sourceTree = "<group>"; };
|
|
198
|
+
C20000000000000000000013 /* BonsaiTextModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BonsaiTextModel.swift; sourceTree = "<group>"; };
|
|
199
|
+
C20000000000000000000014 /* BonsaiTextGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BonsaiTextGenerator.swift; sourceTree = "<group>"; };
|
|
200
|
+
C20000000000000000000015 /* BonsaiTextGenerationRunner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BonsaiTextGenerationRunner.swift; sourceTree = "<group>"; };
|
|
179
201
|
CA962C2DD7808CB057168B5C /* GenerationServiceProtocol.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = GenerationServiceProtocol.swift; path = GenerationServiceProtocol.swift; sourceTree = "<group>"; };
|
|
180
202
|
E72903DB5F3C7D30AA5ED70B /* main.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = main.swift; path = main.swift; sourceTree = "<group>"; };
|
|
181
203
|
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
|
|
182
204
|
F11748412D0307B40044C1D9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppDelegate.swift; path = bleam/AppDelegate.swift; sourceTree = "<group>"; };
|
|
183
205
|
F11748442D0722820044C1D9 /* Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "Bridging-Header.h"; path = "bleam/Bridging-Header.h"; sourceTree = "<group>"; };
|
|
184
206
|
FB433ED9D990D1F5BEAC2C93 /* GenerationService.xpc */ = {isa = PBXFileReference; explicitFileType = "wrapper.xpc-service"; includeInIndex = 0; name = GenerationService.xpc; path = GenerationService.xpc; sourceTree = BUILT_PRODUCTS_DIR; };
|
|
185
|
-
A10000000000000000000005 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
|
|
186
|
-
A10000000000000000000006 /* PlatformHelper */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = PlatformHelper; sourceTree = BUILT_PRODUCTS_DIR; };
|
|
187
207
|
/* End PBXFileReference section */
|
|
188
208
|
|
|
189
209
|
/* Begin PBXFrameworksBuildPhase section */
|
|
190
|
-
A10000000000000000000007 /* Frameworks */ = {
|
|
191
|
-
isa = PBXFrameworksBuildPhase;
|
|
192
|
-
buildActionMask = 2147483647;
|
|
193
|
-
files = (
|
|
194
|
-
);
|
|
195
|
-
runOnlyForDeploymentPostprocessing = 0;
|
|
196
|
-
};
|
|
197
210
|
0656BC11F02F0C51B3DC5EE0 /* Frameworks */ = {
|
|
198
211
|
isa = PBXFrameworksBuildPhase;
|
|
199
212
|
buildActionMask = 2147483647;
|
|
@@ -225,6 +238,7 @@
|
|
|
225
238
|
8C3E6C6922B84B0C9F49B001 /* SceneDelegate.swift */,
|
|
226
239
|
8C3E6C7822B84B0C9F49B001 /* bleam.entitlements */,
|
|
227
240
|
8D1001002F00000000000100 /* Flux2 */,
|
|
241
|
+
C40000000000000000000001 /* TextGeneration */,
|
|
228
242
|
F11748442D0722820044C1D9 /* Bridging-Header.h */,
|
|
229
243
|
BB2F792B24A3F905000567C9 /* Supporting */,
|
|
230
244
|
13B07FB51A68108700A75B9A /* Images.xcassets */,
|
|
@@ -277,7 +291,6 @@
|
|
|
277
291
|
C304F306F23C790312DB9DC3 /* ExpoModulesProviders */,
|
|
278
292
|
B895E2E16B0B07754F5B5D83 /* Shared */,
|
|
279
293
|
AB7C58FE1F91CA4ED0C60825 /* GenerationService */,
|
|
280
|
-
A1000000000000000000000F /* PlatformHelper */,
|
|
281
294
|
);
|
|
282
295
|
indentWidth = 2;
|
|
283
296
|
sourceTree = "<group>";
|
|
@@ -289,7 +302,6 @@
|
|
|
289
302
|
children = (
|
|
290
303
|
13B07F961A680F5B00A75B9A /* bleam.app */,
|
|
291
304
|
FB433ED9D990D1F5BEAC2C93 /* GenerationService.xpc */,
|
|
292
|
-
A10000000000000000000006 /* PlatformHelper */,
|
|
293
305
|
);
|
|
294
306
|
name = Products;
|
|
295
307
|
sourceTree = "<group>";
|
|
@@ -339,19 +351,12 @@
|
|
|
339
351
|
7DFD85F313B4BAB889F5FECF /* GenerationService.entitlements */,
|
|
340
352
|
E72903DB5F3C7D30AA5ED70B /* main.swift */,
|
|
341
353
|
A4485061CD0366330F3F5BE0 /* ImageGenerationRunner.swift */,
|
|
354
|
+
C20000000000000000000015 /* BonsaiTextGenerationRunner.swift */,
|
|
342
355
|
);
|
|
343
356
|
name = GenerationService;
|
|
344
357
|
path = GenerationService;
|
|
345
358
|
sourceTree = "<group>";
|
|
346
359
|
};
|
|
347
|
-
A1000000000000000000000F /* PlatformHelper */ = {
|
|
348
|
-
isa = PBXGroup;
|
|
349
|
-
children = (
|
|
350
|
-
A10000000000000000000005 /* main.swift */,
|
|
351
|
-
);
|
|
352
|
-
path = PlatformHelper;
|
|
353
|
-
sourceTree = "<group>";
|
|
354
|
-
};
|
|
355
360
|
B895E2E16B0B07754F5B5D83 /* Shared */ = {
|
|
356
361
|
isa = PBXGroup;
|
|
357
362
|
children = (
|
|
@@ -386,6 +391,74 @@
|
|
|
386
391
|
name = ExpoModulesProviders;
|
|
387
392
|
sourceTree = "<group>";
|
|
388
393
|
};
|
|
394
|
+
C40000000000000000000001 /* TextGeneration */ = {
|
|
395
|
+
isa = PBXGroup;
|
|
396
|
+
children = (
|
|
397
|
+
C40000000000000000000002 /* Core */,
|
|
398
|
+
C40000000000000000000003 /* Qwen3 */,
|
|
399
|
+
C40000000000000000000004 /* QwenHybrid */,
|
|
400
|
+
C40000000000000000000005 /* Qwen35 */,
|
|
401
|
+
C40000000000000000000006 /* Bonsai */,
|
|
402
|
+
);
|
|
403
|
+
name = TextGeneration;
|
|
404
|
+
path = bleam/AI/TextGeneration;
|
|
405
|
+
sourceTree = "<group>";
|
|
406
|
+
};
|
|
407
|
+
C40000000000000000000002 /* Core */ = {
|
|
408
|
+
isa = PBXGroup;
|
|
409
|
+
children = (
|
|
410
|
+
C20000000000000000000001 /* ModelCapabilities.swift */,
|
|
411
|
+
C20000000000000000000002 /* GenerationTypes.swift */,
|
|
412
|
+
C20000000000000000000003 /* TokenSampler.swift */,
|
|
413
|
+
C20000000000000000000004 /* TextKVCache.swift */,
|
|
414
|
+
);
|
|
415
|
+
path = Core;
|
|
416
|
+
sourceTree = "<group>";
|
|
417
|
+
};
|
|
418
|
+
C40000000000000000000003 /* Qwen3 */ = {
|
|
419
|
+
isa = PBXGroup;
|
|
420
|
+
children = (
|
|
421
|
+
C20000000000000000000005 /* Qwen3CheckpointLoader.swift */,
|
|
422
|
+
C20000000000000000000006 /* Qwen3Configuration.swift */,
|
|
423
|
+
C20000000000000000000007 /* Qwen3Model.swift */,
|
|
424
|
+
C20000000000000000000008 /* Qwen3InferenceSession.swift */,
|
|
425
|
+
C20000000000000000000009 /* Qwen3Layers.swift */,
|
|
426
|
+
);
|
|
427
|
+
path = Qwen3;
|
|
428
|
+
sourceTree = "<group>";
|
|
429
|
+
};
|
|
430
|
+
C40000000000000000000004 /* QwenHybrid */ = {
|
|
431
|
+
isa = PBXGroup;
|
|
432
|
+
children = (
|
|
433
|
+
C2000000000000000000000A /* QwenHybridFullAttention.swift */,
|
|
434
|
+
C2000000000000000000000B /* QwenHybridLayers.swift */,
|
|
435
|
+
C2000000000000000000000C /* QwenHybridLinearAttention.swift */,
|
|
436
|
+
C2000000000000000000000D /* QwenHybridCache.swift */,
|
|
437
|
+
);
|
|
438
|
+
path = QwenHybrid;
|
|
439
|
+
sourceTree = "<group>";
|
|
440
|
+
};
|
|
441
|
+
C40000000000000000000005 /* Qwen35 */ = {
|
|
442
|
+
isa = PBXGroup;
|
|
443
|
+
children = (
|
|
444
|
+
C2000000000000000000000E /* Qwen35Session.swift */,
|
|
445
|
+
C2000000000000000000000F /* Qwen35Configuration.swift */,
|
|
446
|
+
C20000000000000000000010 /* Qwen35Checkpoint.swift */,
|
|
447
|
+
C20000000000000000000011 /* Qwen35Model.swift */,
|
|
448
|
+
);
|
|
449
|
+
path = Qwen35;
|
|
450
|
+
sourceTree = "<group>";
|
|
451
|
+
};
|
|
452
|
+
C40000000000000000000006 /* Bonsai */ = {
|
|
453
|
+
isa = PBXGroup;
|
|
454
|
+
children = (
|
|
455
|
+
C20000000000000000000012 /* BonsaiTextSnapshotValidator.swift */,
|
|
456
|
+
C20000000000000000000013 /* BonsaiTextModel.swift */,
|
|
457
|
+
C20000000000000000000014 /* BonsaiTextGenerator.swift */,
|
|
458
|
+
);
|
|
459
|
+
path = Bonsai;
|
|
460
|
+
sourceTree = "<group>";
|
|
461
|
+
};
|
|
389
462
|
D1A2D6EC5CB7BB01DBBDF46B /* Generation */ = {
|
|
390
463
|
isa = PBXGroup;
|
|
391
464
|
children = (
|
|
@@ -422,13 +495,11 @@
|
|
|
422
495
|
84C420C0881684F1F1EB77FB /* [bleam] Normalize Catalyst prebuilt frameworks */,
|
|
423
496
|
BEC473809D63946EDB256C9A /* [CP] Embed Pods Frameworks */,
|
|
424
497
|
CA12AFD569B8A5A458B4F36A /* Embed XPC Services */,
|
|
425
|
-
A10000000000000000000010 /* Embed Platform Helper */,
|
|
426
498
|
);
|
|
427
499
|
buildRules = (
|
|
428
500
|
);
|
|
429
501
|
dependencies = (
|
|
430
502
|
6E20F2C4EC850BB2D3853EAD /* PBXTargetDependency */,
|
|
431
|
-
A1000000000000000000000B /* PBXTargetDependency */,
|
|
432
503
|
);
|
|
433
504
|
name = bleam;
|
|
434
505
|
productName = bleam;
|
|
@@ -453,23 +524,6 @@
|
|
|
453
524
|
productReference = FB433ED9D990D1F5BEAC2C93 /* GenerationService.xpc */;
|
|
454
525
|
productType = "com.apple.product-type.xpc-service";
|
|
455
526
|
};
|
|
456
|
-
A1000000000000000000000A /* PlatformHelper */ = {
|
|
457
|
-
isa = PBXNativeTarget;
|
|
458
|
-
buildConfigurationList = A1000000000000000000000E /* Build configuration list for PBXNativeTarget "PlatformHelper" */;
|
|
459
|
-
buildPhases = (
|
|
460
|
-
A10000000000000000000009 /* Sources */,
|
|
461
|
-
A10000000000000000000007 /* Frameworks */,
|
|
462
|
-
A10000000000000000000008 /* Resources */,
|
|
463
|
-
);
|
|
464
|
-
buildRules = (
|
|
465
|
-
);
|
|
466
|
-
dependencies = (
|
|
467
|
-
);
|
|
468
|
-
name = PlatformHelper;
|
|
469
|
-
productName = PlatformHelper;
|
|
470
|
-
productReference = A10000000000000000000006 /* PlatformHelper */;
|
|
471
|
-
productType = "com.apple.product-type.tool";
|
|
472
|
-
};
|
|
473
527
|
/* End PBXNativeTarget section */
|
|
474
528
|
|
|
475
529
|
/* Begin PBXProject section */
|
|
@@ -484,9 +538,6 @@
|
|
|
484
538
|
8F04CB76A01E93A4B73D67A5 = {
|
|
485
539
|
LastSwiftMigration = 1250;
|
|
486
540
|
};
|
|
487
|
-
A1000000000000000000000A = {
|
|
488
|
-
LastSwiftMigration = 1250;
|
|
489
|
-
};
|
|
490
541
|
};
|
|
491
542
|
};
|
|
492
543
|
buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "Bleam" */;
|
|
@@ -504,7 +555,6 @@
|
|
|
504
555
|
targets = (
|
|
505
556
|
13B07F861A680F5B00A75B9A /* bleam */,
|
|
506
557
|
8F04CB76A01E93A4B73D67A5 /* GenerationService */,
|
|
507
|
-
A1000000000000000000000A /* PlatformHelper */,
|
|
508
558
|
);
|
|
509
559
|
};
|
|
510
560
|
/* End PBXProject section */
|
|
@@ -528,13 +578,6 @@
|
|
|
528
578
|
);
|
|
529
579
|
runOnlyForDeploymentPostprocessing = 0;
|
|
530
580
|
};
|
|
531
|
-
A10000000000000000000008 /* Resources */ = {
|
|
532
|
-
isa = PBXResourcesBuildPhase;
|
|
533
|
-
buildActionMask = 2147483647;
|
|
534
|
-
files = (
|
|
535
|
-
);
|
|
536
|
-
runOnlyForDeploymentPostprocessing = 0;
|
|
537
|
-
};
|
|
538
581
|
/* End PBXResourcesBuildPhase section */
|
|
539
582
|
|
|
540
583
|
/* Begin PBXShellScriptBuildPhase section */
|
|
@@ -696,6 +739,27 @@
|
|
|
696
739
|
D63D5719C5F6BEF2642A0627 /* GenerationWorkerProtocol.swift in Sources */,
|
|
697
740
|
90AAAF98423C82ED52385571 /* main.swift in Sources */,
|
|
698
741
|
B23B4E23A940CE8F6FD4B85A /* ImageGenerationRunner.swift in Sources */,
|
|
742
|
+
C30000000000000000000015 /* BonsaiTextGenerationRunner.swift in Sources */,
|
|
743
|
+
C30000000000000000000001 /* ModelCapabilities.swift in Sources */,
|
|
744
|
+
C30000000000000000000002 /* GenerationTypes.swift in Sources */,
|
|
745
|
+
C30000000000000000000003 /* TokenSampler.swift in Sources */,
|
|
746
|
+
C30000000000000000000004 /* TextKVCache.swift in Sources */,
|
|
747
|
+
C30000000000000000000005 /* Qwen3CheckpointLoader.swift in Sources */,
|
|
748
|
+
C30000000000000000000006 /* Qwen3Configuration.swift in Sources */,
|
|
749
|
+
C30000000000000000000007 /* Qwen3Model.swift in Sources */,
|
|
750
|
+
C30000000000000000000008 /* Qwen3InferenceSession.swift in Sources */,
|
|
751
|
+
C30000000000000000000009 /* Qwen3Layers.swift in Sources */,
|
|
752
|
+
C3000000000000000000000A /* QwenHybridFullAttention.swift in Sources */,
|
|
753
|
+
C3000000000000000000000B /* QwenHybridLayers.swift in Sources */,
|
|
754
|
+
C3000000000000000000000C /* QwenHybridLinearAttention.swift in Sources */,
|
|
755
|
+
C3000000000000000000000D /* QwenHybridCache.swift in Sources */,
|
|
756
|
+
C3000000000000000000000E /* Qwen35Session.swift in Sources */,
|
|
757
|
+
C3000000000000000000000F /* Qwen35Configuration.swift in Sources */,
|
|
758
|
+
C30000000000000000000010 /* Qwen35Checkpoint.swift in Sources */,
|
|
759
|
+
C30000000000000000000011 /* Qwen35Model.swift in Sources */,
|
|
760
|
+
C30000000000000000000012 /* BonsaiTextSnapshotValidator.swift in Sources */,
|
|
761
|
+
C30000000000000000000013 /* BonsaiTextModel.swift in Sources */,
|
|
762
|
+
C30000000000000000000014 /* BonsaiTextGenerator.swift in Sources */,
|
|
699
763
|
5224DF2286EAF50159491DCA /* Flux2Config.swift in Sources */,
|
|
700
764
|
814C5B6310C5000E9B289C59 /* MemoryConfig.swift in Sources */,
|
|
701
765
|
9819B5258147130BD109E6CD /* MemoryOptimizationConfig.swift in Sources */,
|
|
@@ -730,14 +794,6 @@
|
|
|
730
794
|
);
|
|
731
795
|
runOnlyForDeploymentPostprocessing = 0;
|
|
732
796
|
};
|
|
733
|
-
A10000000000000000000009 /* Sources */ = {
|
|
734
|
-
isa = PBXSourcesBuildPhase;
|
|
735
|
-
buildActionMask = 2147483647;
|
|
736
|
-
files = (
|
|
737
|
-
A10000000000000000000001 /* main.swift in Sources */,
|
|
738
|
-
);
|
|
739
|
-
runOnlyForDeploymentPostprocessing = 0;
|
|
740
|
-
};
|
|
741
797
|
/* End PBXSourcesBuildPhase section */
|
|
742
798
|
|
|
743
799
|
/* Begin PBXTargetDependency section */
|
|
@@ -747,12 +803,6 @@
|
|
|
747
803
|
target = 8F04CB76A01E93A4B73D67A5 /* GenerationService */;
|
|
748
804
|
targetProxy = 0B3BB0ECB863062C83BCE9B3 /* PBXContainerItemProxy */;
|
|
749
805
|
};
|
|
750
|
-
A1000000000000000000000B /* PBXTargetDependency */ = {
|
|
751
|
-
isa = PBXTargetDependency;
|
|
752
|
-
name = PlatformHelper;
|
|
753
|
-
target = A1000000000000000000000A /* PlatformHelper */;
|
|
754
|
-
targetProxy = A10000000000000000000003 /* PBXContainerItemProxy */;
|
|
755
|
-
};
|
|
756
806
|
/* End PBXTargetDependency section */
|
|
757
807
|
|
|
758
808
|
/* Begin XCBuildConfiguration section */
|
|
@@ -916,7 +966,7 @@
|
|
|
916
966
|
"-DRCT_REMOVE_LEGACY_ARCH=1",
|
|
917
967
|
);
|
|
918
968
|
PODFILE_DIR = "$(SRCROOT)";
|
|
919
|
-
REACT_NATIVE_PATH = "${PODS_ROOT}
|
|
969
|
+
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
|
|
920
970
|
SDKROOT = iphoneos;
|
|
921
971
|
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG";
|
|
922
972
|
SWIFT_ENABLE_EXPLICIT_MODULES = NO;
|
|
@@ -980,7 +1030,7 @@
|
|
|
980
1030
|
"-DRCT_REMOVE_LEGACY_ARCH=1",
|
|
981
1031
|
);
|
|
982
1032
|
PODFILE_DIR = "$(SRCROOT)";
|
|
983
|
-
REACT_NATIVE_PATH = "${PODS_ROOT}
|
|
1033
|
+
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
|
|
984
1034
|
SDKROOT = iphoneos;
|
|
985
1035
|
SWIFT_ENABLE_EXPLICIT_MODULES = NO;
|
|
986
1036
|
USE_HERMES = true;
|
|
@@ -1067,41 +1117,6 @@
|
|
|
1067
1117
|
};
|
|
1068
1118
|
name = Debug;
|
|
1069
1119
|
};
|
|
1070
|
-
A1000000000000000000000C /* Debug */ = {
|
|
1071
|
-
isa = XCBuildConfiguration;
|
|
1072
|
-
buildSettings = {
|
|
1073
|
-
ARCHS = arm64;
|
|
1074
|
-
CODE_SIGN_STYLE = Automatic;
|
|
1075
|
-
DEAD_CODE_STRIPPING = YES;
|
|
1076
|
-
DEVELOPMENT_TEAM = 5SZ3H5P69M;
|
|
1077
|
-
ENABLE_APP_SANDBOX = NO;
|
|
1078
|
-
ENABLE_HARDENED_RUNTIME = YES;
|
|
1079
|
-
MACOSX_DEPLOYMENT_TARGET = 13.4;
|
|
1080
|
-
PRODUCT_NAME = "$(TARGET_NAME)";
|
|
1081
|
-
SDKROOT = macosx;
|
|
1082
|
-
SKIP_INSTALL = YES;
|
|
1083
|
-
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
|
1084
|
-
SWIFT_VERSION = 5.0;
|
|
1085
|
-
};
|
|
1086
|
-
name = Debug;
|
|
1087
|
-
};
|
|
1088
|
-
A1000000000000000000000D /* Release */ = {
|
|
1089
|
-
isa = XCBuildConfiguration;
|
|
1090
|
-
buildSettings = {
|
|
1091
|
-
ARCHS = arm64;
|
|
1092
|
-
CODE_SIGN_STYLE = Automatic;
|
|
1093
|
-
DEAD_CODE_STRIPPING = YES;
|
|
1094
|
-
DEVELOPMENT_TEAM = 5SZ3H5P69M;
|
|
1095
|
-
ENABLE_APP_SANDBOX = NO;
|
|
1096
|
-
ENABLE_HARDENED_RUNTIME = YES;
|
|
1097
|
-
MACOSX_DEPLOYMENT_TARGET = 13.4;
|
|
1098
|
-
PRODUCT_NAME = "$(TARGET_NAME)";
|
|
1099
|
-
SDKROOT = macosx;
|
|
1100
|
-
SKIP_INSTALL = YES;
|
|
1101
|
-
SWIFT_VERSION = 5.0;
|
|
1102
|
-
};
|
|
1103
|
-
name = Release;
|
|
1104
|
-
};
|
|
1105
1120
|
/* End XCBuildConfiguration section */
|
|
1106
1121
|
|
|
1107
1122
|
/* Begin XCConfigurationList section */
|
|
@@ -1132,15 +1147,6 @@
|
|
|
1132
1147
|
defaultConfigurationIsVisible = 0;
|
|
1133
1148
|
defaultConfigurationName = Release;
|
|
1134
1149
|
};
|
|
1135
|
-
A1000000000000000000000E /* Build configuration list for PBXNativeTarget "PlatformHelper" */ = {
|
|
1136
|
-
isa = XCConfigurationList;
|
|
1137
|
-
buildConfigurations = (
|
|
1138
|
-
A1000000000000000000000C /* Debug */,
|
|
1139
|
-
A1000000000000000000000D /* Release */,
|
|
1140
|
-
);
|
|
1141
|
-
defaultConfigurationIsVisible = 0;
|
|
1142
|
-
defaultConfigurationName = Release;
|
|
1143
|
-
};
|
|
1144
1150
|
/* End XCConfigurationList section */
|
|
1145
1151
|
};
|
|
1146
1152
|
rootObject = 83CBB9F71A601CBA00E9B192 /* Project object */;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import MLX
|
|
3
|
+
|
|
4
|
+
final class BonsaiTextGenerationRunner: @unchecked Sendable {
|
|
5
|
+
private let request: BonsaiTextGenerationRequest
|
|
6
|
+
private let emit: @Sendable (BonsaiTextGenerationEvent) -> Void
|
|
7
|
+
private let stateLock = NSLock()
|
|
8
|
+
private var cancellationRequested = false
|
|
9
|
+
private var generatedTokenIDs: [Int] = []
|
|
10
|
+
|
|
11
|
+
init(
|
|
12
|
+
request: BonsaiTextGenerationRequest,
|
|
13
|
+
emit: @escaping @Sendable (BonsaiTextGenerationEvent) -> Void
|
|
14
|
+
) {
|
|
15
|
+
self.request = request
|
|
16
|
+
self.emit = emit
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
func cancel() {
|
|
20
|
+
stateLock.withLock { cancellationRequested = true }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func run(isCancelled externalCancellation: @escaping @Sendable () -> Bool) async {
|
|
24
|
+
defer { MLX.Memory.clearCache() }
|
|
25
|
+
do {
|
|
26
|
+
let profile = try BonsaiTextModelProfile.resolve(request.model)
|
|
27
|
+
let parameters = try generationParameters(defaults: profile.defaultGenerationParameters)
|
|
28
|
+
let endTokenIDs = request.endTokenIDs.isEmpty ? profile.defaultEndTokenIDs : Set(request.endTokenIDs)
|
|
29
|
+
let result = try await BonsaiTextGenerator.generate(
|
|
30
|
+
profile: profile,
|
|
31
|
+
modelURL: URL(fileURLWithPath: request.modelPath, isDirectory: true),
|
|
32
|
+
inputIDs: request.inputIDs,
|
|
33
|
+
endTokenIDs: endTokenIDs,
|
|
34
|
+
parameters: parameters,
|
|
35
|
+
isCancelled: { [weak self] in
|
|
36
|
+
externalCancellation() || (self?.isCancellationRequested ?? true)
|
|
37
|
+
},
|
|
38
|
+
onToken: { [weak self, emit, id = request.id] tokenID in
|
|
39
|
+
guard let tokenIDs = self?.append(tokenID) else { return false }
|
|
40
|
+
emit(.init(type: .update, id: id, tokenIDs: tokenIDs))
|
|
41
|
+
return true
|
|
42
|
+
}
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
if result.finishReason == .cancelled || shouldCancel(externalCancellation) {
|
|
46
|
+
emit(.init(type: .canceled, id: request.id, tokenIDs: result.tokenIDs, finishReason: GenerationFinishReason.cancelled.rawValue))
|
|
47
|
+
} else {
|
|
48
|
+
emit(.init(type: .completed, id: request.id, tokenIDs: result.tokenIDs, finishReason: result.finishReason.rawValue))
|
|
49
|
+
}
|
|
50
|
+
} catch is CancellationError {
|
|
51
|
+
emit(.init(type: .canceled, id: request.id, tokenIDs: generatedTokens, finishReason: GenerationFinishReason.cancelled.rawValue))
|
|
52
|
+
} catch {
|
|
53
|
+
emit(.init(type: .failed, id: request.id, tokenIDs: generatedTokens, message: error.localizedDescription))
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private var isCancellationRequested: Bool {
|
|
58
|
+
stateLock.withLock { cancellationRequested }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private var generatedTokens: [Int] {
|
|
62
|
+
stateLock.withLock { generatedTokenIDs }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private func append(_ tokenID: Int) -> [Int] {
|
|
66
|
+
stateLock.withLock {
|
|
67
|
+
generatedTokenIDs.append(tokenID)
|
|
68
|
+
return generatedTokenIDs
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private func shouldCancel(_ externalCancellation: @escaping @Sendable () -> Bool) -> Bool {
|
|
73
|
+
Task.isCancelled || externalCancellation() || isCancellationRequested
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private func generationParameters(defaults: GenerationParameters) throws -> GenerationParameters {
|
|
77
|
+
let seed: UInt64?
|
|
78
|
+
if let requestedSeed = request.seed {
|
|
79
|
+
guard let converted = UInt64(exactly: requestedSeed) else {
|
|
80
|
+
throw BonsaiTextError.invalidSeed(requestedSeed)
|
|
81
|
+
}
|
|
82
|
+
seed = converted
|
|
83
|
+
} else {
|
|
84
|
+
seed = defaults.seed
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let parameters = GenerationParameters(
|
|
88
|
+
maximumNewTokens: request.maximumNewTokens ?? defaults.maximumNewTokens,
|
|
89
|
+
temperature: request.temperature.map(Float.init) ?? defaults.temperature,
|
|
90
|
+
topP: request.topP.map(Float.init) ?? defaults.topP,
|
|
91
|
+
topK: request.topK ?? defaults.topK,
|
|
92
|
+
repetitionPenalty: request.repetitionPenalty.map(Float.init) ?? defaults.repetitionPenalty,
|
|
93
|
+
repetitionContextSize: request.repetitionContextSize ?? defaults.repetitionContextSize,
|
|
94
|
+
seed: seed
|
|
95
|
+
)
|
|
96
|
+
try TokenSampler.validate(parameters)
|
|
97
|
+
guard parameters.temperature.isFinite, parameters.topP.isFinite,
|
|
98
|
+
parameters.repetitionPenalty.isFinite else {
|
|
99
|
+
throw BonsaiTextError.invalidGenerationParameters("floating-point values must be finite")
|
|
100
|
+
}
|
|
101
|
+
return parameters
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -7,6 +7,7 @@ import UniformTypeIdentifiers
|
|
|
7
7
|
final class ImageGenerationRunner: @unchecked Sendable {
|
|
8
8
|
private let request: GenerationWorkerRequest
|
|
9
9
|
private let emit: @Sendable (GenerationWorkerEvent) -> Void
|
|
10
|
+
private let stateLock = NSLock()
|
|
10
11
|
private var isCancelled = false
|
|
11
12
|
|
|
12
13
|
init(
|
|
@@ -18,7 +19,7 @@ final class ImageGenerationRunner: @unchecked Sendable {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
func cancel() {
|
|
21
|
-
isCancelled = true
|
|
22
|
+
stateLock.withLock { isCancelled = true }
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
func run(isCancelled externalCancellation: @escaping @Sendable () -> Bool) async throws {
|
|
@@ -88,10 +89,13 @@ final class ImageGenerationRunner: @unchecked Sendable {
|
|
|
88
89
|
// First service version is deliberately memory-first: the runner releases
|
|
89
90
|
// text encoder, transformer, and VAE stages instead of keeping a warm
|
|
90
91
|
// pipeline. Add warm caching later only behind explicit idle trimming.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
let runner = FluxImageRunner(
|
|
93
|
+
paths: FluxImageRunnerPaths(
|
|
94
|
+
transformer: URL(fileURLWithPath: request.transformerPath, isDirectory: true),
|
|
95
|
+
vae: URL(fileURLWithPath: request.vaePath, isDirectory: true)
|
|
96
|
+
),
|
|
97
|
+
transformerProfile: transformerProfile()
|
|
98
|
+
)
|
|
95
99
|
var fluxStage = "denoise"
|
|
96
100
|
do {
|
|
97
101
|
return try runner.generate(
|
|
@@ -147,11 +151,13 @@ final class ImageGenerationRunner: @unchecked Sendable {
|
|
|
147
151
|
}
|
|
148
152
|
|
|
149
153
|
private func shouldCancel(_ externalCancellation: @escaping @Sendable () -> Bool) -> Bool {
|
|
150
|
-
Task.isCancelled || isCancelled || externalCancellation()
|
|
154
|
+
Task.isCancelled || stateLock.withLock { isCancelled } || externalCancellation()
|
|
151
155
|
}
|
|
152
156
|
|
|
153
157
|
private func validateRequest() throws {
|
|
154
|
-
guard request.model == "flux2-klein-4b-8bit-abliterated"
|
|
158
|
+
guard request.model == "flux2-klein-4b-8bit-abliterated"
|
|
159
|
+
|| request.model == "ternary-bonsai-image-4b"
|
|
160
|
+
else {
|
|
155
161
|
throw GenerationWorkerFailure(message: "Unsupported image model: \(request.model)")
|
|
156
162
|
}
|
|
157
163
|
guard !request.prompt.isEmpty else {
|
|
@@ -264,6 +270,12 @@ final class ImageGenerationRunner: @unchecked Sendable {
|
|
|
264
270
|
}
|
|
265
271
|
}
|
|
266
272
|
|
|
273
|
+
private func transformerProfile() -> Flux2TransformerRepoProfile {
|
|
274
|
+
request.model == "ternary-bonsai-image-4b"
|
|
275
|
+
? ModelRegistry.TransformerRepo.prismMLBonsaiKlein4B2bit.profile
|
|
276
|
+
: ModelRegistry.TransformerRepo.moxinOrgKlein4B8bit.profile
|
|
277
|
+
}
|
|
278
|
+
|
|
267
279
|
private static func validateSafetensors(atPath path: String) throws {
|
|
268
280
|
let url = URL(fileURLWithPath: path)
|
|
269
281
|
let fileSize: UInt64
|