ortops.optim#

optimize#

onnx_extended.ortops.optim.optimize.change_onnx_operator_domain(onx: ModelProto | GraphProto | FunctionProto, op_type: str, op_domain: str = '', new_op_type: str | None = None, new_op_domain: str | None = None, new_opset: int | None = None, **kwargs: Dict[str, Any]) ModelProto | GraphProto | FunctionProto[source]#

Replaces an operator by another one in the same domain or another one.

Parameters:
  • onx – proto to modify

  • op_type – operator to look for

  • op_domain – domain to look for

  • new_op_type – new operator name or None for the same name

  • new_op_domain – new domain name or None the for the same domain

  • new_opset – new opset for the new domain, if not specified, it is 1 for any opset other than “”

  • kwargs – modified parameters, set it to None to remove them

Returns:

same type as the input

The function is not recursive yet.

onnx_extended.ortops.optim.optimize.optimize_model(onx: ModelProto, feeds: Dict[str, ndarray], transform: Callable[[ModelProto], ModelProto], session: Callable[[ModelProto], Any], params: Dict[str, List[Any]], baseline: Callable[[ModelProto], Any] | None = None, verbose: bool = False, number: int = 10, repeat: int = 10, warmup: int = 5, n_tries: int = 2, sleep: float = 0.1) List[Dict[str, str | float]][source]#

Optimizes a model by trying out many possibilities.

Parameters:
  • onx – ModelProto

  • feeds – inputs as a dictionary of numpy arrays

  • transform – function taking a ModelProto and returning a ModelProto based on the values coming from params

  • session – function which takes a modifed ModelProto and return a session

  • params – dictionary of values to test { param_name: [ param_values ] }

  • baseline – function which takes a modifed ModelProto and return a session, identified as the baseline

  • verbose – use tqdm to show improvment

  • number – parameter to measure_time

  • repeat – parameter to measure_time

  • warmup – parameter to measure_time

  • n_tries – number of times to measure, if the measurements returns very different results, values for number or repeat should be increased

  • sleep – time to sleep between two measurements

Returns:

list of results returned by measure_time

See example TreeEnsemble optimization for an example.

CPU: onnx_extented.ortops.optim.cpu#

onnx_extended.ortops.optim.cpu.get_ort_ext_libs() List[str][source]#

Returns the list of libraries implementing new simple onnxruntime kernels implemented for the CPUExecutionProvider.

List of implemented kernels

<<<

from onnx_extended.ortops.optim.cpu import documentation

print("\n".join(documentation()))

>>>

onnx_extented.ortops.option.cpu.TreeEnsembleClassifier#

It does the sum of two tensors.

Provider

CPUExecutionProvider

Inputs

  • X (T1): tensor of type T1

Outputs

  • label (T3): labels of type T3

  • Y (T2): probabilities of type T2

Constraints

  • T1: float, double

  • T2: float, double

  • T3: int64

Attributes

onnx_extented.ortops.option.cpu.TreeEnsembleRegressor#

It does the sum of two tensors.

Provider

CPUExecutionProvider

Inputs

  • X (T1): tensor of type T1

Outputs

  • Y (T2): prediction of type T2

Constraints

  • T1: float, double

  • T2: float, double

Attributes