"...api/git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "e30d3bf5442fbdbee899e8a5da0b11b621d54f1b"
Unverified Commit ed78e127 authored by Michael Yang's avatar Michael Yang Committed by GitHub
Browse files

fix(cmd): unload model before removal (#12832)

this change fixes two bugs with `ollama rm`:

1. before a model is removed, it will first be stopped. this only
   happens for the first argument and skipped for all other models
2. models are unloaded indiscriminately. this errors for cloud models
   and should be omitted
parent d432ade7
...@@ -280,6 +280,13 @@ func loadOrUnloadModel(cmd *cobra.Command, opts *runOptions) error { ...@@ -280,6 +280,13 @@ func loadOrUnloadModel(cmd *cobra.Command, opts *runOptions) error {
return err return err
} }
if info, err := client.Show(cmd.Context(), &api.ShowRequest{Model: opts.Model}); err != nil {
return err
} else if info.RemoteHost != "" {
// Cloud model, no need to load/unload
return nil
}
req := &api.GenerateRequest{ req := &api.GenerateRequest{
Model: opts.Model, Model: opts.Model,
KeepAlive: opts.KeepAlive, KeepAlive: opts.KeepAlive,
...@@ -720,23 +727,21 @@ func DeleteHandler(cmd *cobra.Command, args []string) error { ...@@ -720,23 +727,21 @@ func DeleteHandler(cmd *cobra.Command, args []string) error {
return err return err
} }
// Unload the model if it's running before deletion for _, arg := range args {
opts := &runOptions{ // Unload the model if it's running before deletion
Model: args[0], if err := loadOrUnloadModel(cmd, &runOptions{
KeepAlive: &api.Duration{Duration: 0}, Model: args[0],
} KeepAlive: &api.Duration{Duration: 0},
if err := loadOrUnloadModel(cmd, opts); err != nil { }); err != nil {
if !strings.Contains(strings.ToLower(err.Error()), "not found") { if !strings.Contains(strings.ToLower(err.Error()), "not found") {
fmt.Fprintf(os.Stderr, "Warning: unable to stop model '%s'\n", args[0]) fmt.Fprintf(os.Stderr, "Warning: unable to stop model '%s'\n", args[0])
}
} }
}
for _, name := range args { if err := client.Delete(cmd.Context(), &api.DeleteRequest{Name: arg}); err != nil {
req := api.DeleteRequest{Name: name}
if err := client.Delete(cmd.Context(), &req); err != nil {
return err return err
} }
fmt.Printf("deleted '%s'\n", name) fmt.Printf("deleted '%s'\n", arg)
} }
return nil return nil
} }
......
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