Skip to content

Ultra-lightweight open-source LLM implementation running entirely client-side using transformers.js - GitHub Pages deployable with mobile optimization and browser memory management

License

Notifications You must be signed in to change notification settings

harisnae/browser-based-LLM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Browser based LLM

GitHub repo size GitHub top language npm

A reference implementation for deploying ultra-lightweight open-source language models entirely in the browser with no server infrastructure required. This project demonstrates how to overcome browser constraints to deliver a functional LLM experience across all devices.

Technical Implementation Details

Core Technologies

  • 🧠 Model Framework: @xenova/[email protected] - Browser-optimized fork of Hugging Face Transformers
  • ⚙️ Execution Engine: WebAssembly (WASM) with SIMD support for tensor operations
  • 📱 Mobile Optimization: Responsive design + memory constraints handling for mobile browsers
  • ☁️ Deployment: Pure static files on GitHub Pages (zero backend)

Key Technical Achievements

  • Complete Client-Side Execution: All model loading, tokenization, and inference happens in-browser
  • Memory Management System:
    • Model unloading after 10 minutes of inactivity
    • Browser memory API monitoring
    • Progressive loading indicators
  • Mobile Browser Compatibility:
    • Touch-friendly interface
    • Reduced memory footprint strategies
    • Network condition awareness
  • Streaming Response Handling: Real-time token generation display
  • Cancellation Support: AbortController integration for long-running generations

Technical Constraints Addressed

Challenge Solution
Large model size (~2GB) Lazy loading (only on first interaction)
Browser memory limits Active monitoring + model unloading
Mobile device limitations Reduced token generation parameters
WebAssembly initialization Progress callbacks + loading states
Network reliability Browser caching strategies

Why This Implementation Matters

This project demonstrates that modern browsers can execute meaningful language models without server infrastructure, enabling:

  • Privacy-preserving AI applications
  • Offline-capable language tools
  • Zero-cost deployment for educational demos
  • Cross-platform compatibility (desktop/mobile)

The implementation specifically targets the technical challenges of browser-based LLMs rather than focusing on any particular model, making it a valuable reference for developers exploring this emerging space.

DEMO

https://harisnae.github.io/browser-based-LLM/

About

Ultra-lightweight open-source LLM implementation running entirely client-side using transformers.js - GitHub Pages deployable with mobile optimization and browser memory management

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published