Skip to content

Real Semantic Embeddings & Mobile Optimization

Pre-release
Pre-release

Choose a tag to compare

@qwatts-dev qwatts-dev released this 21 Feb 17:20
117ef8c

This release marks a major milestone: the WebGPU pipeline is no longer running on mock data. It now successfully extracts, loads, and processes the actual high-precision semantic embeddings from Microsoft's bitnet-b1.58-2B-4T model, running end-to-end on desktop, tablet, and mobile devices.

Key Features

  • Real Semantic Embeddings: Replaced the PRNG mock embeddings with the true 2,560-dimensional vectors used by the BitNet model. When you type "Hello", the GPU processes the exact mathematical concept of that word.
  • Mobile Memory Wall Conquered: Implemented a "Vocab-Slice" strategy to bypass strict iOS WebKit memory limits. By extracting the top 16,384 most common English tokens (plus domain-specific tokens like "WebGPU") and converting them to Float16, the embedding dictionary size was reduced from a crushing 1.3 GB down to a mobile-friendly 80 MB.
  • Cross-Device Determinism: The pipeline produces bit-exact identical output across an iPhone 14 Pro Max (A16), iPad Air (M3), and MacBook Pro (M2 Max).
  • Interactive Latency on Edge Devices: An iPhone 14 Pro Max successfully processes the 17.7 million ternary parameters of the down_proj layer in just 27 ms.

Technical Changes

  • Added extract_sparse_embeddings.py to slice the Hugging Face model.embed_tokens.weight tensor into a sparse FP16 binary and generate a vocab_map.json.
  • Updated bitnet-kernel.js to fetch the sparse dictionary, perform OOV (Out-of-Vocabulary) fallback, convert FP16 to Float32 on the fly, and zero-pad the vector to match the GPU kernel's expected 6,912 input dimension.
  • Configured Git LFS to track the .bin weight and embedding files.

Benchmarks (Interactive Mode)

  • MacBook M2 Max: 6.3 ms compute
  • iPad 13" M3: 10.0 ms compute
  • iPhone 14 Pro Max: 27.0 ms compute