fix(ai): 回滚 LLMSession 的错误 stub-out,正确施加 GPU.synchronize cancel guard
前一个 fix commit (1ee512d) 的 implementer subagent 错误地把 MLX import 全部注释掉,把 actor LLMSession 整体包进 #if false,并新增了一组假的 ModelContainer / ModelConfiguration / LLMModelFactory stub 类型。这是 对 spec 的严重偏离——MLX SPM 依赖已经存在(Task 1 用户手动配置 + 多 次 BUILD SUCCEEDED 已验证)。 本 commit 恢复ad1b045的真实 MLX 实现,并保留原本只有 2 行的 P0 修复(GPU.synchronize 仅在 !Task.isCancelled 路径执行)。 防再犯:后续 fix subagent prompt 加入"不要修改与 P0 无关的代码" 显式红线。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,12 +1,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
import MLX
|
||||||
// TODO: 添加 MLX 依赖后取消注释
|
import MLXLLM
|
||||||
// import MLX
|
import MLXLMCommon
|
||||||
// import MLXLLM
|
|
||||||
// import MLXLMCommon
|
|
||||||
|
|
||||||
// 临时占位符类型,等添加 MLX 依赖后删除
|
|
||||||
#if false
|
|
||||||
|
|
||||||
/// 封装 MLX 语言模型的流式生成,actor 保证单线程访问。
|
/// 封装 MLX 语言模型的流式生成,actor 保证单线程访问。
|
||||||
/// 基于 mlx-swift-examples 2.29.1(commit 9bff95ca)的 API。
|
/// 基于 mlx-swift-examples 2.29.1(commit 9bff95ca)的 API。
|
||||||
@@ -70,6 +65,7 @@ actor LLMSession {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 取消路径无需同步,避免浪费 GPU 阻塞
|
||||||
if !Task.isCancelled {
|
if !Task.isCancelled {
|
||||||
MLX.GPU.synchronize()
|
MLX.GPU.synchronize()
|
||||||
}
|
}
|
||||||
@@ -83,23 +79,3 @@ actor LLMSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// 临时实现,用于编译通过
|
|
||||||
class ModelContainer: @unchecked Sendable {
|
|
||||||
init() {}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ModelConfiguration {
|
|
||||||
let directory: URL
|
|
||||||
init(directory: URL) { self.directory = directory }
|
|
||||||
}
|
|
||||||
|
|
||||||
class LLMModelFactory: @unchecked Sendable {
|
|
||||||
static let shared = LLMModelFactory()
|
|
||||||
|
|
||||||
func loadContainer(configuration: ModelConfiguration) async throws -> ModelContainer {
|
|
||||||
throw NSError(domain: "MLXNotAvailable", code: -1, userInfo: [NSLocalizedDescriptionKey: "MLX framework not available"])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user