Skip to content

perf(inference): add latency benchmarking, edge caps, and INT8 quantization - #3677

Merged
Puneet04-tech merged 1 commit into
Puneet04-tech:masterfrom
ayush-kr-repo:perf/inference-latency-optimization
Aug 18, 2026
Merged

perf(inference): add latency benchmarking, edge caps, and INT8 quantization#3677
Puneet04-tech merged 1 commit into
Puneet04-tech:masterfrom
ayush-kr-repo:perf/inference-latency-optimization

Conversation

@ayush-kr-repo

Copy link
Copy Markdown
Contributor

Closes #3676

Summary

The README advertises a <200ms p99 budget (89ms for HTGNN) but nothing measures it, and no optimization is applied to the served model. This PR adds the measurement harness plus two opt-in optimizations, and reports what they actually do.

Changes

  • New src/inference/optimization.py
    • benchmark_latencyLatencyReport (p50/p95/p99/mean/min/max, meets_budget()); warm-up runs discarded; injectable timer so tests are deterministic
    • percentile — nearest-rank in integer arithmetic (floats would report the max as p99, see docstring)
    • cap_subgraph_edges — per-transaction edge budget; node set intact so no re-indexing; input never mutated
    • quantize_model_dynamic — INT8 dynamic quantization of Linear layers, degrading to the original model on failure
  • ProductionRiskScorer — opt-in max_subgraph_edges (applied before tensor work) and quantize; both off by default

Measured results

Edge cap, driven through the real scorer with a 20k-edge hub account:

p50 p99
baseline 0.53ms 0.74ms
capped (500 edges) 0.26ms 0.41ms

~45% off p99.

INT8 quantization, 3-layer MLP (p99) — included because the result is not the expected one:

width fp32 int8 change
64 0.09ms 0.44ms 374% slower
256 1.37ms 0.97ms 29% faster
512 4.17ms 1.54ms 63% faster

Quantization overhead is fixed per call while savings scale with matmul size, so narrow layers regress. Quantized Linear also requires rank ≥ 2 inputs — a model feeding 1-D tensors works in FP32 and raises once quantized. Both are documented in the docstring; quantization is off by default and ships beside the benchmark harness so it can be verified per model.

Note: the actual HTGAT was not benchmarked as no checkpoint is committed to the repo, so this PR provides the harness and the size threshold rather than claiming a speedup for the served model.

Testing

  • 34 new tests in tests/test_inference_optimization.py (RUN_TORCH_TESTS-gated): exact percentiles from a scripted fake clock, nearest-rank correctness (p99 of 1..100 is 99, not 100), warm-up excluded from measurement, budget checks, quantization output-shape/precision/fallback, and edge-cap invariants (aligned tensor truncation, edge_index within node range, no mutation, under-budget and None passthrough)
  • Regression: test_production_scorer.py, test_mc_dropout_uncertainty.py, test_performance.py — 76 tests total passing; flake8 critical check clean

@github-actions

Copy link
Copy Markdown

🌟 Welcome to AegisGraph-Sentinel-2.0!

Thank you for submitting your pull request, @ayush-kr-repo! 🙌 We truly appreciate your time, effort, and dedication to improving our platform.


📌 Next Steps & Guidelines:

  • Review Process: Our Project administrators will review your changes as soon as possible.
  • Feedback: If there are any specific modifications, edge cases, or code improvements needed, we will provide detailed feedback directly in this pull request thread.
  • Continuous Integration: Ensure that all automated pipeline checks and status workflows pass successfully.

Thank you once again for your valuable contribution to Puneet04-tech/AegisGraph-Sentinel-2.0! Let's build something amazing together. Happy coding! 🚀

@github-actions github-actions Bot added the merge ready PR is mergeable and has no conflicts label Aug 16, 2026
@Puneet04-tech
Puneet04-tech merged commit b60e6ff into Puneet04-tech:master Aug 18, 2026
8 of 9 checks passed
@github-actions

Copy link
Copy Markdown

🎉 Contribution Merged!

Thank you so much, @ayush-kr-repo, for your contribution! Your pull request #3677 has been successfully merged.

We truly appreciate your time and effort in making this project better for the community. Keep up the amazing work! 🚀✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Measure and optimize inference latency against the advertised <200ms budget

2 participants