inferdiff 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- inferdiff-0.1.0/LICENSE +21 -0
- inferdiff-0.1.0/PKG-INFO +165 -0
- inferdiff-0.1.0/README.md +138 -0
- inferdiff-0.1.0/pyproject.toml +44 -0
- inferdiff-0.1.0/setup.cfg +4 -0
- inferdiff-0.1.0/src/inferdiff/__init__.py +64 -0
- inferdiff-0.1.0/src/inferdiff/__main__.py +10 -0
- inferdiff-0.1.0/src/inferdiff/canary.py +1431 -0
- inferdiff-0.1.0/src/inferdiff/cli.py +490 -0
- inferdiff-0.1.0/src/inferdiff/detectors.py +423 -0
- inferdiff-0.1.0/src/inferdiff/dialects/__init__.py +41 -0
- inferdiff-0.1.0/src/inferdiff/dialects/ollama_ndjson.py +94 -0
- inferdiff-0.1.0/src/inferdiff/dialects/openai_chat.py +113 -0
- inferdiff-0.1.0/src/inferdiff/dialects/openai_responses.py +180 -0
- inferdiff-0.1.0/src/inferdiff/dialects/sglang_native.py +68 -0
- inferdiff-0.1.0/src/inferdiff/differ.py +649 -0
- inferdiff-0.1.0/src/inferdiff/exporter.py +482 -0
- inferdiff-0.1.0/src/inferdiff/probes/__init__.py +5 -0
- inferdiff-0.1.0/src/inferdiff/probes/base.py +52 -0
- inferdiff-0.1.0/src/inferdiff/recorder.py +918 -0
- inferdiff-0.1.0/src/inferdiff/redact.py +355 -0
- inferdiff-0.1.0/src/inferdiff/schema.py +955 -0
- inferdiff-0.1.0/src/inferdiff/waterfall.py +771 -0
- inferdiff-0.1.0/src/inferdiff.egg-info/PKG-INFO +165 -0
- inferdiff-0.1.0/src/inferdiff.egg-info/SOURCES.txt +29 -0
- inferdiff-0.1.0/src/inferdiff.egg-info/dependency_links.txt +1 -0
- inferdiff-0.1.0/src/inferdiff.egg-info/entry_points.txt +2 -0
- inferdiff-0.1.0/src/inferdiff.egg-info/requires.txt +6 -0
- inferdiff-0.1.0/src/inferdiff.egg-info/top_level.txt +1 -0
- inferdiff-0.1.0/tests/test_doctor_and_waterfall.py +692 -0
- inferdiff-0.1.0/tests/test_inferdiff.py +1163 -0
inferdiff-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ApacheWang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
inferdiff-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: inferdiff
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Wireshark for streaming LLMs: catch HTTP 200 silent truncations, broken tool JSON, fake SSE relays & usage drops.
|
|
5
|
+
Author: ApacheWang
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/ApacheWang/inferdiff
|
|
8
|
+
Project-URL: Repository, https://github.com/ApacheWang/inferdiff
|
|
9
|
+
Project-URL: Issues, https://github.com/ApacheWang/inferdiff/issues
|
|
10
|
+
Keywords: llm,inference,sse,streaming,vllm,llama-cpp,sglang,ollama,litellm,testing
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Software Development :: Testing
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Provides-Extra: httpx
|
|
23
|
+
Requires-Dist: httpx>=0.27; extra == "httpx"
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# inferdiff
|
|
29
|
+
|
|
30
|
+
[](https://github.com/ApacheWang/inferdiff/actions/workflows/ci.yml)
|
|
31
|
+
[](https://github.com/ApacheWang/inferdiff)
|
|
32
|
+
[](https://github.com/ApacheWang/inferdiff/blob/main/pyproject.toml)
|
|
33
|
+
[](https://github.com/ApacheWang/inferdiff/blob/main/LICENSE)
|
|
34
|
+
|
|
35
|
+
**Wireshark & protocol bill-checker for streaming LLM APIs.**
|
|
36
|
+
|
|
37
|
+
Catch silent `HTTP 200 OK` failures — truncated tool JSON, ghost thinking starvation, buffered nonconformant SSE relays, and illusory benchmark speedups — with **zero third-party runtime dependencies** (Python 3.11+ standard library only).
|
|
38
|
+
|
|
39
|
+
[中文文档 (README.zh-CN.md)](https://github.com/ApacheWang/inferdiff/blob/main/README.zh-CN.md)
|
|
40
|
+
|
|
41
|
+

|
|
42
|
+
|
|
43
|
+
## Why `inferdiff`? (`HTTP 200 OK` != Your Stream Worked)
|
|
44
|
+
|
|
45
|
+
Standard uptime monitors and latency benchmarks only check HTTP status codes and wall-clock speed. In production, streaming LLM upgrades and third-party OpenAI-compatible relays routinely return `200 OK` while silently corrupting wire contracts:
|
|
46
|
+
|
|
47
|
+
| Who Gets Burned | What Breaks Silently Under `HTTP 200 OK` | Real-World Bug Anchors | How `inferdiff` Catches It |
|
|
48
|
+
| :--- | :--- | :--- | :--- |
|
|
49
|
+
| **Agent & App Engineers** | Tool-call JSON arguments are cut off mid-string by token budgets yet reported as `completed` / `stop`, reasoning tokens starve `content` to empty, or chunk splits emit `U+FFFD` replacement chars — sending agents into retry loops. | [`llama.cpp #30773`](https://github.com/ggml-org/llama.cpp/issues/30773), [`Ollama #17274`](https://github.com/ollama/ollama/issues/17274), [`vLLM #68324`](https://github.com/vllm-project/vllm/issues/68324) | Rules `D1`, `D2` & Canary `C1`, `C2`, `C6` validate strict JSON syntax trees, UTF-8 multibyte boundaries, and terminal state honesty. |
|
|
50
|
+
| **API Relay & Gateway Users** | Proxies buffer upstream non-streaming responses and dump them as a fake SSE burst, strip trailing `include_usage` chunks, undercount tool-schema tokens, strip initial `delta.role`, or route across mixed-quantization pools. | [`LiteLLM #5803`](https://github.com/BerriAI/litellm/issues/5803), [`LiteLLM #16112`](https://github.com/BerriAI/litellm/issues/16112), [`LiteLLM #24221`](https://github.com/BerriAI/litellm/issues/24221), [vLLM Streaming Usage](https://docs.vllm.ai/en/latest/serving/online_serving/derenderer/) | `inferdiff doctor --profile relay` runs low-budget canary probes (`C1–C8`) and grades wire health from `A+` to `F`. |
|
|
51
|
+
| **AI Infra & Perf Engineers** | Engine upgrades report massive throughput/TTFT jumps because fixed-length `ignore_eos` runs stopped at `8 / 8000` tokens, prefix caches leaked across runs, or empty handshake frames gamed first-frame timers. | [`SGLang #53119`](https://github.com/sgl-project/sglang/pull/53119), [`SGLang #50443`](https://github.com/sgl-project/sglang/issues/50443), [vLLM Benchmarking CLI](https://docs.vllm.ai/en/stable/benchmarking/cli/) | Separates empty handshake `ttff_ms` from real `ttft_effective_ms` and flags short-generation & cache-pollution illusions (`D3`, `D5`). |
|
|
52
|
+
| **OSS Contributors & Release CI** | SSE chunk boundaries shift between runs, making raw `curl` logs impossible to diff by eye — while noisy log dumps get closed upstream. | [rusefi LLM Policy](https://github.com/rusefi/rusefi/wiki/LLM-policy) | Normalizes chunk jitter, pins the **exact first divergent wire frame**, and exports an airgapped `<80 KiB` HTML waterfall or a `<=25`-line redacted `curl` reproducer. |
|
|
53
|
+
|
|
54
|
+
## Quickstart
|
|
55
|
+
|
|
56
|
+
Zero-install via [`uvx`](https://docs.astral.sh/uv/guides/tools/) directly from GitHub, or install locally with `pip` (Python 3.11+, zero runtime dependencies):
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# 1. Zero-install live health check on a local engine (llama-server, vLLM, SGLang, Ollama)
|
|
60
|
+
uvx --from git+https://github.com/ApacheWang/inferdiff inferdiff \
|
|
61
|
+
doctor http://127.0.0.1:8080/v1 --html doctor.html
|
|
62
|
+
|
|
63
|
+
# 2. Audit an OpenAI-compatible relay API + generate shareable single-file HTML scorecard
|
|
64
|
+
OPENAI_API_KEY=sk-... uvx --from git+https://github.com/ApacheWang/inferdiff inferdiff \
|
|
65
|
+
doctor https://api.your-relay.example/v1 \
|
|
66
|
+
--model qwen3-32b --profile relay --html relay-report.html
|
|
67
|
+
|
|
68
|
+
# 3. Or install once locally (or clone this repo to try bundled golden examples offline)
|
|
69
|
+
pip install git+https://github.com/ApacheWang/inferdiff
|
|
70
|
+
|
|
71
|
+
# Offline demo on bundled Case 1 (llama.cpp #30773, no GPU or server required)
|
|
72
|
+
inferdiff diff \
|
|
73
|
+
examples/case1_responses_truncated_tool/baseline.trace.jsonl \
|
|
74
|
+
examples/case1_responses_truncated_tool/target.trace.jsonl \
|
|
75
|
+
--html case1-waterfall.html
|
|
76
|
+
|
|
77
|
+
inferdiff export \
|
|
78
|
+
examples/case1_responses_truncated_tool/baseline.trace.jsonl \
|
|
79
|
+
examples/case1_responses_truncated_tool/target.trace.jsonl \
|
|
80
|
+
--format github-issue
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
> **Auth note**: If neither `--api-key` nor `-H "Authorization: ..."` is passed, `inferdiff doctor` falls back to `OPENAI_API_KEY` from the environment and sends it to the target URL (use `https://` for production keys). Reflected secrets are scrubbed from terminal output, saved traces, JSON, and HTML exports.
|
|
84
|
+
|
|
85
|
+
## Single-File Offline HTML Frame Waterfall
|
|
86
|
+
|
|
87
|
+
Every `diff --html`, `audit --html`, `doctor --html`, and `export --format html` command produces a self-contained, airgap-safe HTML5 + inline SVG report strictly under `80 KiB` with zero external CDN requests:
|
|
88
|
+
|
|
89
|
+

|
|
90
|
+
|
|
91
|
+
> GitHub Markdown strips interactive SVG scripts; download [`case1-waterfall.html` from the `v0.1.0` Release](https://github.com/ApacheWang/inferdiff/releases/tag/v0.1.0) to hover frame timings, toggle Absolute ms / Normalized %, and click any lane segment offline.
|
|
92
|
+
|
|
93
|
+
## Canary Probe Matrix (`inferdiff doctor`)
|
|
94
|
+
|
|
95
|
+
| Probe | Target Failure Mode | Profiles | Upstream Anchor |
|
|
96
|
+
| :--- | :--- | :--- | :--- |
|
|
97
|
+
| `C1` (P0) | Truncated tool-call JSON claiming `stop`/`completed` (plus `/v1/responses` cross-check in `full`) | `quick`, `full`, `relay` | [`llama.cpp #30773`](https://github.com/ggml-org/llama.cpp/issues/30773) |
|
|
98
|
+
| `C2` (P0) | Reasoning swallows budget -> empty visible output claiming `stop` | `full`, `relay` | [`Ollama #17274`](https://github.com/ollama/ollama/issues/17274) |
|
|
99
|
+
| `C3` (P1) | `ignore_eos=true` fixed-length budget mismatch (auto-`SKIP` on HTTP 400/422) | `full` | [`SGLang #53119`](https://github.com/sgl-project/sglang/pull/53119) |
|
|
100
|
+
| `C4` (P1) | Stripped trailing empty-`choices` `include_usage` chunk or omitted tool-schema tokens | `quick`, `full`, `relay` | [`LiteLLM #16112`](https://github.com/BerriAI/litellm/issues/16112), [`#28553`](https://github.com/BerriAI/litellm/issues/28553) |
|
|
101
|
+
| `C5` (P1/P0) | Missing initial `delta.role`, omitted/invalid raw indices, or parallel tool index collision | `quick`, `full`, `relay` | [`LiteLLM #24221`](https://github.com/BerriAI/litellm/issues/24221) |
|
|
102
|
+
| `C6` (P0) | Multi-byte UTF-8 / 4-byte emoji `U+FFFD` corruption or swallowed stream tail | `quick`, `full`, `relay` | [`vLLM #68324`](https://github.com/vllm-project/vllm/issues/68324), [`#47161`](https://github.com/vllm-project/vllm/issues/47161) |
|
|
103
|
+
| `C7` (P1) | Buffered non-streaming response dumped as a fake SSE burst | `quick`, `full`, `relay` | [`LiteLLM #5803`](https://github.com/BerriAI/litellm/issues/5803) |
|
|
104
|
+
| `C8` (P2) | Randomized-prefix same-seed heterogeneous backend pool drift (advisory) | `full`, `relay` | [vLLM Benchmarking CLI](https://docs.vllm.ai/en/stable/benchmarking/cli/) |
|
|
105
|
+
|
|
106
|
+
## Recording, Side-by-Side Comparison & Bundled Examples
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# Record one request or a multi-line .jsonl suite (strict RFC 9112 framing + per-frame flush)
|
|
110
|
+
inferdiff record --url http://127.0.0.1:8080/v1/responses -d request.json -o target.trace.jsonl
|
|
111
|
+
|
|
112
|
+
# Compare two live endpoints sequentially with per-target scoped credentials
|
|
113
|
+
inferdiff compare \
|
|
114
|
+
--before-url http://127.0.0.1:8080/v1/chat/completions \
|
|
115
|
+
--after-url http://127.0.0.1:8081/v1/chat/completions \
|
|
116
|
+
--before-header "Authorization: Bearer $KEY_A" \
|
|
117
|
+
--after-header "Authorization: Bearer $KEY_B" \
|
|
118
|
+
-d request.json --save-dir ./traces --html compare.html --fail-on p1
|
|
119
|
+
|
|
120
|
+
# Additional bundled golden examples
|
|
121
|
+
inferdiff diff examples/case2_ollama_ghost_thinking_tokens/baseline.trace.jsonl \
|
|
122
|
+
examples/case2_ollama_ghost_thinking_tokens/target.trace.jsonl
|
|
123
|
+
inferdiff diff examples/case3_sglang_8_of_8000_short_gen/baseline.trace.jsonl \
|
|
124
|
+
examples/case3_sglang_8_of_8000_short_gen/target.trace.jsonl --fail-on p1
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Wire Health Grades & Deterministic CI Exit Codes
|
|
128
|
+
|
|
129
|
+
- **Doctor grades**: `A+` (all executed probes pass with zero skips/warnings), `A` (zero P0/P1 issues, advisory P2 warning or inconclusive/skipped probe), `B` (1 P1 warning), `C` (2+ P1 warnings), `F` (any P0 silent protocol breach or transport/HTTP error).
|
|
130
|
+
|
|
131
|
+
| Exit Code | Constant | Meaning |
|
|
132
|
+
| :--- | :--- | :--- |
|
|
133
|
+
| `0` | `EXIT_OK` | Gate passed (`doctor` grades `A+` / `A` / `B` / `C` without `--strict`) |
|
|
134
|
+
| `1` | `EXIT_USAGE_OR_IO_ERROR` | CLI usage error, malformed trace schema, unreachable endpoint, or non-200 HTTP failure |
|
|
135
|
+
| `2` | `EXIT_SILENT_PROTOCOL_BREACH` | Confirmed P0 silent protocol breach (`D1`, `D2`, `D4`, or `doctor` P0 `FAIL`) |
|
|
136
|
+
| `3` | `EXIT_SEMANTIC_REGRESSION` | P1 regression (`D3`, `D5`, terminal drift, TTFT regression, `--fail-on any-diff`, or `doctor --strict` P1 warn) |
|
|
137
|
+
|
|
138
|
+
## Airgap-Safe HTML Waterfall & Privacy Defaults
|
|
139
|
+
|
|
140
|
+
- Single-file HTML5 + inline SVG reports use a hash-locked CSP (`default-src 'none'; style-src 'unsafe-inline'; script-src 'sha256-...'; img-src data:;`) with zero external scripts, fonts, or stylesheets, and adaptive folding to stay strictly under `80 KiB`.
|
|
141
|
+
- Shareable exports (`export --format github-issue|json|html`, `diff --html`, `audit --html`, `doctor --html`) omit arbitrary request bodies and raw wire payloads by default; pass `--include-body` or `--include-wire` to `export` only after reviewing your trace.
|
|
142
|
+
|
|
143
|
+
## Positioning: How `inferdiff` Complements Existing Tools
|
|
144
|
+
|
|
145
|
+
`inferdiff` is intentionally scoped as a **wire-level surgical knife** (`git diff` + protocol bill-checker for streaming frames), not an all-in-one evaluation or load-testing platform. Use it alongside — not instead of — established ecosystem tools:
|
|
146
|
+
|
|
147
|
+
| Tool Category | Great Open-Source Options | Use Them When You Need To... | Use `inferdiff` When You Need To... |
|
|
148
|
+
| :--- | :--- | :--- | :--- |
|
|
149
|
+
| **Semantic & Agent Evals** | [promptfoo](https://github.com/promptfoo/promptfoo) | Grade prompt accuracy, RAG faithfulness, or red-team safety across models after responses are assembled. | Catch **wire-level silent corruption** under `HTTP 200 OK` (truncated tool JSON, missing `arguments.done`, `U+FFFD` chunk-split leaks) before SDKs even finish assembling text. |
|
|
150
|
+
| **Load & Throughput Benchmarks** | [GuideLLM](https://github.com/vllm-project/guidellm), [LLMPerf](https://github.com/ray-project/llmperf) | Measure multi-concurrency QPS, latency percentiles, and capacity curves under sustained load. | Verify your benchmark isn't **measuring an illusion** (e.g., `8 / 8000` short generation on `ignore_eos`, empty handshake frames gaming TTFT, or unisolated prefix caches). |
|
|
151
|
+
| **Broad Engine & Relay Suites** | [ddalcu/llmprobe](https://github.com/ddalcu/llmprobe), [lmspeed-audit](https://github.com/nexmoe/lmspeed-audit) | Run comprehensive Node.js capability scorecards (GPQA/AIME evals, surface coverage, or provider fingerprinting) using built-in test banks. | Run a **zero-dep Python CLI** inside GPU containers to **record & frame-diff your own failing production payloads** across `openai-chat`, `openai-responses`, `sglang-native`, and `ollama-ndjson`, and export a `<=25`-line upstream GitHub Issue. |
|
|
152
|
+
| **Interactive Local Proxies** | [StreamLens](https://github.com/alexandrmotologa/streamlens), [ForkMind](https://github.com/Medhovarsh/forkmind) | Route local app traffic through a persistent reverse proxy and inspect conversations interactively in a Web UI. | Run **stateless CLI / CI regression gates** (`Exit 0/1/2/3`) and generate `<80 KiB` airgap-safe single-file HTML frame waterfalls without deploying a proxy. |
|
|
153
|
+
|
|
154
|
+
### Explicit Non-Goals
|
|
155
|
+
|
|
156
|
+
- **No LLM-as-a-Judge or capability leaderboards**: `inferdiff` never grades prose quality, math/coding intelligence, or jailbreak resistance. Every verdict is a deterministic function of raw wire bytes, JSON syntax trees, and monotonic frame timestamps.
|
|
157
|
+
- **No heavy runtime stack**: Core CLI and HTML/SVG waterfall rendering stay 100% Python 3.11+ standard library (`0` mandatory `pip` packages, `0` Node.js runtime, `0` external CDN requests).
|
|
158
|
+
|
|
159
|
+
## Roadmap (v0.2: Non-Intrusive KV & Storage Probes)
|
|
160
|
+
|
|
161
|
+
`inferdiff.trace.v1` and `inferdiff.probes.base.BackendProbe` already expose the three-point snapshot lifecycle (`T_pre -> T_ttft -> T_eof`) for optional v0.2 plugins (`LmcacheMpProbe`, `MooncakeStoreProbe`, `LinuxProcIoProbe`) and storage x inference rules `D6`–`D8`.
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
MIT
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# inferdiff
|
|
2
|
+
|
|
3
|
+
[](https://github.com/ApacheWang/inferdiff/actions/workflows/ci.yml)
|
|
4
|
+
[](https://github.com/ApacheWang/inferdiff)
|
|
5
|
+
[](https://github.com/ApacheWang/inferdiff/blob/main/pyproject.toml)
|
|
6
|
+
[](https://github.com/ApacheWang/inferdiff/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
**Wireshark & protocol bill-checker for streaming LLM APIs.**
|
|
9
|
+
|
|
10
|
+
Catch silent `HTTP 200 OK` failures — truncated tool JSON, ghost thinking starvation, buffered nonconformant SSE relays, and illusory benchmark speedups — with **zero third-party runtime dependencies** (Python 3.11+ standard library only).
|
|
11
|
+
|
|
12
|
+
[中文文档 (README.zh-CN.md)](https://github.com/ApacheWang/inferdiff/blob/main/README.zh-CN.md)
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
## Why `inferdiff`? (`HTTP 200 OK` != Your Stream Worked)
|
|
17
|
+
|
|
18
|
+
Standard uptime monitors and latency benchmarks only check HTTP status codes and wall-clock speed. In production, streaming LLM upgrades and third-party OpenAI-compatible relays routinely return `200 OK` while silently corrupting wire contracts:
|
|
19
|
+
|
|
20
|
+
| Who Gets Burned | What Breaks Silently Under `HTTP 200 OK` | Real-World Bug Anchors | How `inferdiff` Catches It |
|
|
21
|
+
| :--- | :--- | :--- | :--- |
|
|
22
|
+
| **Agent & App Engineers** | Tool-call JSON arguments are cut off mid-string by token budgets yet reported as `completed` / `stop`, reasoning tokens starve `content` to empty, or chunk splits emit `U+FFFD` replacement chars — sending agents into retry loops. | [`llama.cpp #30773`](https://github.com/ggml-org/llama.cpp/issues/30773), [`Ollama #17274`](https://github.com/ollama/ollama/issues/17274), [`vLLM #68324`](https://github.com/vllm-project/vllm/issues/68324) | Rules `D1`, `D2` & Canary `C1`, `C2`, `C6` validate strict JSON syntax trees, UTF-8 multibyte boundaries, and terminal state honesty. |
|
|
23
|
+
| **API Relay & Gateway Users** | Proxies buffer upstream non-streaming responses and dump them as a fake SSE burst, strip trailing `include_usage` chunks, undercount tool-schema tokens, strip initial `delta.role`, or route across mixed-quantization pools. | [`LiteLLM #5803`](https://github.com/BerriAI/litellm/issues/5803), [`LiteLLM #16112`](https://github.com/BerriAI/litellm/issues/16112), [`LiteLLM #24221`](https://github.com/BerriAI/litellm/issues/24221), [vLLM Streaming Usage](https://docs.vllm.ai/en/latest/serving/online_serving/derenderer/) | `inferdiff doctor --profile relay` runs low-budget canary probes (`C1–C8`) and grades wire health from `A+` to `F`. |
|
|
24
|
+
| **AI Infra & Perf Engineers** | Engine upgrades report massive throughput/TTFT jumps because fixed-length `ignore_eos` runs stopped at `8 / 8000` tokens, prefix caches leaked across runs, or empty handshake frames gamed first-frame timers. | [`SGLang #53119`](https://github.com/sgl-project/sglang/pull/53119), [`SGLang #50443`](https://github.com/sgl-project/sglang/issues/50443), [vLLM Benchmarking CLI](https://docs.vllm.ai/en/stable/benchmarking/cli/) | Separates empty handshake `ttff_ms` from real `ttft_effective_ms` and flags short-generation & cache-pollution illusions (`D3`, `D5`). |
|
|
25
|
+
| **OSS Contributors & Release CI** | SSE chunk boundaries shift between runs, making raw `curl` logs impossible to diff by eye — while noisy log dumps get closed upstream. | [rusefi LLM Policy](https://github.com/rusefi/rusefi/wiki/LLM-policy) | Normalizes chunk jitter, pins the **exact first divergent wire frame**, and exports an airgapped `<80 KiB` HTML waterfall or a `<=25`-line redacted `curl` reproducer. |
|
|
26
|
+
|
|
27
|
+
## Quickstart
|
|
28
|
+
|
|
29
|
+
Zero-install via [`uvx`](https://docs.astral.sh/uv/guides/tools/) directly from GitHub, or install locally with `pip` (Python 3.11+, zero runtime dependencies):
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# 1. Zero-install live health check on a local engine (llama-server, vLLM, SGLang, Ollama)
|
|
33
|
+
uvx --from git+https://github.com/ApacheWang/inferdiff inferdiff \
|
|
34
|
+
doctor http://127.0.0.1:8080/v1 --html doctor.html
|
|
35
|
+
|
|
36
|
+
# 2. Audit an OpenAI-compatible relay API + generate shareable single-file HTML scorecard
|
|
37
|
+
OPENAI_API_KEY=sk-... uvx --from git+https://github.com/ApacheWang/inferdiff inferdiff \
|
|
38
|
+
doctor https://api.your-relay.example/v1 \
|
|
39
|
+
--model qwen3-32b --profile relay --html relay-report.html
|
|
40
|
+
|
|
41
|
+
# 3. Or install once locally (or clone this repo to try bundled golden examples offline)
|
|
42
|
+
pip install git+https://github.com/ApacheWang/inferdiff
|
|
43
|
+
|
|
44
|
+
# Offline demo on bundled Case 1 (llama.cpp #30773, no GPU or server required)
|
|
45
|
+
inferdiff diff \
|
|
46
|
+
examples/case1_responses_truncated_tool/baseline.trace.jsonl \
|
|
47
|
+
examples/case1_responses_truncated_tool/target.trace.jsonl \
|
|
48
|
+
--html case1-waterfall.html
|
|
49
|
+
|
|
50
|
+
inferdiff export \
|
|
51
|
+
examples/case1_responses_truncated_tool/baseline.trace.jsonl \
|
|
52
|
+
examples/case1_responses_truncated_tool/target.trace.jsonl \
|
|
53
|
+
--format github-issue
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
> **Auth note**: If neither `--api-key` nor `-H "Authorization: ..."` is passed, `inferdiff doctor` falls back to `OPENAI_API_KEY` from the environment and sends it to the target URL (use `https://` for production keys). Reflected secrets are scrubbed from terminal output, saved traces, JSON, and HTML exports.
|
|
57
|
+
|
|
58
|
+
## Single-File Offline HTML Frame Waterfall
|
|
59
|
+
|
|
60
|
+
Every `diff --html`, `audit --html`, `doctor --html`, and `export --format html` command produces a self-contained, airgap-safe HTML5 + inline SVG report strictly under `80 KiB` with zero external CDN requests:
|
|
61
|
+
|
|
62
|
+

|
|
63
|
+
|
|
64
|
+
> GitHub Markdown strips interactive SVG scripts; download [`case1-waterfall.html` from the `v0.1.0` Release](https://github.com/ApacheWang/inferdiff/releases/tag/v0.1.0) to hover frame timings, toggle Absolute ms / Normalized %, and click any lane segment offline.
|
|
65
|
+
|
|
66
|
+
## Canary Probe Matrix (`inferdiff doctor`)
|
|
67
|
+
|
|
68
|
+
| Probe | Target Failure Mode | Profiles | Upstream Anchor |
|
|
69
|
+
| :--- | :--- | :--- | :--- |
|
|
70
|
+
| `C1` (P0) | Truncated tool-call JSON claiming `stop`/`completed` (plus `/v1/responses` cross-check in `full`) | `quick`, `full`, `relay` | [`llama.cpp #30773`](https://github.com/ggml-org/llama.cpp/issues/30773) |
|
|
71
|
+
| `C2` (P0) | Reasoning swallows budget -> empty visible output claiming `stop` | `full`, `relay` | [`Ollama #17274`](https://github.com/ollama/ollama/issues/17274) |
|
|
72
|
+
| `C3` (P1) | `ignore_eos=true` fixed-length budget mismatch (auto-`SKIP` on HTTP 400/422) | `full` | [`SGLang #53119`](https://github.com/sgl-project/sglang/pull/53119) |
|
|
73
|
+
| `C4` (P1) | Stripped trailing empty-`choices` `include_usage` chunk or omitted tool-schema tokens | `quick`, `full`, `relay` | [`LiteLLM #16112`](https://github.com/BerriAI/litellm/issues/16112), [`#28553`](https://github.com/BerriAI/litellm/issues/28553) |
|
|
74
|
+
| `C5` (P1/P0) | Missing initial `delta.role`, omitted/invalid raw indices, or parallel tool index collision | `quick`, `full`, `relay` | [`LiteLLM #24221`](https://github.com/BerriAI/litellm/issues/24221) |
|
|
75
|
+
| `C6` (P0) | Multi-byte UTF-8 / 4-byte emoji `U+FFFD` corruption or swallowed stream tail | `quick`, `full`, `relay` | [`vLLM #68324`](https://github.com/vllm-project/vllm/issues/68324), [`#47161`](https://github.com/vllm-project/vllm/issues/47161) |
|
|
76
|
+
| `C7` (P1) | Buffered non-streaming response dumped as a fake SSE burst | `quick`, `full`, `relay` | [`LiteLLM #5803`](https://github.com/BerriAI/litellm/issues/5803) |
|
|
77
|
+
| `C8` (P2) | Randomized-prefix same-seed heterogeneous backend pool drift (advisory) | `full`, `relay` | [vLLM Benchmarking CLI](https://docs.vllm.ai/en/stable/benchmarking/cli/) |
|
|
78
|
+
|
|
79
|
+
## Recording, Side-by-Side Comparison & Bundled Examples
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Record one request or a multi-line .jsonl suite (strict RFC 9112 framing + per-frame flush)
|
|
83
|
+
inferdiff record --url http://127.0.0.1:8080/v1/responses -d request.json -o target.trace.jsonl
|
|
84
|
+
|
|
85
|
+
# Compare two live endpoints sequentially with per-target scoped credentials
|
|
86
|
+
inferdiff compare \
|
|
87
|
+
--before-url http://127.0.0.1:8080/v1/chat/completions \
|
|
88
|
+
--after-url http://127.0.0.1:8081/v1/chat/completions \
|
|
89
|
+
--before-header "Authorization: Bearer $KEY_A" \
|
|
90
|
+
--after-header "Authorization: Bearer $KEY_B" \
|
|
91
|
+
-d request.json --save-dir ./traces --html compare.html --fail-on p1
|
|
92
|
+
|
|
93
|
+
# Additional bundled golden examples
|
|
94
|
+
inferdiff diff examples/case2_ollama_ghost_thinking_tokens/baseline.trace.jsonl \
|
|
95
|
+
examples/case2_ollama_ghost_thinking_tokens/target.trace.jsonl
|
|
96
|
+
inferdiff diff examples/case3_sglang_8_of_8000_short_gen/baseline.trace.jsonl \
|
|
97
|
+
examples/case3_sglang_8_of_8000_short_gen/target.trace.jsonl --fail-on p1
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Wire Health Grades & Deterministic CI Exit Codes
|
|
101
|
+
|
|
102
|
+
- **Doctor grades**: `A+` (all executed probes pass with zero skips/warnings), `A` (zero P0/P1 issues, advisory P2 warning or inconclusive/skipped probe), `B` (1 P1 warning), `C` (2+ P1 warnings), `F` (any P0 silent protocol breach or transport/HTTP error).
|
|
103
|
+
|
|
104
|
+
| Exit Code | Constant | Meaning |
|
|
105
|
+
| :--- | :--- | :--- |
|
|
106
|
+
| `0` | `EXIT_OK` | Gate passed (`doctor` grades `A+` / `A` / `B` / `C` without `--strict`) |
|
|
107
|
+
| `1` | `EXIT_USAGE_OR_IO_ERROR` | CLI usage error, malformed trace schema, unreachable endpoint, or non-200 HTTP failure |
|
|
108
|
+
| `2` | `EXIT_SILENT_PROTOCOL_BREACH` | Confirmed P0 silent protocol breach (`D1`, `D2`, `D4`, or `doctor` P0 `FAIL`) |
|
|
109
|
+
| `3` | `EXIT_SEMANTIC_REGRESSION` | P1 regression (`D3`, `D5`, terminal drift, TTFT regression, `--fail-on any-diff`, or `doctor --strict` P1 warn) |
|
|
110
|
+
|
|
111
|
+
## Airgap-Safe HTML Waterfall & Privacy Defaults
|
|
112
|
+
|
|
113
|
+
- Single-file HTML5 + inline SVG reports use a hash-locked CSP (`default-src 'none'; style-src 'unsafe-inline'; script-src 'sha256-...'; img-src data:;`) with zero external scripts, fonts, or stylesheets, and adaptive folding to stay strictly under `80 KiB`.
|
|
114
|
+
- Shareable exports (`export --format github-issue|json|html`, `diff --html`, `audit --html`, `doctor --html`) omit arbitrary request bodies and raw wire payloads by default; pass `--include-body` or `--include-wire` to `export` only after reviewing your trace.
|
|
115
|
+
|
|
116
|
+
## Positioning: How `inferdiff` Complements Existing Tools
|
|
117
|
+
|
|
118
|
+
`inferdiff` is intentionally scoped as a **wire-level surgical knife** (`git diff` + protocol bill-checker for streaming frames), not an all-in-one evaluation or load-testing platform. Use it alongside — not instead of — established ecosystem tools:
|
|
119
|
+
|
|
120
|
+
| Tool Category | Great Open-Source Options | Use Them When You Need To... | Use `inferdiff` When You Need To... |
|
|
121
|
+
| :--- | :--- | :--- | :--- |
|
|
122
|
+
| **Semantic & Agent Evals** | [promptfoo](https://github.com/promptfoo/promptfoo) | Grade prompt accuracy, RAG faithfulness, or red-team safety across models after responses are assembled. | Catch **wire-level silent corruption** under `HTTP 200 OK` (truncated tool JSON, missing `arguments.done`, `U+FFFD` chunk-split leaks) before SDKs even finish assembling text. |
|
|
123
|
+
| **Load & Throughput Benchmarks** | [GuideLLM](https://github.com/vllm-project/guidellm), [LLMPerf](https://github.com/ray-project/llmperf) | Measure multi-concurrency QPS, latency percentiles, and capacity curves under sustained load. | Verify your benchmark isn't **measuring an illusion** (e.g., `8 / 8000` short generation on `ignore_eos`, empty handshake frames gaming TTFT, or unisolated prefix caches). |
|
|
124
|
+
| **Broad Engine & Relay Suites** | [ddalcu/llmprobe](https://github.com/ddalcu/llmprobe), [lmspeed-audit](https://github.com/nexmoe/lmspeed-audit) | Run comprehensive Node.js capability scorecards (GPQA/AIME evals, surface coverage, or provider fingerprinting) using built-in test banks. | Run a **zero-dep Python CLI** inside GPU containers to **record & frame-diff your own failing production payloads** across `openai-chat`, `openai-responses`, `sglang-native`, and `ollama-ndjson`, and export a `<=25`-line upstream GitHub Issue. |
|
|
125
|
+
| **Interactive Local Proxies** | [StreamLens](https://github.com/alexandrmotologa/streamlens), [ForkMind](https://github.com/Medhovarsh/forkmind) | Route local app traffic through a persistent reverse proxy and inspect conversations interactively in a Web UI. | Run **stateless CLI / CI regression gates** (`Exit 0/1/2/3`) and generate `<80 KiB` airgap-safe single-file HTML frame waterfalls without deploying a proxy. |
|
|
126
|
+
|
|
127
|
+
### Explicit Non-Goals
|
|
128
|
+
|
|
129
|
+
- **No LLM-as-a-Judge or capability leaderboards**: `inferdiff` never grades prose quality, math/coding intelligence, or jailbreak resistance. Every verdict is a deterministic function of raw wire bytes, JSON syntax trees, and monotonic frame timestamps.
|
|
130
|
+
- **No heavy runtime stack**: Core CLI and HTML/SVG waterfall rendering stay 100% Python 3.11+ standard library (`0` mandatory `pip` packages, `0` Node.js runtime, `0` external CDN requests).
|
|
131
|
+
|
|
132
|
+
## Roadmap (v0.2: Non-Intrusive KV & Storage Probes)
|
|
133
|
+
|
|
134
|
+
`inferdiff.trace.v1` and `inferdiff.probes.base.BackendProbe` already expose the three-point snapshot lifecycle (`T_pre -> T_ttft -> T_eof`) for optional v0.2 plugins (`LmcacheMpProbe`, `MooncakeStoreProbe`, `LinuxProcIoProbe`) and storage x inference rules `D6`–`D8`.
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
MIT
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "inferdiff"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Wireshark for streaming LLMs: catch HTTP 200 silent truncations, broken tool JSON, fake SSE relays & usage drops."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.11"
|
|
12
|
+
dependencies = []
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "ApacheWang" },
|
|
15
|
+
]
|
|
16
|
+
keywords = ["llm", "inference", "sse", "streaming", "vllm", "llama-cpp", "sglang", "ollama", "litellm", "testing"]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 4 - Beta",
|
|
19
|
+
"Environment :: Console",
|
|
20
|
+
"Intended Audience :: Developers",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Topic :: Software Development :: Testing",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.optional-dependencies]
|
|
29
|
+
httpx = ["httpx>=0.27"]
|
|
30
|
+
dev = ["pytest>=8.0"]
|
|
31
|
+
|
|
32
|
+
[project.scripts]
|
|
33
|
+
inferdiff = "inferdiff.cli:main"
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/ApacheWang/inferdiff"
|
|
37
|
+
Repository = "https://github.com/ApacheWang/inferdiff"
|
|
38
|
+
Issues = "https://github.com/ApacheWang/inferdiff/issues"
|
|
39
|
+
|
|
40
|
+
[tool.setuptools]
|
|
41
|
+
package-dir = { "" = "src" }
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.packages.find]
|
|
44
|
+
where = ["src"]
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""inferdiff: Wire-level canary doctor, regression diff, silent-failure forensics, and HTML waterfall."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__version__ = "0.1.0"
|
|
6
|
+
|
|
7
|
+
from .canary import DoctorReport, ProbeResult, run_doctor
|
|
8
|
+
from .detectors import Finding, audit_trace, detect_d1, detect_d2, detect_d3, detect_d4, detect_d5
|
|
9
|
+
from .differ import DiffReport, DivergencePoint, diff_traces
|
|
10
|
+
from .exporter import render_audit_terminal, render_ci_summary, render_diff_terminal, render_github_issue
|
|
11
|
+
from .recorder import RecorderError, record_stream
|
|
12
|
+
from .schema import (
|
|
13
|
+
EXIT_OK,
|
|
14
|
+
EXIT_SEMANTIC_REGRESSION,
|
|
15
|
+
EXIT_SILENT_PROTOCOL_BREACH,
|
|
16
|
+
EXIT_USAGE_OR_IO_ERROR,
|
|
17
|
+
SCHEMA_VERSION,
|
|
18
|
+
TraceDocument,
|
|
19
|
+
TraceFrame,
|
|
20
|
+
TraceHeader,
|
|
21
|
+
TraceSchemaError,
|
|
22
|
+
TraceSummary,
|
|
23
|
+
load_trace,
|
|
24
|
+
write_trace,
|
|
25
|
+
)
|
|
26
|
+
from .waterfall import render_audit_html, render_diff_html, render_doctor_html
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"__version__",
|
|
30
|
+
"SCHEMA_VERSION",
|
|
31
|
+
"EXIT_OK",
|
|
32
|
+
"EXIT_USAGE_OR_IO_ERROR",
|
|
33
|
+
"EXIT_SILENT_PROTOCOL_BREACH",
|
|
34
|
+
"EXIT_SEMANTIC_REGRESSION",
|
|
35
|
+
"DoctorReport",
|
|
36
|
+
"ProbeResult",
|
|
37
|
+
"run_doctor",
|
|
38
|
+
"Finding",
|
|
39
|
+
"DiffReport",
|
|
40
|
+
"DivergencePoint",
|
|
41
|
+
"TraceDocument",
|
|
42
|
+
"TraceFrame",
|
|
43
|
+
"TraceHeader",
|
|
44
|
+
"TraceSummary",
|
|
45
|
+
"TraceSchemaError",
|
|
46
|
+
"RecorderError",
|
|
47
|
+
"record_stream",
|
|
48
|
+
"load_trace",
|
|
49
|
+
"write_trace",
|
|
50
|
+
"audit_trace",
|
|
51
|
+
"diff_traces",
|
|
52
|
+
"detect_d1",
|
|
53
|
+
"detect_d2",
|
|
54
|
+
"detect_d3",
|
|
55
|
+
"detect_d4",
|
|
56
|
+
"detect_d5",
|
|
57
|
+
"render_audit_terminal",
|
|
58
|
+
"render_diff_terminal",
|
|
59
|
+
"render_github_issue",
|
|
60
|
+
"render_ci_summary",
|
|
61
|
+
"render_audit_html",
|
|
62
|
+
"render_diff_html",
|
|
63
|
+
"render_doctor_html",
|
|
64
|
+
]
|