Skip to content

Commit 9f8691c

Browse files
authored
Add llama2 / torch models for ollama create (ollama#3607)
1 parent a0b8a32 commit 9f8691c

File tree

11 files changed

+860
-291
lines changed

11 files changed

+860
-291
lines changed

cmd/cmd.go

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,48 @@ func CreateHandler(cmd *cobra.Command, args []string) error {
105105

106106
zf := zip.NewWriter(tf)
107107

108-
files, err := filepath.Glob(filepath.Join(path, "model-*.safetensors"))
108+
files := []string{}
109+
110+
tfiles, err := filepath.Glob(filepath.Join(path, "pytorch_model-*.bin"))
109111
if err != nil {
110112
return err
113+
} else if len(tfiles) == 0 {
114+
tfiles, err = filepath.Glob(filepath.Join(path, "model-*.safetensors"))
115+
if err != nil {
116+
return err
117+
}
111118
}
112119

120+
files = append(files, tfiles...)
121+
113122
if len(files) == 0 {
114-
return fmt.Errorf("no safetensors files were found in '%s'", path)
123+
return fmt.Errorf("no models were found in '%s'", path)
115124
}
116125

117-
// add the safetensor config file + tokenizer
126+
// add the safetensor/torch config file + tokenizer
118127
files = append(files, filepath.Join(path, "config.json"))
128+
files = append(files, filepath.Join(path, "params.json"))
119129
files = append(files, filepath.Join(path, "added_tokens.json"))
120130
files = append(files, filepath.Join(path, "tokenizer.model"))
121131

122132
for _, fn := range files {
123133
f, err := os.Open(fn)
124-
if os.IsNotExist(err) && strings.HasSuffix(fn, "added_tokens.json") {
125-
continue
134+
135+
// just skip whatever files aren't there
136+
if os.IsNotExist(err) {
137+
if strings.HasSuffix(fn, "tokenizer.model") {
138+
// try the parent dir before giving up
139+
parentDir := filepath.Dir(path)
140+
newFn := filepath.Join(parentDir, "tokenizer.model")
141+
f, err = os.Open(newFn)
142+
if os.IsNotExist(err) {
143+
continue
144+
} else if err != nil {
145+
return err
146+
}
147+
} else {
148+
continue
149+
}
126150
} else if err != nil {
127151
return err
128152
}

0 commit comments

Comments
 (0)