Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Curio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jim Wallace
Curio
Commits
76dba7d1
Commit
76dba7d1
authored
1 year ago
by
Abhinav Jain
Browse files
Options
Downloads
Patches
Plain Diff
name changes
parent
6ea88ef5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!15
Add interface for using generic CoreML LLMs
Pipeline
#116025
canceled
1 year ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Sources/SwiftNLPGenericLLMMacros/Macros.swift
+6
-4
6 additions, 4 deletions
Sources/SwiftNLPGenericLLMMacros/Macros.swift
Sources/SwiftNLPGenericLLMMacros/ModelClasses.swift
+5
-2
5 additions, 2 deletions
Sources/SwiftNLPGenericLLMMacros/ModelClasses.swift
with
11 additions
and
6 deletions
Sources/SwiftNLPGenericLLMMacros/Macros.swift
+
6
−
4
View file @
76dba7d1
...
...
@@ -127,28 +127,30 @@ public enum LLMPredictionFunctions: DeclarationMacro {
let
model_type_name
=
v
[
LLMModelClassesKey
.
Model
]
!
;
let
model_input_name
=
v
[
LLMModelClassesKey
.
Input
]
!
;
let
model_output_name
=
v
[
LLMModelClassesKey
.
Output
]
!
;
let
model_url
=
v
[
LLMModelClassesKey
.
URL
]
!
;
ret
+=
"""
public static func prediction(input:
\(
model_input_name
)
) throws ->
\(
model_output_name
)
{
let model = try
\(
model_type_name
)
();
let model = try
\(
model_type_name
)
(
contentsOf: URL(fileURLWithPath:
\"
Sources/SwiftNLP/Models/
\(
model_url
)\"
);
return try model.prediction(input: input, options: MLPredictionOptions())
}
public static func prediction(input:
\(
model_input_name
)
, options: MLPredictionOptions) throws ->
\(
model_output_name
)
{
let model = try
\(
model_type_name
)
();
let model = try
\(
model_type_name
)
(
contentsOf: URL(fileURLWithPath:
\"
Sources/SwiftNLP/Models/
\(
model_url
)\"
);
let outFeatures: MLFeatureProvider = try model.prediction(input: input, options:options)
return
\(
model_output_name
)
(features: outFeatures)
}
@available(macOS 13.6, iOS 17.0, tvOS 17.0, watchOS 10.0, *)
public static func prediction(input:
\(
model_input_name
)
, options: MLPredictionOptions = MLPredictionOptions()) async throws ->
\(
model_output_name
)
{
let model = try
\(
model_type_name
)
();
let model = try
\(
model_type_name
)
(
contentsOf: URL(fileURLWithPath:
\"
Sources/SwiftNLP/Models/
\(
model_url
)\"
);
let outFeatures: MLFeatureProvider? = try await model.prediction(input: input, options:options)
return
\(
model_output_name
)
(features: outFeatures!)
}
public static func predictions(inputs: [
\(
model_input_name
)
], options: MLPredictionOptions = MLPredictionOptions()) throws -> [
\(
model_output_name
)
] {
let model = try
\(
model_type_name
)
();
let model = try
\(
model_type_name
)
(
contentsOf: URL(fileURLWithPath:
\"
Sources/SwiftNLP/Models/
\(
model_url
)\"
);
let res = try model.predictions(inputs: inputs, options: options);
return res;
}
...
...
This diff is collapsed.
Click to expand it.
Sources/SwiftNLPGenericLLMMacros/ModelClasses.swift
+
5
−
2
View file @
76dba7d1
...
...
@@ -3,6 +3,7 @@ enum LLMModelClassesKey {
case
Output
case
Model
case
FeatureName
case
URL
}
let
LLM_MODEL_CLASSES
:
[
String
:
[
LLMModelClassesKey
:
Any
]]
=
[
...
...
@@ -10,12 +11,14 @@ let LLM_MODEL_CLASSES: [String: [LLMModelClassesKey: Any]] = [
LLMModelClassesKey
.
Input
:
all_MiniLM_L6_v2Input
.
self
,
LLMModelClassesKey
.
Output
:
all_MiniLM_L6_v2Output
.
self
,
LLMModelClassesKey
.
Model
:
all_MiniLM_L6_v2
.
self
,
LLMModelClassesKey
.
FeatureName
:
"embeddings"
LLMModelClassesKey
.
FeatureName
:
"embeddings"
,
LLMModelClassesKey
.
URL
:
"all-MiniLM-L6-v2.mlmodelc"
],
"gte-small"
:
[
LLMModelClassesKey
.
Input
:
float32_modelInput
.
self
,
LLMModelClassesKey
.
Output
:
float32_modelOutput
.
self
,
LLMModelClassesKey
.
Model
:
float32_model
.
self
,
LLMModelClassesKey
.
FeatureName
:
"pooler_output"
LLMModelClassesKey
.
FeatureName
:
"pooler_output"
,
LLMModelClassesKey
.
URL
:
"float32_model.mlmodelc"
]
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment