Skip to content

Commit 3af33f6

Browse files
2026ww16 security fixes (#281)
* Update download-models deps * Update common py deps * Update compile-models py deps + fix models * Exclude 3rdparty from code ql init * Add onnx script dep * Bump actions/cache from 5.0.1 to 5.0.3 Bumps [actions/cache](https://github.com/actions/cache) from 5.0.1 to 5.0.3. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](actions/cache@9255dc7...cdf6c1f) --- updated-dependencies: - dependency-name: actions/cache dependency-version: 5.0.3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Bump github/codeql-action from 4.31.9 to 4.32.3 Bumps [github/codeql-action](https://github.com/github/codeql-action) from 4.31.9 to 4.32.3. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](github/codeql-action@5d4e8d1...9e907b5) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: 4.32.3 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Bump openvinotoolkit/openvino from 2025.4.1 to 2026.0.1 Bumps [openvinotoolkit/openvino](https://github.com/openvinotoolkit/openvino) from 2025.4.1 to 2026.0.1. - [Release notes](https://github.com/openvinotoolkit/openvino/releases) - [Changelog](https://github.com/openvinotoolkit/openvino/blob/master/docs/RELEASE.MD) - [Commits](openvinotoolkit/openvino@82bbf02...9185925) --- updated-dependencies: - dependency-name: openvinotoolkit/openvino dependency-version: 2026.0.1 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * Revert patchelf * Revert build docs --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 01a807a commit 3af33f6

25 files changed

Lines changed: 1694 additions & 416 deletions

.github/actions/compile-models/convert_pytorch_to_onnx.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ def forward(self, input_ids, attention_mask, pixel_values):
4545
)
4646

4747

48+
class ResNetWrapper(torch.nn.Module):
49+
"""
50+
ResNetForImageClassification returns an ImageClassifierOutputWithNoAttention dataclass.
51+
In transformers 5.x, ONNX tracing of this dataclass may expose intermediate feature
52+
tensors (e.g. the 2048-dim pooler output) alongside the logits, causing onnxruntime
53+
shape inference to fail during quantization with (2048) vs (1000) mismatch.
54+
This wrapper ensures only the logits tensor is exported.
55+
"""
56+
57+
def __init__(self, model):
58+
super().__init__()
59+
self.model = model
60+
61+
def forward(self, pixel_values):
62+
"""Returns logits only"""
63+
return self.model(pixel_values).logits
64+
65+
4866
class PromptEncoderWrapper(torch.nn.Module):
4967
"""
5068
SamPromptEncoder takes extra input_boxes optional input
@@ -72,24 +90,24 @@ class MaskDecoderWrapper(torch.nn.Module):
7290
that shouldn't be counted in onnx model inputs.
7391
"""
7492

75-
def __init__(self, decoder):
93+
def __init__(self, decoder, multimask_output: bool):
7694
super().__init__()
7795
self.decoder = decoder
96+
self.multimask_output = multimask_output
7897

7998
def forward(
8099
self,
81100
image_embeddings,
82101
sparse_prompt_embeddings,
83102
dense_prompt_embeddings,
84-
multimask_output,
85103
):
86104
"""Adds extra image_positional_embeddings input"""
87105
low_res_masks, iou_predictions = self.decoder(
88106
image_embeddings=image_embeddings,
89107
image_positional_embeddings=torch.randn_like(image_embeddings),
90108
sparse_prompt_embeddings=sparse_prompt_embeddings,
91109
dense_prompt_embeddings=dense_prompt_embeddings,
92-
multimask_output=multimask_output,
110+
multimask_output=self.multimask_output,
93111
)
94112
return low_res_masks, iou_predictions
95113

@@ -100,6 +118,7 @@ def convert_pytorch_to_onnx(model: dict, torch_model_path: str):
100118
onnx_model_path = pytorch_model_dir / f"{model.get('name')}.onnx"
101119
model_type = model.get("model_type", "")
102120
convert_config = model.get("Convert", {})
121+
export_kwargs = {}
103122

104123
input_names = convert_config.get("input_names", [])
105124
output_names = convert_config.get("output_names", [])
@@ -108,6 +127,10 @@ def convert_pytorch_to_onnx(model: dict, torch_model_path: str):
108127
for name, shape in convert_config.get("dynamic_axes", {}).items():
109128
dynamic_axes[name] = {int(axis): type for axis, type in shape.items()}
110129

130+
if model_type == "sam_mask_decoder":
131+
input_names = [name for name in input_names if name != "multimask_output"]
132+
dynamic_axes.pop("multimask_output", None)
133+
111134
if model_type == "transformer":
112135
tokenizer = AutoTokenizer.from_pretrained(pytorch_model_dir, use_fast=True)
113136
pytorch_model = AutoModel.from_pretrained(pytorch_model_dir)
@@ -145,6 +168,7 @@ def convert_pytorch_to_onnx(model: dict, torch_model_path: str):
145168
sam_pytorch_model = SamModel.from_pretrained(pytorch_model_dir)
146169
processor = SamProcessor.from_pretrained(pytorch_model_dir)
147170
pytorch_model = sam_pytorch_model.vision_encoder.eval()
171+
export_kwargs["dynamo"] = False
148172

149173
image = Image.open(
150174
requests.get(
@@ -171,23 +195,24 @@ def convert_pytorch_to_onnx(model: dict, torch_model_path: str):
171195
}
172196
elif model_type == "sam_mask_decoder":
173197
sam_pytorch_model = SamModel.from_pretrained(pytorch_model_dir)
174-
pytorch_model = MaskDecoderWrapper(sam_pytorch_model.mask_decoder.eval())
198+
multimask_output = bool(convert_config.get("multimask_output", False))
199+
pytorch_model = MaskDecoderWrapper(
200+
sam_pytorch_model.mask_decoder.eval(),
201+
multimask_output,
202+
)
175203

176204
image_embeddings = torch.rand(convert_config.get("image_embeddings_shape", []))
177205
sparse_embeddings = torch.rand(
178206
convert_config.get("sparse_embeddings_shape", [])
179207
)
180208
dense_embeddings = torch.rand(convert_config.get("dense_embeddings_shape", []))
181-
multimask_output = torch.tensor([0], dtype=torch.bool)
182209
inputs = {
183210
"image_embeddings": image_embeddings,
184211
"sparse_embeddings": sparse_embeddings,
185212
"dense_embeddings": dense_embeddings,
186-
"multimask_output": multimask_output,
187213
}
188214
elif model_type == "resnet":
189-
pytorch_model = ResNetForImageClassification.from_pretrained(pytorch_model_dir)
190-
pytorch_model.eval()
215+
pytorch_model = ResNetWrapper(ResNetForImageClassification.from_pretrained(pytorch_model_dir)).eval()
191216
processor = AutoImageProcessor.from_pretrained(pytorch_model_dir, use_fast=True)
192217

193218
image = Image.open(
@@ -205,6 +230,7 @@ def convert_pytorch_to_onnx(model: dict, torch_model_path: str):
205230
output_names=output_names,
206231
dynamic_axes=dynamic_axes,
207232
opset_version=18,
233+
**export_kwargs,
208234
)
209235

210236
return onnx_model_path

.github/actions/compile-models/quantize_onnx.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@
22
Dynamically quantizes an ONNX model
33
"""
44

5+
import onnx
56
from pathlib import Path
67
from onnxruntime.quantization import quantize_dynamic, QuantType
78

89

910
def quantize_onnx_model(model: dict, input_model_path: Path):
1011
"""Dynamically quantizes an ONNX model"""
1112
output_model_path = input_model_path.parent / f"{model.get('name')}_quantized.onnx"
13+
14+
# Strip intermediate value_info that may contain stale shape annotations from
15+
# torch.onnx.export. onnxruntime's quantizer uses onnx.shape_inference.infer_shapes_path
16+
# in strict mode, which raises InferenceError when existing annotations conflict with
17+
# inferred shapes. Removing them lets onnxruntime infer all shapes from scratch.
18+
onnx_model = onnx.load(str(input_model_path))
19+
del onnx_model.graph.value_info[:]
20+
onnx.save(onnx_model, str(input_model_path))
21+
1222
quantize_dynamic(
1323
model_input=str(input_model_path),
1424
model_output=str(output_model_path),

.github/actions/compile-models/requirements.in

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
--extra-index-url https://download.pytorch.org/whl/cpu
22

33
# Core
4-
transformers==4.57.3
5-
torch==2.8.0+cpu
6-
torchvision==0.23.0+cpu
7-
protobuf==6.33.5
8-
onnx==1.20.0
9-
onnxruntime==1.23.2
4+
transformers==5.5.4
5+
torch==2.11.0+cpu
6+
torchvision==0.26.0+cpu
7+
protobuf==7.34.1
8+
onnx==1.21.0
9+
onnxruntime==1.24.4
1010
onnxruntime-tools>=1.7.0
11+
onnxscript==0.6.2
1112

1213
# Hugging Face Hub
13-
huggingface_hub==0.36.2
14-
hf-xet==1.4.2
14+
huggingface_hub==1.10.2
15+
hf-xet==1.4.3
1516

1617
# Utils
17-
pillow>=12.1.1
18-
requests>=2.32.5
18+
pillow>=12.2.0
19+
requests>=2.33.1
1920
tqdm>=4.67.3
2021
accelerate>=1.13.0
2122
urllib3>=2.6.3

0 commit comments

Comments
 (0)