inference-factory-sim is a trace-driven laboratory for testing a specific
hypothesis:
Cheap frontier-model inference is an emergent property of high decode utilization, speculative generation, workload-aware MoE placement, tiered KV reuse, low precision, and prefill/decode specialization—not one magic kernel.
The repository converts that hypothesis into an inspectable model. It does not claim to reproduce DeepSeek's private infrastructure or provide cycle-accurate GPU simulation.
Read the companion long-form article: The model is not the product. The factory is.
- Continuous batching from request arrival rate and visible stream duration.
- Separate prefill and decode pools.
- Exact-prefix KV reuse across HBM, DRAM, and NVMe LRU tiers.
- Workload-dependent speculative-decoding acceptance.
- MoE expert hotspots, slowest-rank efficiency, and redundant hot experts.
- Low-precision, fused-kernel, and communication-overlap gains.
- API revenue, energy, capex depreciation, gross margin, and GPU payback.
Every optimization is independently switchable through TOML configuration.
No third-party runtime dependencies are required.
python -m venv .venv
.venv/Scripts/activate
python -m pip install -e .
inference-factory compare --config configs/factory.tomlWithout installation:
$env:PYTHONPATH = "src"
python -m inference_factory compare --config configs/factory.tomlGenerate machine-readable output:
inference-factory compare --config configs/factory.toml --json
inference-factory compare --config configs/factory.toml --output results/comparison.jsonRun one scenario rather than the built-in baseline comparison:
inference-factory simulate --config configs/factory.tomlThe compare command generates one deterministic request trace and runs it
through two configurations:
baseline: no tiered cache, speculation, continuous batching, expert replication, low precision, fusion, communication overlap, or P/D split.factory: the switches and factors from the supplied configuration.
Both sides therefore see identical prompts, outputs, prefix popularity, expert activation tendencies, and arrival times.
The principal decode relation is:
effective decode tok/s/GPU =
base saturated throughput
× batch efficiency
× precision gain
× fused-kernel gain
× communication-overlap gain
× realized speculative gain
× slowest-rank expert efficiency
Speculative gain is discounted because accepted tokens per verification pass do not translate perfectly into wall-clock speedup. Draft overhead and divergence remain.
cache hit rateis the fraction of all input tokens restored from reusable prefix KV, not request hit rate.batch efficiencyapproximates how fully the serving fleet amortizes model weight movement.speculative tokens/passis realized throughput gain after overhead, not raw draft acceptance length.expert efficiencyis mean GPU expert load divided by the slowest GPU load.required GPU-hoursis useful accelerator work for the trace.modeled infra costcharges useful work attarget_utilization; it assumes a shared fleet can absorb spare capacity.gross marginincludes accelerator depreciation and electricity only. It excludes networking, storage capex, CPUs, staff, tax, R&D, and financing.paybackis an inference-unit economic indicator, not an accounting forecast.
src/inference_factory/
cache.py exclusive HBM/DRAM/NVMe KV hierarchy
moe.py expert activation and replica placement
workload.py deterministic mixed request traces
simulator.py throughput and economics engine
config.py strict TOML loader
cli.py command-line interface
configs/
factory.toml DeepSeek-like hypothesis, using public-style assumptions
conservative.toml
tests/
docs/
MODEL.md equations, boundaries, and extension points
python -m unittest discover -s tests -vThis is a comparative systems model. Absolute results depend strongly on the calibration values. In particular:
- Optimization factors overlap in real systems.
- Actual expert activation traces are model- and traffic-specific.
- Prefix reuse requires exact token prefixes.
- SSD is modeled as persistence/restoration, not as storage read on every decoding step.
- A provider's reported gross margin cannot be inferred from hardware throughput alone.
Use the simulator to ask “which combination could explain the economics?” and to run sensitivity analyses—not to assert undisclosed company facts.