From 3b6df6613477bdec92ec5d38ff17ce0364cefedb Mon Sep 17 00:00:00 2001 From: Pedro Cuenca Date: Thu, 5 Sep 2024 15:18:19 +0200 Subject: [PATCH] Allow archiving for Mac MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SPM dependencies are always compiled for the standard architectures, but Float16 is not available for `x86_64`. Thanks @joshnewnham for the workaround 🙌 --- Sources/Models/LanguageModel.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sources/Models/LanguageModel.swift b/Sources/Models/LanguageModel.swift index b4c5ac67..50bf72ad 100644 --- a/Sources/Models/LanguageModel.swift +++ b/Sources/Models/LanguageModel.swift @@ -383,14 +383,22 @@ public class LanguageModelWithStatefulKVCache: LanguageModel { Keys.inputIds: inputIds, ] if isRequiringAttentionMask { + #if !((os(macOS) || (macCatalyst)) && arch(x86_64)) // TODO: Infer scalar type from cache or model I/O descriptors let attentionMask = MLTensor(zeros: [1, 1, 1, tokenCount + 1], scalarType: Float16.self) inputDictionary[Keys.attentionMask] = attentionMask + #else + fatalError() + #endif } if isRequiringCausalMask { + #if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64)) // TODO: Infer scalar type from cache or model I/O descriptors let causalMask = MLTensor(zeros: [1, 1, 1, tokenCount + 1], scalarType: Float16.self) inputDictionary[Keys.causalMask] = causalMask + #else + fatalError() + #endif } let outputs = try! await model.prediction(from: inputDictionary, using: state)