Skip to content
Snippets Groups Projects
Commit 67a7b716 authored by Abhinav Jain's avatar Abhinav Jain
Browse files

fix build script

parent 02447119
No related branches found
No related tags found
1 merge request!15Add interface for using generic CoreML LLMs
Pipeline #116009 failed
This commit is part of merge request !15. Comments created here will be created in the context of that merge request.
......@@ -24,6 +24,12 @@ build-macOS:
test-macOS:
stage: test
script:
- xcrun coremlcompiler compile Sources/SwiftNLP/Resources/all-MiniLM-L6-v2.mlpackage/ Sources/SwiftNLP/Models
- xcrun coremlcompiler generate Sources/SwiftNLP/Resources/all-MiniLM-L6-v2.mlpackage/ --language Swift Sources/SwiftNLP/Resources
- mv Sources/SwiftNLP/Resources/all-MiniLM-L6-v2.swift Sources/SwiftNLP/2.\ Encoding
- xcrun coremlcompiler compile Sources/SwiftNLP/Resources/float32_model.mlpackage/ Sources/SwiftNLP/Models
- xcrun coremlcompiler generate Sources/SwiftNLP/Resources/float32_model.mlpackage/ --language Swift Sources/SwiftNLP/Resources
- mv Sources/SwiftNLP/Resources/float32_model.swift Sources/SwiftNLP/2.\ Encoding
- swift test -c release -Xswiftc -enable-testing
# - swift test --sanitize=address -c release -Xswiftc -enable-testing
# - swift test --sanitize=thread -c release -Xswiftc -enable-testing
......
......@@ -43,6 +43,11 @@ public macro MODEL_MAKE_PREDICTION(_ input_name: Any, _ attention_ids: Any, _ ou
module: "SwiftNLPGenericLLMMacros",
type: "LLMModelPredictionCases")
@freestanding(expression)
public macro MODEL_VALIDATE_NAME() = #externalMacro(
module: "SwiftNLPGenericLLMMacros",
type: "LLMModelNameValidation")
class CoreMLEncoder<Scalar: BinaryFloatingPoint & Codable>: SNLPEncoder {
......@@ -77,6 +82,8 @@ public class MiniLMEmbeddings {
self.model = model_type;
self.tokenizer = BertTokenizer(maxLen: self.inputDimention)
#MODEL_VALIDATE_NAME()
}
// MARK: - Dense Embeddings
......
......@@ -3,6 +3,45 @@ import SwiftSyntax
import SwiftSyntaxMacros
@available(macOS 12, iOS 15.0, tvOS 17.0, watchOS 10.0, *)
public struct LLMModelNameValidation: ExpressionMacro {
/**
Example expansion:
let valid_models = ["all_MiniLM_L6_v2", "gte-small"];
if !valid_models.contains(self.model) {
throw fatalError("Model is not valid.");
}
*/
public static func expansion(
of node: some FreestandingMacroExpansionSyntax,
in context: some MacroExpansionContext
) throws -> ExprSyntax {
var macro = "let valid_models = [";
var index = 0;
for (k, v) in LLM_MODEL_CLASSES {
macro += "\"\(k)\"";
index += 1;
if index < LLM_MODEL_CLASSES.count {
macro += ", ";
}
}
macro += "];";
return ExprSyntax(stringLiteral:
"""
\(macro)
if !valid_models.contains(self.model) {
throw fatalError("Model is not valid.");
}
"""
)
}
}
@available(macOS 12, iOS 15.0, tvOS 17.0, watchOS 10.0, *)
public struct LLMModelPredictionCases: ExpressionMacro {
/**
......
......@@ -6,6 +6,7 @@ struct SwiftNLPGenericLLMMacros: CompilerPlugin {
init() {}
var providingMacros: [SwiftSyntaxMacros.Macro.Type] = [
LLMPredictionFunctions.self,
LLMModelPredictionCases.self
LLMModelPredictionCases.self,
LLMModelNameValidation.self
]
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment