Commit 06ef90c0 authored by Michael Yang's avatar Michael Yang
Browse files

fix parameter inheritence

parameters are not inherited because they are processed differently from
other layer. fix this by explicitly merging the inherited params into
the new params. parameter values defined in the new modelfile will
override those defined in the inherited modelfile. array lists are
replaced instead of appended
parent e9f6df7d
...@@ -276,6 +276,7 @@ func CreateModel(ctx context.Context, name string, path string, fn func(resp api ...@@ -276,6 +276,7 @@ func CreateModel(ctx context.Context, name string, path string, fn func(resp api
var layers []*LayerReader var layers []*LayerReader
params := make(map[string][]string) params := make(map[string][]string)
var sourceParams map[string]any
embed := EmbeddingParams{fn: fn} embed := EmbeddingParams{fn: fn}
for _, c := range commands { for _, c := range commands {
log.Printf("[%s] - %s\n", c.Name, c.Args) log.Printf("[%s] - %s\n", c.Name, c.Args)
...@@ -359,6 +360,23 @@ func CreateModel(ctx context.Context, name string, path string, fn func(resp api ...@@ -359,6 +360,23 @@ func CreateModel(ctx context.Context, name string, path string, fn func(resp api
config.FileType = source.FileType config.FileType = source.FileType
for _, l := range mf.Layers { for _, l := range mf.Layers {
if l.MediaType == "application/vnd.ollama.image.params" {
sourceParamsBlobPath, err := GetBlobsPath(l.Digest)
if err != nil {
return err
}
sourceParamsBlob, err := os.Open(sourceParamsBlobPath)
if err != nil {
return err
}
defer sourceParamsBlob.Close()
if err := json.NewDecoder(sourceParamsBlob).Decode(&sourceParams); err != nil {
return err
}
}
newLayer, err := GetLayerWithBufferFromLayer(l) newLayer, err := GetLayerWithBufferFromLayer(l)
if err != nil { if err != nil {
return err return err
...@@ -436,6 +454,12 @@ func CreateModel(ctx context.Context, name string, path string, fn func(resp api ...@@ -436,6 +454,12 @@ func CreateModel(ctx context.Context, name string, path string, fn func(resp api
return fmt.Errorf("couldn't create params json: %v", err) return fmt.Errorf("couldn't create params json: %v", err)
} }
for k, v := range sourceParams {
if _, ok := formattedParams[k]; !ok {
formattedParams[k] = v
}
}
bts, err := json.Marshal(formattedParams) bts, err := json.Marshal(formattedParams)
if err != nil { if err != nil {
return err return err
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment