Error Initializing Llama Model: Context Limit Reached
samtin0x opened this issue · comments
Description
When using this library on an Expo v50 app I got a persistent error that stopped the completions from working. The app was functioning correctly, but after a series of prompts, it failed with the error "[Error: Context limit reached]". I smell this is an easy fix from my end? Any help is appreciated :)
Steps to Reproduce
- Initialize the Llama model with standard settings.
- Send multiple messages to the model.
- Observe the failure after several interactions.
Environment
- Expo version: v50
- Model: phi2 3B Q2_K - Medium
- Device: iPhone 14 Pro Max (development build)
Code Snippet
export const runLlama = async (message: string, modelId: string) => {
const MODEL_FILE_PATH = `${FileSystem.documentDirectory}${modelId}.gguf`;
return new Promise((resolve, reject) => {
initLlama({
model: MODEL_FILE_PATH,
use_mlock: true,
n_ctx: 2048,
n_gpu_layers: 1,
})
.then((context) => {
context.completion({
prompt: message,
n_predict: 60,
temperature: 0.7,
top_p: 1.0,
stop: ['</s>', 'Llama:', 'User:'],
}, (data) => {
const { token } = data;
resolve({ type: 'partial', token });
})
.then((sss) => {
console.log('Completion result:', sss.text);
resolve({ type: 'final', text: sss.text });
})
.catch((error) => {
console.log('Error running Llama:', error);
reject(error);
});
})
.catch((error) => {
console.log('Error initializing Llama:', error);
reject(error);
});
});
};
Error
ERROR Error running Llama: [Error: Context limit reached]
There is the code of context limit in this module:
Lines 36 to 39 in 7fbcebc
If you want to run more contexts, you can set more context limit by setContextLimit
. Otherwise, you should release the existing context before initialize a new one.