Skip to content

The Sampling Engine

Pre-release
Pre-release

Choose a tag to compare

@qwatts-dev qwatts-dev released this 22 Feb 03:14
361a782

This release replaces rigid greedy decoding (argmax) with a robust LLM sampling engine, enabling dynamic and varied text generation while successfully breaking infinite hallucination loops.

Key Architectural Updates:

  • Advanced Token Sampling: Implemented sampleToken() featuring Temperature scaling, Top-K filtering, and Top-P (Nucleus) sampling.
  • Frequency Penalty: Replaced the flat presence penalty with an exponentially scaling frequency penalty (Map<sparseIdx, count>). This aggressively taxes repeated tokens (penalty^count), successfully forcing the single-layer (Layer 0) engine out of its mathematical feedback loop ("mass mass mass").
  • W1.58A8 Parked: The W1.58A8 Activation Quantization shader was successfully written but parked. WebGPU does not yet expose hardware-accelerated integer dot products (DP4a) on Apple Silicon, meaning the FP32 pipeline remains mathematically faster for now. The 2-bit packed weights (W1.58) are already memory-efficient enough (~442 MB for 26 layers) to fit within the iOS 1.5 GB memory limit.

Performance Benchmarks (Layer 0):

  • MacBook Pro M2 Max: Sustained ~43.4 ms/token (~23 tokens per second) utilizing the restored FP32 WGSL pipeline.