Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes ConvNd usability and shape inference for qonnx export on Torch 2.0.1 #692

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions src/brevitas/export/onnx/qonnx/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import torch
from torch.autograd import Function
from torch.onnx.symbolic_helper import _get_tensor_sizes

from brevitas.core.bit_width import BitWidthConst
from brevitas.core.function_wrapper.clamp import TensorClamp
Expand All @@ -11,6 +12,7 @@
from brevitas.function import binary_sign
from brevitas.quant.solver.common import solve_float_to_int_impl_from_enum


DOMAIN_STRING = "onnx.brevitas"


Expand All @@ -19,6 +21,7 @@ class BrevitasBinaryQuantFn(Function):
@staticmethod
def symbolic(g, x, scale, zero_point, bit_width, narrow_range, signed, rounding_mode):
ret = g.op(f'{DOMAIN_STRING}::BipolarQuant', x, scale)
ret.setType(x.type().with_sizes(_get_tensor_sizes(x)))
return ret

@staticmethod
Expand All @@ -40,6 +43,7 @@ def symbolic(g, x, scale, zero_point, bit_width, narrow_range, signed, rounding_
rounding_mode_s=rounding_mode,
signed_i=int(signed),
narrow_i=int(narrow_range))
ret.setType(x.type().with_sizes(_get_tensor_sizes(x)))
return ret

@staticmethod
Expand Down
8 changes: 6 additions & 2 deletions src/brevitas/export/onnx/qonnx/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from brevitas.export.manager import _set_recurrent_layer_export_mode
from brevitas.export.onnx.debug import DebugMarkerFunction
from brevitas.export.onnx.manager import ONNXBaseManager
from brevitas.export.onnx.finn.function.parameter import QuantizedConvNdFn
from brevitas.export.onnx.finn.handler.parameter import FINNQuantConvNdHandler

from .function import BrevitasBinaryQuantFn
from .function import BrevitasQuantFn
Expand Down Expand Up @@ -42,14 +44,16 @@ class QONNXManager(ONNXBaseManager):
BrevitasDecoupledWeightQuantProxyHandler,
BrevitasDecoupledWeightQuantWithInputProxyHandler,
BrevitasTruncQuantProxyHandler,
BrevitasQuantLSTMLayerHandler]
BrevitasQuantLSTMLayerHandler,
FINNQuantConvNdHandler]
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this (FINN ONNX is being deprecated).


custom_fns = [
DebugMarkerFunction,
BrevitasQuantFn,
BrevitasBinaryQuantFn,
BrevitasTruncFn,
BrevitasQuantLSTMCellFn]
BrevitasQuantLSTMCellFn,
QuantizedConvNdFn]
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this (FINN ONNX is being deprecated).


@classmethod
def set_export_mode(cls, model: Module, enabled: bool):
Expand Down