quark.onnx.finetuning.create_torch.create_model_ops#

Module Contents#

Functions#

quark.onnx.finetuning.create_torch.create_model_ops.param_is_symmetric(params: List[Any]) bool#

Check if parameters are symmetric, all values [2,2,2,2]. Then we can use only [2,2].

quark.onnx.finetuning.create_torch.create_model_ops.extract_padding_params(params: List[Any]) Any#

Extract padding parameters for Pad layers.

quark.onnx.finetuning.create_torch.create_model_ops.extract_padding_params_for_conv(params: List[Any]) Any#

Padding params in onnx are different than in pytorch. That is why we need to check if they are symmetric and cut half or return a padding layer.

quark.onnx.finetuning.create_torch.create_model_ops.extract_weight_and_bias(params: List[Any]) Tuple[numpy.typing.NDArray[Any], Union[numpy.typing.NDArray[Any], None]]#

Extract weights and biases.

quark.onnx.finetuning.create_torch.create_model_ops.load_weight_and_bias(layer: torch.nn.Module, weight: numpy.typing.NDArray[Any], bias: Union[numpy.typing.NDArray[Any], None]) None#

Load weight and bias to a given layer from onnx format.

quark.onnx.finetuning.create_torch.create_model_ops.convert_conv(node: onnx.NodeProto, layer_params: List[Any], layer_qinfos: List[Any]) Tuple[quark.onnx.finetuning.create_torch.quant_base_ops.QuantizeWrapper, Union[quark.onnx.finetuning.create_torch.quant_base_ops.QuantizeWrapper, None]]#

Use to convert Conv ONNX node to Torch module (or called layer). This function supports onnx’s Conv and ConvTranspose from 1 to 11.

:param node : ONNX node. :param layer_params : Layer weight and bias parameters. :param layer_qinfos : Layer quantization informations. :return: Converted conv layer, perhaps it has a pad layer.

quark.onnx.finetuning.create_torch.create_model_ops.convert_gemm(node: onnx.NodeProto, layer_params: List[Any], layer_qinfos: List[Any]) Tuple[quark.onnx.finetuning.create_torch.quant_gemm_ops.QGemm, None]#

Use to convert Gemm ONNX node to Torch module. This function supports onnx’s Instance Norm from 6.

:param node : ONNX node. :param layer_params : Layer weight and bias parameters. :param layer_qinfos : Layer quantization informations. :return: Converted Gemm layer.

quark.onnx.finetuning.create_torch.create_model_ops.convert_norm(node: onnx.NodeProto, layer_params: List[Any], layer_qinfos: List[Any]) Tuple[quark.onnx.finetuning.create_torch.quant_norm_ops.QInstanceNorm2d, None]#

Use to convert norm (Instance Norm) ONNX node to Torch module. This function supports onnx’s Instance Norm from 6.

:param node : ONNX node. :param layer_params : Layer weight and bias parameters. :param layer_qinfos : Layer quantization informations. :return: Converted norm (Instance Norm) layer.

quark.onnx.finetuning.create_torch.create_model_ops.convert_act(node: onnx.NodeProto) Union[torch.nn.Module, None]#

Use to convert Activation ONNX node to Torch module (or called layer). :param node : ONNX node. :return: Converted act layer.

quark.onnx.finetuning.create_torch.create_model_ops.convert_ops_to_modules(onnx_model: onnx.ModelProto) Tuple[Optional[torch.nn.Module], Optional[torch.nn.Module], Optional[torch.nn.Module], Optional[quark.onnx.finetuning.create_torch.quant_base_ops.QuantizationModule]]#

Convert ONNX operations to Torch modules.

quark.onnx.finetuning.create_torch.create_model_ops.set_modules_original_weight(module: torch.nn.Module, weight: numpy.typing.NDArray[Any]) None#

For setting original float weight

quark.onnx.finetuning.create_torch.create_model_ops.get_modules_optimized_weight(module: torch.nn.Module) Any#

For getting optimized quantized weight

quark.onnx.finetuning.create_torch.create_model_ops.set_modules_original_bias(module: torch.nn.Module, bias: numpy.typing.NDArray[Any]) None#

For setting original float bias

quark.onnx.finetuning.create_torch.create_model_ops.get_modules_optimized_bias(module: torch.nn.Module) Any#

For getting optimized quantized bias