Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"export": {
"opset_version": 17,
"batch_size": 1,
"export_params": true,
"do_constant_folding": true,
"verbose": false,
"dynamo": false,
"enable_hierarchy_tags": true,
"clean_onnx": false,
"hierarchy_tag_format": "full",
"input_tensors": [
{
"name": "input_ids",
"dtype": "int32",
"shape": [
1,
512
],
"value_range": [
0,
250037
]
},
{
"name": "attention_mask",
"dtype": "int32",
"shape": [
1,
512
],
"value_range": [
0,
2
]
},
{
"name": "token_type_ids",
"dtype": "int32",
"shape": [
1,
512
],
"value_range": [
0,
2
]
}
],
"output_tensors": [
{
"name": "last_hidden_state"
}
],
"compatibility": {
"transformers_attention": "eager"
}
},
"optim": {
"clamp_constant_values": true
},
"quant": {
"mode": "fp16",
"samples": 10,
"calibration_method": "minmax",
"weight_type": "uint8",
"activation_type": "uint8",
"per_channel": false,
"symmetric": false,
"weight_symmetric": null,
"activation_symmetric": null,
"save_calibration": false,
"distribution": "uniform",
"seed": null,
"calibration_load_path": null,
"calibration_save_path": null,
"op_types_to_quantize": null,
"nodes_to_exclude": null,
"task": "feature-extraction",
"model_id": "intfloat/multilingual-e5-small",
"model_type": "bert",
"fp16_keep_io_types": true,
"fp16_op_block_list": null
},
"compile": null,
"loader": {
"task": "feature-extraction",
"model_class": "AutoModel",
"model_type": "bert"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"export": {
"opset_version": 17,
"batch_size": 1,
"export_params": true,
"do_constant_folding": true,
"verbose": false,
"dynamo": false,
"enable_hierarchy_tags": true,
"clean_onnx": false,
"hierarchy_tag_format": "full",
"input_tensors": [
{
"name": "input_ids",
"dtype": "int32",
"shape": [
1,
512
],
"value_range": [
0,
250037
]
},
{
"name": "attention_mask",
"dtype": "int32",
"shape": [
1,
512
],
"value_range": [
0,
2
]
},
{
"name": "token_type_ids",
"dtype": "int32",
"shape": [
1,
512
],
"value_range": [
0,
2
]
}
],
"output_tensors": [
{
"name": "last_hidden_state"
}
],
"compatibility": {
"transformers_attention": "eager"
}
},
"optim": {
"clamp_constant_values": true
},
"quant": null,
"compile": null,
"loader": {
"task": "feature-extraction",
"model_class": "AutoModel",
"model_type": "bert"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"export": {
"opset_version": 17,
"batch_size": 1,
"export_params": true,
"do_constant_folding": true,
"verbose": false,
"dynamo": false,
"enable_hierarchy_tags": true,
"clean_onnx": false,
"hierarchy_tag_format": "full",
"input_tensors": [
{
"name": "input_ids",
"dtype": "int32",
"shape": [
1,
512
],
"value_range": [
0,
250037
]
},
{
"name": "attention_mask",
"dtype": "int32",
"shape": [
1,
512
],
"value_range": [
0,
2
]
},
{
"name": "token_type_ids",
"dtype": "int32",
"shape": [
1,
512
],
"value_range": [
0,
2
]
}
],
"output_tensors": [
{
"name": "last_hidden_state"
}
],
"compatibility": {
"transformers_attention": "eager"
}
},
"optim": {
"clamp_constant_values": true
},
"quant": {
"mode": "fp16",
"samples": 10,
"calibration_method": "minmax",
"weight_type": "uint8",
"activation_type": "uint8",
"per_channel": false,
"symmetric": false,
"weight_symmetric": null,
"activation_symmetric": null,
"save_calibration": false,
"distribution": "uniform",
"seed": null,
"calibration_load_path": null,
"calibration_save_path": null,
"op_types_to_quantize": null,
"nodes_to_exclude": null,
"task": "sentence-similarity",
"model_id": "intfloat/multilingual-e5-small",
"model_type": "bert",
"fp16_keep_io_types": true,
"fp16_op_block_list": null
},
"compile": null,
"loader": {
"task": "sentence-similarity",
"model_class": "AutoModel",
"model_type": "bert"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"export": {
"opset_version": 17,
"batch_size": 1,
"export_params": true,
"do_constant_folding": true,
"verbose": false,
"dynamo": false,
"enable_hierarchy_tags": true,
"clean_onnx": false,
"hierarchy_tag_format": "full",
"input_tensors": [
{
"name": "input_ids",
"dtype": "int32",
"shape": [
1,
512
],
"value_range": [
0,
250037
]
},
{
"name": "attention_mask",
"dtype": "int32",
"shape": [
1,
512
],
"value_range": [
0,
2
]
},
{
"name": "token_type_ids",
"dtype": "int32",
"shape": [
1,
512
],
"value_range": [
0,
2
]
}
],
"output_tensors": [
{
"name": "last_hidden_state"
}
],
"compatibility": {
"transformers_attention": "eager"
}
},
"optim": {
"clamp_constant_values": true
},
"quant": null,
"compile": null,
"loader": {
"task": "sentence-similarity",
"model_class": "AutoModel",
"model_type": "bert"
}
}
27 changes: 26 additions & 1 deletion src/winml/modelkit/models/winml/feature_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from collections import OrderedDict
from typing import Any

import numpy as np
from transformers.utils.generic import ModelOutput

from .base import WinMLPreTrainedModel
Expand Down Expand Up @@ -58,7 +59,31 @@ def forward(self, **kwargs: Any) -> ModelOutput:
order. Tensors keep their native rank (no unsqueeze); downstream
pooling handles 1-D and 2-D after raw[0].

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wrapper cannot infer from tensor shape or ONNX metadata that the request contains only one segment. If a caller passes tokenized paired BERT input without token_type_ids, segment-B positions require 1, but this path silently supplies all zeros and returns incorrect embeddings instead of preserving the missing-input error. Could zero synthesis be gated by explicit preprocessing metadata that establishes a single-text request (or a declarative safe-default policy), rather than applied universally whenever the tensor is omitted?

"""
outputs = self._run_inference(self._format_inputs(**kwargs))
inputs = self._format_inputs(**kwargs)
if "token_type_ids" not in inputs and "input_ids" in inputs:
input_names = self.io_config.get("input_names", [])
if "token_type_ids" in input_names:
input_index = input_names.index("token_type_ids")
input_types = self.io_config.get("input_types", [])
input_shapes = self.io_config.get("input_shapes", [])
if input_index < len(input_types) and input_index < len(input_shapes):
required_shape = input_shapes[input_index]
actual_shape = inputs["input_ids"].shape
shape_matches = len(required_shape) == len(actual_shape) and all(
not isinstance(dimension, int)
or dimension <= 0
or dimension == actual_dimension
for dimension, actual_dimension in zip(
required_shape, actual_shape, strict=True
)
)
if shape_matches:
inputs["token_type_ids"] = np.zeros(
actual_shape,
dtype=np.dtype(input_types[input_index]),
)

outputs = self._run_inference(inputs)
# WinMLEncoderDecoderModel expects its encoder sub-component to expose
# hidden states as "last_hidden_state". Alias the primary output when an
# encoder ONNX graph named it otherwise (e.g. "encoder_hidden_states").
Expand Down
Loading
Loading