Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
d006e1e0
Unverified
Commit
d006e1e0
authored
Feb 14, 2025
by
Bruce MacDonald
Committed by
GitHub
Feb 14, 2025
Browse files
model: document high-level model interface (#9122)
parent
df2680b4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
2 deletions
+8
-2
model/model.go
model/model.go
+8
-2
No files found.
model/model.go
View file @
d006e1e0
...
...
@@ -21,6 +21,7 @@ import (
_
"github.com/ollama/ollama/ml/backend"
)
// Options contains the inputs for a model forward pass
type
Options
struct
{
Inputs
[]
int32
Positions
[]
int32
...
...
@@ -34,11 +35,13 @@ type config struct {
Cache
kvcache
.
Cache
}
// Base implements the common fields and methods for all models
type
Base
struct
{
b
ml
.
Backend
config
}
// Backend returns the underlying backend that will run the model
func
(
m
*
Base
)
Backend
()
ml
.
Backend
{
return
m
.
b
}
...
...
@@ -47,6 +50,7 @@ func (m *Base) Config() config {
return
m
.
config
}
// Model implements a specific model architecture, defining the forward pass and any model-specific configuration
type
Model
interface
{
Forward
(
ml
.
Context
,
Options
)
(
ml
.
Tensor
,
error
)
...
...
@@ -56,6 +60,7 @@ type Model interface {
var
models
=
make
(
map
[
string
]
func
(
ml
.
Config
)
(
Model
,
error
))
// Register registers a model constructor for the given architecture
func
Register
(
name
string
,
f
func
(
ml
.
Config
)
(
Model
,
error
))
{
if
_
,
ok
:=
models
[
name
];
ok
{
panic
(
"model: model already registered"
)
...
...
@@ -64,8 +69,9 @@ func Register(name string, f func(ml.Config) (Model, error)) {
models
[
name
]
=
f
}
func
New
(
s
string
)
(
Model
,
error
)
{
r
,
err
:=
os
.
Open
(
s
)
// New initializes a new model instance with the provided configuration based on the metadata in the model file
func
New
(
modelPath
string
)
(
Model
,
error
)
{
r
,
err
:=
os
.
Open
(
modelPath
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment