diff --git a/体己.xcodeproj/project.pbxproj b/体己.xcodeproj/project.pbxproj index ab4c588..f619d9a 100644 --- a/体己.xcodeproj/project.pbxproj +++ b/体己.xcodeproj/project.pbxproj @@ -6,6 +6,11 @@ objectVersion = 77; objects = { +/* Begin PBXBuildFile section */ + FEED000000000000DEAD0001 /* MLXLLM in Frameworks */ = {isa = PBXBuildFile; productRef = FEED000000000000DEAD0003 /* MLXLLM */; }; + FEED000000000000DEAD0002 /* MLXLMCommon in Frameworks */ = {isa = PBXBuildFile; productRef = FEED000000000000DEAD0004 /* MLXLMCommon */; }; +/* End PBXBuildFile section */ + /* Begin PBXContainerItemProxy section */ 5E463D092FC403BC0089145B /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; @@ -52,6 +57,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + FEED000000000000DEAD0001 /* MLXLLM in Frameworks */, + FEED000000000000DEAD0002 /* MLXLMCommon in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -112,6 +119,8 @@ ); name = "体己"; packageProductDependencies = ( + FEED000000000000DEAD0003 /* MLXLLM */, + FEED000000000000DEAD0004 /* MLXLMCommon */, ); productName = "体己"; productReference = 5E463CF92FC403BB0089145B /* 体己.app */; @@ -195,6 +204,9 @@ ); mainGroup = 5E463CF02FC403BB0089145B; minimizedProjectReferenceProxies = 1; + packageReferences = ( + 5E9A1F872FC43C9A0097DD29 /* XCRemoteSwiftPackageReference "mlx-swift-examples" */, + ); preferredProjectObjectVersion = 77; productRefGroup = 5E463CFA2FC403BB0089145B /* Products */; projectDirPath = ""; @@ -615,6 +627,30 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + 5E9A1F872FC43C9A0097DD29 /* XCRemoteSwiftPackageReference "mlx-swift-examples" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/ml-explore/mlx-swift-examples"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 2.29.1; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + FEED000000000000DEAD0003 /* MLXLLM */ = { + isa = XCSwiftPackageProductDependency; + package = 5E9A1F872FC43C9A0097DD29 /* XCRemoteSwiftPackageReference "mlx-swift-examples" */; + productName = MLXLLM; + }; + FEED000000000000DEAD0004 /* MLXLMCommon */ = { + isa = XCSwiftPackageProductDependency; + package = 5E9A1F872FC43C9A0097DD29 /* XCRemoteSwiftPackageReference "mlx-swift-examples" */; + productName = MLXLMCommon; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = 5E463CF12FC403BB0089145B /* Project object */; } diff --git a/体己.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/体己.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 0000000..6fffd8a --- /dev/null +++ b/体己.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,69 @@ +{ + "originHash" : "6b8265ebd61c6fdfca835dd1f90f17439ca9abc5c11a8b7b5db8790be0349e4d", + "pins" : [ + { + "identity" : "gzipswift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/1024jp/GzipSwift", + "state" : { + "revision" : "731037f6cc2be2ec01562f6597c1d0aa3fe6fd05", + "version" : "6.0.1" + } + }, + { + "identity" : "mlx-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/ml-explore/mlx-swift", + "state" : { + "revision" : "072b684acaae80b6a463abab3a103732f33774bf", + "version" : "0.29.1" + } + }, + { + "identity" : "mlx-swift-examples", + "kind" : "remoteSourceControl", + "location" : "https://github.com/ml-explore/mlx-swift-examples", + "state" : { + "revision" : "9bff95ca5f0b9e8c021acc4d71a2bbe4a7441631", + "version" : "2.29.1" + } + }, + { + "identity" : "swift-collections", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-collections.git", + "state" : { + "revision" : "fea17c02d767f46b23070fdfdacc28a03a39232a", + "version" : "1.5.1" + } + }, + { + "identity" : "swift-jinja", + "kind" : "remoteSourceControl", + "location" : "https://github.com/huggingface/swift-jinja.git", + "state" : { + "revision" : "0b67ecb79139f6addef8699eff3622808aa6c7dc", + "version" : "2.3.6" + } + }, + { + "identity" : "swift-numerics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-numerics", + "state" : { + "revision" : "0c0290ff6b24942dadb83a929ffaaa1481df04a2", + "version" : "1.1.1" + } + }, + { + "identity" : "swift-transformers", + "kind" : "remoteSourceControl", + "location" : "https://github.com/huggingface/swift-transformers", + "state" : { + "revision" : "a2e184dddb4757bc943e77fbe99ac6786c53f0b2", + "version" : "1.0.0" + } + } + ], + "version" : 3 +} diff --git a/体己/AI/LLMSession.swift b/体己/AI/LLMSession.swift index dc9a1bc..579a321 100644 --- a/体己/AI/LLMSession.swift +++ b/体己/AI/LLMSession.swift @@ -1,5 +1,4 @@ import Foundation -import MLX import MLXLLM import MLXLMCommon @@ -65,10 +64,10 @@ actor LLMSession { break } } - // 取消路径无需同步,避免浪费 GPU 阻塞 - if !Task.isCancelled { - MLX.GPU.synchronize() - } + // 注:研究笔记里曾建议尾部 MLX.GPU.synchronize() 以确保 + // GPU 操作全部完成。但 AsyncStream 已经 yield 真实解码后的 + // 文字,GPU 是否完全空闲不影响数据正确性。去掉此调用同时省 + // 一份 transitive import MLX 的依赖,简化 SPM 链接。 } continuation.finish() } catch {