bleam 0.0.8 → 0.0.9
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/cli.cjs +23 -4
- package/dist/cli.d.cts +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +23 -4
- package/dist/{ui-Ce-pnUUA.d.ts → ui-Bg11tvlc.d.ts} +7 -7
- package/dist/ui.d.ts +1 -1
- package/dist/window.d.ts +1 -1
- package/package.json +4 -1
- package/templates/image-generation/app/index.tsx +1 -1
- package/templates/native/.gitattributes +1 -0
- package/templates/native/App.tsx +26 -0
- package/templates/native/app.json +12 -0
- package/templates/native/index.ts +8 -0
- package/templates/native/ios/.xcode.env +11 -0
- package/templates/native/ios/Bleam/AI/Flux2/Configuration/Flux2Config.swift +288 -0
- package/templates/native/ios/Bleam/AI/Flux2/Configuration/MemoryConfig.swift +233 -0
- package/templates/native/ios/Bleam/AI/Flux2/Configuration/MemoryOptimizationConfig.swift +157 -0
- package/templates/native/ios/Bleam/AI/Flux2/Configuration/ModelRegistry.swift +425 -0
- package/templates/native/ios/Bleam/AI/Flux2/Configuration/QuantizationConfig.swift +138 -0
- package/templates/native/ios/Bleam/AI/Flux2/Configuration/TransformerRepoProfile.swift +59 -0
- package/templates/native/ios/Bleam/AI/Flux2/Configuration/VAEConfig.swift +134 -0
- package/templates/native/ios/Bleam/AI/Flux2/Flux2Core.swift +55 -0
- package/templates/native/ios/Bleam/AI/Flux2/Loading/WeightLoader.swift +1192 -0
- package/templates/native/ios/Bleam/AI/Flux2/Pipeline/FluxImageRunner.swift +1282 -0
- package/templates/native/ios/Bleam/AI/Flux2/Pipeline/LatentUtils.swift +191 -0
- package/templates/native/ios/Bleam/AI/Flux2/Scheduler/FlowMatchEulerScheduler.swift +279 -0
- package/templates/native/ios/Bleam/AI/Flux2/Text/KleinTextEncoder.swift +380 -0
- package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2Attention.swift +379 -0
- package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2Embeddings.swift +159 -0
- package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2FeedForward.swift +154 -0
- package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2FusedKernels.swift +198 -0
- package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2KVCache.swift +36 -0
- package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2Modulation.swift +193 -0
- package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2ParallelAttention.swift +389 -0
- package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2RoPE.swift +304 -0
- package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2SingleBlock.swift +290 -0
- package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2Transformer.swift +530 -0
- package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2TransformerBlock.swift +362 -0
- package/templates/native/ios/Bleam/AI/Flux2/Utils/Flux2Debug.swift +101 -0
- package/templates/native/ios/Bleam/AI/Flux2/Utils/MLXCheckpoint.swift +118 -0
- package/templates/native/ios/Bleam/AI/Flux2/Utils/MemoryManager.swift +201 -0
- package/templates/native/ios/Bleam/AI/Flux2/VAE/AutoencoderKL.swift +476 -0
- package/templates/native/ios/Bleam/AI/Flux2/VAE/ResnetBlock.swift +316 -0
- package/templates/native/ios/Bleam/AI/Flux2/VAE/VAEDecoder.swift +120 -0
- package/templates/native/ios/Bleam/AI/Flux2/VAE/VAEEncoder.swift +136 -0
- package/templates/native/ios/Bleam/AppDelegate.swift +373 -0
- package/templates/native/ios/Bleam/Appearance.swift +62 -0
- package/templates/native/ios/Bleam/Bridging-Header.h +3 -0
- package/templates/native/ios/Bleam/Images.xcassets/AppIcon.appiconset/Contents.json +13 -0
- package/templates/native/ios/Bleam/Images.xcassets/Contents.json +6 -0
- package/templates/native/ios/Bleam/Info.plist +76 -0
- package/templates/native/ios/Bleam/PrivacyInfo.xcprivacy +48 -0
- package/templates/native/ios/Bleam/SceneDelegate.swift +58 -0
- package/templates/native/ios/Bleam/SplashScreen.storyboard +47 -0
- package/templates/native/ios/Bleam/Supporting/Expo.plist +6 -0
- package/templates/native/ios/Bleam/bleam.entitlements +10 -0
- package/templates/native/ios/Bleam.xcodeproj/project.pbxproj +1146 -0
- package/templates/native/ios/Bleam.xcodeproj/xcshareddata/xcschemes/Bleam.xcscheme +88 -0
- package/templates/native/ios/GenerationService/GenerationService.entitlements +10 -0
- package/templates/native/ios/GenerationService/ImageGenerationRunner.swift +591 -0
- package/templates/native/ios/GenerationService/Info.plist +31 -0
- package/templates/native/ios/GenerationService/main.swift +165 -0
- package/templates/native/ios/PlatformHelper/Info.plist +29 -0
- package/templates/native/ios/PlatformHelper/main.swift +335 -0
- package/templates/native/ios/Podfile +198 -0
- package/templates/native/ios/Podfile.lock +2284 -0
- package/templates/native/ios/Podfile.properties.json +5 -0
- package/templates/native/ios/Shared/Generation/GenerationServiceProtocol.swift +12 -0
- package/templates/native/ios/Shared/Generation/GenerationWorkerProtocol.swift +124 -0
- package/templates/native/metro.config.js +6 -0
- package/templates/native/modules/bleam-runtime/BleamRuntime.podspec +14 -0
- package/templates/native/modules/bleam-runtime/expo-module.config.json +8 -0
- package/templates/native/modules/bleam-runtime/ios/AIModule.swift +1258 -0
- package/templates/native/modules/bleam-runtime/ios/GenerationContracts.swift +135 -0
- package/templates/native/modules/bleam-runtime/ios/PlatformModule.swift +313 -0
- package/templates/native/modules/bleam-runtime/package.json +5 -0
- package/templates/native/package.json +39 -0
- package/templates/native/scripts/build/mlx-frameworks.ts +421 -0
- package/templates/native/scripts/start/index.ts +474 -0
- package/templates/native/scripts/start/known-failures.ts +20 -0
- package/templates/native/scripts/start/loader.ts +76 -0
- package/templates/native/scripts/start/native-state.ts +242 -0
- package/templates/native/scripts/start/package.json +4 -0
- package/templates/native/scripts/start/swift-packages.ts +414 -0
- package/templates/native/scripts/start/xcode-formatter.ts +106 -0
- package/templates/native/tsconfig.json +14 -0
- package/templates/native/yarn.lock +3749 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// VAEConfig.swift - Flux.2 VAE Configuration
|
|
2
|
+
// Copyright 2025 Vincent Gourbin
|
|
3
|
+
|
|
4
|
+
import Foundation
|
|
5
|
+
|
|
6
|
+
/// Configuration for the Flux.2 VAE (AutoencoderKL)
|
|
7
|
+
public struct VAEConfig: Codable, Sendable {
|
|
8
|
+
/// Number of input/output channels (3 for RGB)
|
|
9
|
+
public var inChannels: Int
|
|
10
|
+
|
|
11
|
+
/// Number of output channels (same as input)
|
|
12
|
+
public var outChannels: Int
|
|
13
|
+
|
|
14
|
+
/// Number of latent channels (32 for Flux.2, vs 4 for Flux.1)
|
|
15
|
+
public var latentChannels: Int
|
|
16
|
+
|
|
17
|
+
/// Channel multipliers for each block
|
|
18
|
+
public var blockOutChannels: [Int]
|
|
19
|
+
|
|
20
|
+
/// Number of ResNet blocks per level
|
|
21
|
+
public var layersPerBlock: Int
|
|
22
|
+
|
|
23
|
+
/// Activation function
|
|
24
|
+
public var activationFunction: String
|
|
25
|
+
|
|
26
|
+
/// Normalization layer epsilon
|
|
27
|
+
public var normEps: Float
|
|
28
|
+
|
|
29
|
+
/// Number of groups for group normalization
|
|
30
|
+
public var normNumGroups: Int
|
|
31
|
+
|
|
32
|
+
/// Scaling factor for latent space
|
|
33
|
+
public var scalingFactor: Float
|
|
34
|
+
|
|
35
|
+
/// Whether to use BatchNorm for latent normalization
|
|
36
|
+
public var useBatchNorm: Bool
|
|
37
|
+
|
|
38
|
+
/// Patch size for latent packing
|
|
39
|
+
public var patchSize: (Int, Int)
|
|
40
|
+
|
|
41
|
+
public init(
|
|
42
|
+
inChannels: Int = 3,
|
|
43
|
+
outChannels: Int = 3,
|
|
44
|
+
latentChannels: Int = 32,
|
|
45
|
+
blockOutChannels: [Int] = [128, 256, 512, 512],
|
|
46
|
+
layersPerBlock: Int = 2,
|
|
47
|
+
activationFunction: String = "silu",
|
|
48
|
+
normEps: Float = 1e-6,
|
|
49
|
+
normNumGroups: Int = 32,
|
|
50
|
+
scalingFactor: Float = 0.18215,
|
|
51
|
+
useBatchNorm: Bool = true,
|
|
52
|
+
patchSize: (Int, Int) = (2, 2)
|
|
53
|
+
) {
|
|
54
|
+
self.inChannels = inChannels
|
|
55
|
+
self.outChannels = outChannels
|
|
56
|
+
self.latentChannels = latentChannels
|
|
57
|
+
self.blockOutChannels = blockOutChannels
|
|
58
|
+
self.layersPerBlock = layersPerBlock
|
|
59
|
+
self.activationFunction = activationFunction
|
|
60
|
+
self.normEps = normEps
|
|
61
|
+
self.normNumGroups = normNumGroups
|
|
62
|
+
self.scalingFactor = scalingFactor
|
|
63
|
+
self.useBatchNorm = useBatchNorm
|
|
64
|
+
self.patchSize = patchSize
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/// Default Flux.2 VAE configuration
|
|
68
|
+
public static let flux2Dev = VAEConfig()
|
|
69
|
+
|
|
70
|
+
// MARK: - Codable
|
|
71
|
+
|
|
72
|
+
enum CodingKeys: String, CodingKey {
|
|
73
|
+
case inChannels = "in_channels"
|
|
74
|
+
case outChannels = "out_channels"
|
|
75
|
+
case latentChannels = "latent_channels"
|
|
76
|
+
case blockOutChannels = "block_out_channels"
|
|
77
|
+
case layersPerBlock = "layers_per_block"
|
|
78
|
+
case activationFunction = "act_fn"
|
|
79
|
+
case normEps = "norm_eps"
|
|
80
|
+
case normNumGroups = "norm_num_groups"
|
|
81
|
+
case scalingFactor = "scaling_factor"
|
|
82
|
+
case useBatchNorm = "use_batch_norm"
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public init(from decoder: Decoder) throws {
|
|
86
|
+
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
87
|
+
|
|
88
|
+
inChannels = try container.decodeIfPresent(Int.self, forKey: .inChannels) ?? 3
|
|
89
|
+
outChannels = try container.decodeIfPresent(Int.self, forKey: .outChannels) ?? 3
|
|
90
|
+
latentChannels = try container.decodeIfPresent(Int.self, forKey: .latentChannels) ?? 32
|
|
91
|
+
blockOutChannels = try container.decodeIfPresent([Int].self, forKey: .blockOutChannels) ?? [128, 256, 512, 512]
|
|
92
|
+
layersPerBlock = try container.decodeIfPresent(Int.self, forKey: .layersPerBlock) ?? 2
|
|
93
|
+
activationFunction = try container.decodeIfPresent(String.self, forKey: .activationFunction) ?? "silu"
|
|
94
|
+
normEps = try container.decodeIfPresent(Float.self, forKey: .normEps) ?? 1e-6
|
|
95
|
+
normNumGroups = try container.decodeIfPresent(Int.self, forKey: .normNumGroups) ?? 32
|
|
96
|
+
scalingFactor = try container.decodeIfPresent(Float.self, forKey: .scalingFactor) ?? 0.18215
|
|
97
|
+
useBatchNorm = try container.decodeIfPresent(Bool.self, forKey: .useBatchNorm) ?? true
|
|
98
|
+
patchSize = (2, 2) // Not in JSON, hardcoded for Flux.2
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public func encode(to encoder: Encoder) throws {
|
|
102
|
+
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
103
|
+
|
|
104
|
+
try container.encode(inChannels, forKey: .inChannels)
|
|
105
|
+
try container.encode(outChannels, forKey: .outChannels)
|
|
106
|
+
try container.encode(latentChannels, forKey: .latentChannels)
|
|
107
|
+
try container.encode(blockOutChannels, forKey: .blockOutChannels)
|
|
108
|
+
try container.encode(layersPerBlock, forKey: .layersPerBlock)
|
|
109
|
+
try container.encode(activationFunction, forKey: .activationFunction)
|
|
110
|
+
try container.encode(normEps, forKey: .normEps)
|
|
111
|
+
try container.encode(normNumGroups, forKey: .normNumGroups)
|
|
112
|
+
try container.encode(scalingFactor, forKey: .scalingFactor)
|
|
113
|
+
try container.encode(useBatchNorm, forKey: .useBatchNorm)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/// Load configuration from a JSON file
|
|
117
|
+
public static func load(from url: URL) throws -> VAEConfig {
|
|
118
|
+
let data = try Data(contentsOf: url)
|
|
119
|
+
return try JSONDecoder().decode(VAEConfig.self, from: data)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
extension VAEConfig: CustomStringConvertible {
|
|
124
|
+
public var description: String {
|
|
125
|
+
"""
|
|
126
|
+
VAEConfig(
|
|
127
|
+
channels: \(inChannels) -> latent \(latentChannels) -> \(outChannels),
|
|
128
|
+
blocks: \(blockOutChannels),
|
|
129
|
+
batchNorm: \(useBatchNorm),
|
|
130
|
+
patch: \(patchSize)
|
|
131
|
+
)
|
|
132
|
+
"""
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import MLX
|
|
3
|
+
import MLXNN
|
|
4
|
+
|
|
5
|
+
public enum Flux2Core {
|
|
6
|
+
public static let version = "0.1.0-image-studio"
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
public enum Flux2Error: Error, LocalizedError {
|
|
10
|
+
case modelNotLoaded(String)
|
|
11
|
+
case invalidConfiguration(String)
|
|
12
|
+
case insufficientMemory(required: Int, available: Int)
|
|
13
|
+
case weightLoadingFailed(String)
|
|
14
|
+
case imageProcessingFailed(String)
|
|
15
|
+
case generationFailed(String)
|
|
16
|
+
case generationCancelled
|
|
17
|
+
|
|
18
|
+
public var errorCode: String {
|
|
19
|
+
switch self {
|
|
20
|
+
case .modelNotLoaded:
|
|
21
|
+
return "model_not_loaded"
|
|
22
|
+
case .invalidConfiguration:
|
|
23
|
+
return "invalid_configuration"
|
|
24
|
+
case .insufficientMemory:
|
|
25
|
+
return "insufficient_memory"
|
|
26
|
+
case .weightLoadingFailed:
|
|
27
|
+
return "weight_loading_failed"
|
|
28
|
+
case .imageProcessingFailed:
|
|
29
|
+
return "image_processing_failed"
|
|
30
|
+
case .generationFailed:
|
|
31
|
+
return "generation_failed"
|
|
32
|
+
case .generationCancelled:
|
|
33
|
+
return "generation_cancelled"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public var errorDescription: String? {
|
|
38
|
+
switch self {
|
|
39
|
+
case .modelNotLoaded(let component):
|
|
40
|
+
return "Model component not loaded: \(component)"
|
|
41
|
+
case .invalidConfiguration(let message):
|
|
42
|
+
return "Invalid configuration: \(message)"
|
|
43
|
+
case .insufficientMemory(let required, let available):
|
|
44
|
+
return "Insufficient memory: required \(required / 1_000_000_000)GB, available \(available / 1_000_000_000)GB"
|
|
45
|
+
case .weightLoadingFailed(let message):
|
|
46
|
+
return "Failed to load weights: \(message)"
|
|
47
|
+
case .imageProcessingFailed(let message):
|
|
48
|
+
return "Image processing failed: \(message)"
|
|
49
|
+
case .generationFailed(let message):
|
|
50
|
+
return "Generation failed: \(message)"
|
|
51
|
+
case .generationCancelled:
|
|
52
|
+
return "Generation was cancelled"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|