Skip to content

Commit

Permalink
fix: verified model for kv cache loading as incorrect cache might be …
Browse files Browse the repository at this point in the history
…loaded when using similar architectures
  • Loading branch information
Vali-98 committed Oct 31, 2024
1 parent 7c28239 commit b987145
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions app/constants/APIState/LocalAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,23 @@ class LocalAPI extends APIBase {

inference = async () => {
let context = Llama.useLlama.getState().context
if (!context && mmkv.getBoolean(AppSettings.AutoLoadLocal)) {
let model: undefined | ModelDataType = undefined

try {
const modelString = mmkv.getString(Global.LocalModel)
if (!modelString) {
Logger.log('No Auto-Load Model Set', true)
return
}
model = JSON.parse(modelString)
} catch (e) {
Logger.log('Failed to Auto-Load Model', true)

let model: undefined | ModelDataType = undefined

try {
const modelString = mmkv.getString(Global.LocalModel)
if (!modelString) {
Logger.log('No Auto-Load Model Set', true)
return
}
model = JSON.parse(modelString)
} catch (e) {
Logger.log('Failed to Auto-Load Model', true)
}

if (model && !context && mmkv.getBoolean(AppSettings.AutoLoadLocal)) {
const params = this.getObject(Global.LocalPreset)
if (model && params) {
if (params) {
Logger.log(`Auto-loading: ${model.name}`, true)
await Llama.useLlama.getState().load(model)
context = Llama.useLlama.getState().context
Expand All @@ -80,7 +81,7 @@ class LocalAPI extends APIBase {
const loadKV =
mmkv.getBoolean(AppSettings.SaveLocalKV) && !mmkv.getBoolean(Global.LocalSessionLoaded)

if (loadKV) {
if (loadKV && model?.id === Llama.useLlama.getState().model?.id) {
await Llama.useLlama.getState().loadKV()
mmkv.set(Global.LocalSessionLoaded, true)
}
Expand Down

0 comments on commit b987145

Please sign in to comment.