perf(inference): add latency benchmarking, edge caps, and INT8 quantization - #3677
Merged
Puneet04-tech merged 1 commit intoAug 18, 2026
Conversation
🌟 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:
Thank you once again for your valuable contribution to Puneet04-tech/AegisGraph-Sentinel-2.0! Let's build something amazing together. Happy coding! 🚀 |
🎉 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! 🚀✨ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
src/inference/optimization.pybenchmark_latency→LatencyReport(p50/p95/p99/mean/min/max,meets_budget()); warm-up runs discarded; injectable timer so tests are deterministicpercentile— 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 mutatedquantize_model_dynamic— INT8 dynamic quantization of Linear layers, degrading to the original model on failureProductionRiskScorer— opt-inmax_subgraph_edges(applied before tensor work) andquantize; both off by defaultMeasured results
Edge cap, driven through the real scorer with a 20k-edge hub account:
~45% off p99.
INT8 quantization, 3-layer MLP (p99) — included because the result is not the expected one:
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
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_indexwithin node range, no mutation, under-budget andNonepassthrough)test_production_scorer.py,test_mc_dropout_uncertainty.py,test_performance.py— 76 tests total passing; flake8 critical check clean