[ML] Revert: Harden pytorch_inference with TorchScript model graph validation#3006
Merged
edsavage merged 1 commit intoelastic:mainfrom Mar 20, 2026
Merged
Conversation
…lidation (elastic#2999)" This reverts commit d3df09c.
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
edsavage
added a commit
to edsavage/ml-cpp
that referenced
this pull request
Mar 22, 2026
…alidation (elastic#2999)" (elastic#3006) This reverts commit ceabc9b.
edsavage
added a commit
that referenced
this pull request
Mar 24, 2026
…alidation (#3008) Reapply "[ML] Harden pytorch_inference with TorchScript model graph validation (#2999)" (#3006) This reverts commit ceabc9b. - Adds a static TorchScript graph validation layer (CModelGraphValidator, CSupportedOperations) that rejects models containing operations not observed in supported transformer architectures, reducing the attack surface by ensuring only known-safe operation sets are permitted. - Includes aten::mul_ and quantized::linear_dynamic in the allowed operations for dynamically quantized models (e.g. ELSER v2 imported via Eland). - Adds Python extraction tooling (dev-tools/extract_model_ops/) to trace reference HuggingFace models and collect their op sets, with support for quantized variants. - Adds reference_model_ops.json golden file and C++ drift test to detect allowlist staleness on PyTorch upgrades. - Adds adversarial "evil model" integration tests to verify rejection of forbidden operations. - Adds CHANGELOG entry. - Add aten::norm to graph validator allowlist The prepacked .multilingual-e5-small model uses aten::norm for normalization, which was not in the allowlist. This caused the model to be rejected with "Unrecognised operations: aten::norm". - Add multilingual-e5-small model ops to reference files Extracted ops from intfloat/multilingual-e5-small (base and Eland text_embedding variant) and added both to the reference golden file. The base model uses standard XLM-RoBERTa ops. The Eland variant adds pooling/normalization ops (linalg_vector_norm, clamp, etc.). The prepacked .multilingual-e5-small model bundled with Elasticsearch uses aten::norm (added to the allowlist in the previous commit). - Add graph validator test for prepacked e5 model with aten::norm The prepacked .multilingual-e5-small model uses aten::norm, which was missing from the allowlist and caused production failures. This test loads a tiny (24KB) model that mirrors the real prepacked model's graph structure (including aten::norm) and verifies graph validation passes. The test model was created by tracing a minimal XLM-RoBERTa-like architecture with normalization, then patching the TorchScript IR to use aten::norm (which modern PyTorch decomposes into aten::linalg_vector_norm, so it can't be generated via tracing). Made-with: Cursor
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.
Summary
Made with Cursor