How 1bit-monster/engine works
1bit engine is a model-serving backend hosted by Lemonade. Its main workflow is an OpenAI-compatible request entering 1bit serve, then being proxied or routed to a model/device and returned to the client. The repository also contains NPU inference, Laya request classification, Project Manager delegation, MoE expert caching, and model-registry tooling. Several subsystems are documented but not sampled in implementation excerpts, so their links are limited to README-supported relationships; unsampled implementation details are not inferred.
Main entry points: serve.cpp Serve gateway · main.cpp Command entry · generate.cpp NPU generation · q4nx_forward.cpp Q4NX forward
Components 23
Serving and routing
- Serve gateway
app/serve.cpp - Command entry
app/main.cpp - Memory admission
app/mem_admit.h - Unified serving
app/unified.cpp - Forward server
app/forward_serve.cpp
NPU inference
- NPU model reader
npu/forward/src/model.c - NPU tokenizer
npu/tokenizer.cpp - NPU generation
npu/generate.cpp - Q4NX forward
npu/forward/src/q4nx_forward.cpp - NPU runtime interface
npu/rt.h
Classification and delegation
- Project Manager
app/pm.cpp - Laya policy
laya/policy.cpp - Laya routing
laya/route.cpp - Laya scorer
laya/scorer.cpp
Model capabilities
- MoE expert cache
moe/expert_cache.cpp - GGUF expert index
moe/gguf_index.cpp - Model registry
tools/registry_build.py - Architecture census
tools/census_watch.py - HRX GPU route
app - DwarfStar route
app - ONNX Runtime GenAI
app
Other components
- Lemonade host
- API client
Connections 19
- Lemonade host → Serve gateway: hosts backend
README.md - API client → Serve gateway: sends requests
README.md - Command entry → Serve gateway: dispatches
app/main.cpp - Serve gateway → Memory admission: checks memory
app/serve.cpp - Serve gateway → Project Manager: configures delegation
app/serve.cpp - Serve gateway → Laya scorer: configures classification
app/serve.cpp - Serve gateway → Laya policy: routes requests
app/serve.cpp - Serve gateway → Laya routing: routes requests
app/serve.cpp - Command entry → Unified serving: dispatches
app/main.cpp - Command entry → Forward server: dispatches
app/main.cpp - NPU generation → NPU model reader: loads model
- NPU generation → NPU tokenizer: tokenizes input
- NPU generation → Q4NX forward: runs inference
- Q4NX forward → NPU runtime interface: uses runtime
npu/forward/src/q4nx_forward.cpp - MoE expert cache → GGUF expert index: uses index
- Architecture census → Model registry: updates coverage
- Serve gateway → HRX GPU route: selects GPU route
README.md - Serve gateway → DwarfStar route: selects model route
README.md - Serve gateway → ONNX Runtime GenAI: selects CPU route
README.md