Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-gray101 committed Apr 2, 2024
1 parent 15e6f93 commit 826006a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
31 changes: 31 additions & 0 deletions configuration/backend_rules_onlytwo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[
{
"name": "OnlyTwoLT2",
"desc": "Test Rule: Only allow 2 backends to be loaded at once, unload the least recently used if a 3rd request comes in",
"salience": 10,
"when": [
"Result.Action == ActionDefs.Blank",
"LoadedModelCount <= 1"
],
"then": [
"Result.Action = ActionDefs.Continue",
"Result.ModelName = RequestedModelName"
]
},
{
"name": "OnlyTwoGT2",
"desc": "Test Rule: Only allow 2 backends to be loaded at once, unload the least recently used if a 3rd request comes in",
"salience": 10,
"when": [
"Result.Action == ActionDefs.Blank",
"LoadedModelCount >= 2"
],
"then": [
"Log(\"Too many backends in use, unloading least recently used...\")",
"LRU = LoadedModels[0].ModelName",
"ModelLoader.ShutdownModel(LRU)",
"Result.Action = ActionDefs.Continue",
"Result.ModelName = RequestedModelName"
]
}
]
5 changes: 3 additions & 2 deletions core/services/backend_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,17 @@ func (rbbs RuleBasedBackendService) RuleBasedLoad(modelName string, alreadyLoade
ruleBasedLoadDataCtx := ast.NewDataContext()

ruleBasedLoadDataCtx.Add("ModelLoader", rbbs.modelLoader)
ruleBasedLoadDataCtx.Add("LoadedModelCount", rbbs.modelLoader.LoadedModelCount()) // Still relevant after second line???
ruleBasedLoadDataCtx.Add("LoadedModelCount", rbbs.modelLoader.LoadedModelCount())
ruleBasedLoadDataCtx.Add("LoadedModels", rbbs.modelLoader.SortedLoadedModelMetadata())

ruleBasedLoadDataCtx.Add("ActionDefs", ruleBasedBackendResultActionDefinitions)

ruleBasedLoadDataCtx.Add("RequestedModelName", modelName)
ruleBasedLoadDataCtx.Add("Source", source)
ruleBasedLoadDataCtx.Add("Request", optionalRequest)

ruleBasedLoadDataCtx.Add("BackendConfig", bc)
ruleBasedLoadDataCtx.Add("AppConfig", rbbs.appConfig)

ruleBasedLoadDataCtx.Add("Result", result)

Expand All @@ -114,5 +116,4 @@ func (rbbs RuleBasedBackendService) RuleBasedLoad(modelName string, alreadyLoade
return nil, err
}
return &result, nil

}

0 comments on commit 826006a

Please sign in to comment.