LLMTraceFX is an evidence-first inference toolkit for local models and
OpenAI-compatible streaming APIs. It collects measurements into one canonical
schema, checks model output with deterministic workloads, and recommends a
configuration only when it satisfies an explicit policy.
Related project: agent-strace
records coding-agent sessions (tool calls and decisions). LLMTraceFX measures
inference requests. The two share no code or dependencies; both can export
OpenTelemetry.
Demo
The evidence viewer Space
loading one real collect-api request to a local llama.cpp server
(Qwen2.5-0.5B-Instruct Q4_K_M, Apple M5 Pro) with its server metrics, then the
exported trace in Perfetto. It is a single request, not a benchmark result.
https://github.com/user-attachments/assets/fb060a1a-79d6-4f66-8d0c-735f92f0e793
Research / Publication
Research based on earlier LLMTraceFX work is published as the peer-reviewed
conference paper Understanding GPU-Level Bottlenecks in Large Language Model
Inference by Shubhanshu
Kushwaha, Mamata Samal, and Siddhant Khare. It appears in the Proceedings of
International Conference on Data, Electronics and Computing: ICDEC 2025, Volume
1, Lecture Notes in Networks and Systems, vol. 2003 (Springer, Cham, 2026),
pp. 211–224; first online August 2, 2026.
The paper discusses profiling LLM inference with LLMTraceFX, including memory
bandwidth, GPU interconnects, kernel overhead, and prefill/decoding. It reflects
an earlier research snapshot: this repository has continued evolving, and
current features and results should not be assumed to appear in or have been
validated by the paper.
@inproceedings{kushwaha2026gpu,
author = {Shubhanshu Kushwaha and Mamata Samal and Siddhant Khare},
title = {Understanding GPU-Level Bottlenecks in Large Language Model Inference},
booktitle = {Proceedings of International Conference on Data, Electronics and Computing: ICDEC 2025, Volume 1},
series = {Lecture Notes in Networks and Systems},
volume = {2003},
pages = {211--224},
publisher = {Springer},
address = {Cham},
year = {2026},
doi = {10.1007/978-3-032-27448-9_18},
url = {https://doi.org/10.1007/978-3-032-27448-9_18}
}
For research collaboration, reproducibility questions, or LLMTraceFX usage,
contact siddhantkhare2694@gmail.com.
Please use GitHub Issues
for bug reports.
KV-cache truth auditor demo
From a clean checkout, one offline command builds and verifies the deterministic
public proof:
make kv-cache-demo
It prints an expected-vs-observed table and writes the machine-readable table,
hash-bound evidence bundle, report, claim matrix, privacy-checked manifest, and
standalone verifier under build/kv-cache-truth-demo/. Representative rows:
| case |
input |
expected tokens/blocks |
attested tokens/blocks |
observed prompt work |
verdict |
output identity |
evaluator |
output/performance/quality eligibility |
| exact-duplicate |
9 |
8/n/a |
8/n/a |
1 |
verified_hit |
yes |
yes |
eligible/ineligible/not_applicable |
| interior-mutation |
9 |
3/n/a |
3/n/a |
6 |
partial_reuse |
yes |
yes |
eligible/ineligible/not_applicable |
| boundary-mutation |
9 |
4/n/a |
4/n/a |
5 |
partial_reuse |
yes |
yes |
eligible/ineligible/not_applicable |
| same-length-different-ids |
9 |
0/n/a |
0/n/a |
9 |
verified_miss |
yes |
yes |
eligible/ineligible/not_applicable |
| suffix-change |
9 |
8/n/a |
8/n/a |
1 |
partial_reuse |
yes |
yes |
eligible/ineligible/not_applicable |
| namespace-isolation |
9 |
0/n/a |
0/n/a |
9 |
verified_miss |
yes |
yes |
eligible/ineligible/not_applicable |
| capacity-revisit |
4 |
0/n/a |
0/n/a |
4 |
evicted |
yes |
yes |
eligible/ineligible/not_applicable |
The token-granular reference cache has no block observation, so block cells are
n/a. Timing and runtime memory remain null; the demo invents no benchmark
measurements. The seed, cold, and capacity-pressure rows are retained in
truth-table.json because they are part of the independently verified state
transition proof.
Verify the generated bundle without trusting the installed entry point:
uv run --offline --no-sync python -I \
build/kv-cache-truth-demo/bundle/evidence_bundle.py verify \
--public-dir build/kv-cache-truth-demo/bundle \
--package-root .
This proves the auditor, independent oracle, synthetic attestation, output
evaluator, schemas, claim matrix, privacy checks, hashes, and verifier behavior.
It does not prove MLX or vLLM speedup, production cache correctness,
provider identity, GPU performance, latency improvement, or runtime memory
savings.
The main workflow is:
- Measure with a collector or import an existing runtime artifact.
- Verify the response against a pinned workload and retain failed or
incomplete evidence.
- Compare and tune candidates under one objective and stated constraints.
- Optimize only after the collected evidence supports a recommendation.
Install
uv tool install llmtracefx
This installs the llmtracefx-* commands from
PyPI into their own environment and puts
them on your PATH. The base install has no third-party runtime dependencies.
Extras use the usual syntax, for example uv tool install "llmtracefx[mlx]" on
macOS arm64. yaml adds YAML configs and policies (JSON needs nothing), and
legacy adds the dependencies of the earlier analyzer, API, and dashboard.
- Run one command without installing:
uvx --from llmtracefx llmtracefx-optimizer --help.
- Use the library in a project:
uv add llmtracefx.
pip install llmtracefx also works.
The Quickstart below clones the repository instead, because it reads example
files from the source tree and uses the locked dependencies.
Quickstart
The LLMTraceFX commands in this path use no API key, model download, network
request, or accelerator. Cloning the repository and installing uncached
dependencies can use the network. The commands then audit the environment,
materialize a deterministic workload plan, and write an inspectable API request
plan.
git clone https://github.com/Siddhant-K-code/LLMTraceFX.git
cd LLMTraceFX
uv sync --locked
mkdir -p output/quickstart
uv run llmtracefx-optimizer manifest \
--output output/quickstart/environment.json
uv run llmtracefx-optimizer workloads generate-matrix \
--model-id example/local-model \
--model-family qwen3_next \
--context-tiers 2k \
--max-tokens 16 \
--output-dir output/quickstart/matrix
env -u LLMTRACEFX_QUICKSTART_NO_KEY uv run llmtracefx-optimizer collect-api \
--run-id api-plan \
--provider example \
--endpoint https://example.com/v1/chat/completions \
--model-id example-model \
--prompt-file examples/optimizer/api-smoke-prompt.txt \
--output-dir output/quickstart/api-plan \
--api-key-env LLMTRACEFX_QUICKSTART_NO_KEY \
--dry-run
The last command writes output/quickstart/api-plan/request_plan.json. Its
network_request_performed field is false, and the dry run does not read an
API credential because the named variable is explicitly unset. In general, a
dry run does not require or transmit a credential. If its named variable is
already set, it reads the value only to detect unsafe embedding and redact the
plan.
Two more offline commands describe the optional Modal deployment harness:
uv run llmtracefx-deploy recipe
uv run llmtracefx-deploy budget --credit-usd 30
Neither command imports Modal, authenticates, creates resources, or performs a
network request.
Measure a model on a local server
The commands above send nothing. To end in a measured result, point
workloads run-api at an OpenAI-compatible server you already run. This path
was tested with Ollama 0.35.1 and mlx_lm.server on an Apple M5 Pro laptop.
After the model is pulled (about 400 MB), run-api takes a few seconds.
ollama pull qwen2.5:0.5b-instruct-q4_K_M
uv run llmtracefx-optimizer workloads generate-matrix \
--model-id qwen2.5:0.5b-instruct-q4_K_M \
--model-family qwen2 \
--context-tiers 2k \
--output-dir output/quickstart/local-matrix
export LLMTRACEFX_LOCAL_KEY=local-server-ignores-this-placeholder
uv run llmtracefx-optimizer workloads run-api \
--matrix output/quickstart/local-matrix/manifest.json \
--output-dir output/quickstart/local-results \
--provider ollama \
--endpoint http://localhost:11434/v1/chat/completions \
--model-id qwen2.5:0.5b-instruct-q4_K_M \
--api-key-env LLMTRACEFX_LOCAL_KEY \
--mode autoregressive \
--category structured_json prose_reasoning
uv run llmtracefx-optimizer workloads summarize \
--results output/quickstart/local-results
run-api prints each row's status and, for a completed row, whether the model
passed the task. A 0.5B model typically gets the JSON task right and misses
the reasoning one:
[COMPLETED] structured-json-profile-extraction-2k-autoregressive (task pass: structured_json_exact_field_match=1.00)
[COMPLETED] prose-reasoning-two-train-gap-2k-autoregressive (task fail: exact_answer_pattern_match=0.00)
A row can instead end failed (the server returned an error or the stream
broke), inconclusive (the answer could not be graded) or unsupported.
summarize prints the pass rate and correct cases per minute as JSON. Each
row's evidence is under output/quickstart/local-results/runs/<row>/.
- Credential:
run-api always reads a key from the variable named by
--api-key-env and refuses an empty one. These servers ignore it, so any
placeholder works. Choose one the model will not write, because the key is
redacted wherever it appears in a stored response. Plain http is accepted
only for localhost, 127.0.0.1 and ::1, and such a request skips any
configured proxy.
- Other servers: for
mlx_lm.server or llama-server, set --endpoint
to http://localhost:8080/v1/chat/completions (both default to port 8080),
--model-id to the model the server loaded, and --provider to a label for
the evidence. Only Ollama and mlx_lm.server were tested.
- Measured: the client-observed wall clock of each row (time to first
token, the gaps between streamed deltas, and total time) and the task
verdict. The first row includes the server loading the model if it was not
loaded yet. For a warm measurement, rerun
run-api with a new
--output-dir.
- Not measured: energy or power, memory, a prefill and decode split, and
token counts. Ollama reports usage in a stream only when the request asks for
it, and
run-api does not ask.
- Code rows:
code_completion rows are graded by running the answer, which
run-api refuses for any endpoint. Run them with workloads run against a
local MLX checkpoint.
Current capabilities
Canonical evidence
Inference collectors and the llama.cpp importer produce ExperimentRecord
schema version 1. Instruments collection writes a separate, typed evidence
record for trace capabilities and supported Metal tables. Numeric measurements
carry a unit and a provenance:
measured_native
measured_wall_clock
provider_reported
derived
estimated
Unavailable observations remain absent. They are not converted to zeros or
relabelled as measurements.
Collection
- MLX and MLX-LM: run an existing local model directory on Apple silicon
and record normalized timing and memory evidence. LLMTraceFX does not
download the model.
- OpenAI-compatible streaming APIs: record client-observed headers,
first-byte timing, first visible content, inter-event timing, completion
state, and provider-reported usage without persisting the credential.
- llama.cpp: convert captured stdout and stderr into the canonical evidence
schema. This parser does not launch or configure llama.cpp.
- Ollama native API: stream one request through
/api/chat or
/api/generate and record the server's own load_duration,
prompt_eval_duration, eval_duration, total_duration and token counts
(including prompt_eval_cached_count) as provider_reported, next to the
client-measured TTFT and gaps between chunks. Ollama's OpenAI-compatible
route drops these timers.
- Apple Instruments: check
xctrace capability, print an execution plan,
record a local command, or import an existing trace bundle. Supported Metal
tables are reported narrowly rather than treated as generic GPU utilization.
- NVIDIA GPU energy (NVML): run one command and record device wide GPU
energy from the driver's energy counter, plus sampled power. Totals are only
highlighted when no other process used the GPU during the window. A running
dcgm-exporter can be read instead with
--source dcgm-exporter, and AMD
GPUs with --source amdsmi.
- Native Qwen MTP: emit a capability report and an explicit unsupported
record when the installed stack cannot produce trustworthy native-MTP
evidence.
- Server-side metrics (vLLM, SGLang, llama.cpp, TensorRT-LLM, NVIDIA
Dynamo, legacy TGI):
snapshot a Prometheus endpoint before and after a run and diff the two.
Server numbers such as queue time, server TTFT and cached prompt tokens by
cache tier are only reported when the window provably contains exactly the
requests you sent. Otherwise the window is marked
contaminated,
incomplete, counter_reset, stats_not_enabled, or unverifiable. KV
cache usage is recorded as a point sample at each scrape. The TGI profile
is legacy: Text Generation Inference is archived upstream, so the profile
still reads existing servers with the same exit codes, adds a note to the
evidence (server-metrics diff also prints it to stderr), and gets no new
metrics.
- Trace replay (Mooncake, BurstGPT requests and sessions, AIPerf
single_turn and multi_turn, Weka agentic sessions, GitHub Copilot coding
agent sessions, OpenTelemetry GenAI spans): check a published
arrival trace, plan its schedule offline, and replay it against an
OpenAI-compatible endpoint at the recorded arrival times. Synthetic prompts
keep Mooncake's and Weka's prefix sharing. export otlp output replays
directly. A malformed trace is refused, not repaired.
Export to observability tools