Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to store a loaded engine in react to avoid multiple reloads when refreshing the app? #636

Open
jvjmarinello opened this issue Nov 22, 2024 · 0 comments

Comments

@jvjmarinello
Copy link

I'm working with the web-llm library to load and use models like TinyLlama-1.1B-Chat-v0.4-q4f16_1-MLC-1k. My current implementation downloads the model successfully and caches it using engine.reload, which appears to use IndexedDB under the hood (correct me if I'm wrong). Here's the relevant code snippet:

const modelId = "TinyLlama-1.1B-Chat-v0.4-q4f16_1-MLC-1k";
const webllm = await import("https://esm.run/@mlc-ai/web-llm");
const engine = new webllm.MLCEngine();
engine.setInitProgressCallback((report) => {
console.log(Loading ${modelId}: ${report.text});
});
await engine.reload(modelId, defaultModelParameters);

Now, I want to preload this engine once and make it available across my entire React app without loading on rendering. Is that possible? how and where would you store the pre-loaded engine(s)? I was trying use hooks or context to manage this, ensuring that the engine is initialized once and shared across all components without reloading the model multiple times. I tried to store the engine in localStorage but I get an error due to circular references.

What’s the best way to achieve this in React?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant