Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/model/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ func allExcept(s string) GRPCProcessFilter {
return id != s
}
}

func only(s string) GRPCProcessFilter {
return func(id string, p *process.Process) bool {
return id == s
}
}
19 changes: 14 additions & 5 deletions pkg/model/initializers.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,19 @@ func (ml *ModelLoader) backendLoader(opts ...Option) (client grpc.Backend, err e

model, err := ml.LoadModel(o.modelID, o.model, ml.grpcModel(backend, o))
if err != nil {
err := ml.StopGRPC(only(o.modelID))
if err != nil {
log.Error().Err(err).Str("model", o.modelID).Msg("error stopping model")
}
log.Error().Str("modelID", o.modelID).Err(err).Msgf("Failed to load model %s with backend %s", o.modelID, o.backendString)
return nil, err
}

return model.GRPC(o.parallelRequests, ml.wd), nil
}

func (ml *ModelLoader) stopActiveBackends(modelID string, singleActiveBackend bool) {
if !singleActiveBackend {
func (ml *ModelLoader) stopActiveBackends(modelID string) {
if !ml.singletonMode {
return
}

Expand Down Expand Up @@ -218,15 +222,19 @@ func (ml *ModelLoader) Load(opts ...Option) (grpc.Backend, error) {
// (avoid looping through all the backends)
if m := ml.CheckIsLoaded(o.modelID); m != nil {
log.Debug().Msgf("Model '%s' already loaded", o.modelID)

return m.GRPC(o.parallelRequests, ml.wd), nil
}

ml.stopActiveBackends(o.modelID, ml.singletonMode)
ml.stopActiveBackends(o.modelID)

// if a backend is defined, return the loader directly
if o.backendString != "" {
return ml.backendLoader(opts...)
client, err := ml.backendLoader(opts...)
if err != nil {
ml.Close()
return nil, err
}
return client, nil
}

// Otherwise scan for backends in the asset directory
Expand All @@ -242,6 +250,7 @@ func (ml *ModelLoader) Load(opts ...Option) (grpc.Backend, error) {

if len(autoLoadBackends) == 0 {
log.Error().Msg("No backends found")
ml.Close()
return nil, fmt.Errorf("no backends found")
}

Expand Down
Loading