Skip to content
Merged
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
12 changes: 11 additions & 1 deletion python/tvm/relay/frontend/tflite.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from .. import op as _op
from .. import qnn as _qnn
from ... import nd as _nd
from .util import get_scalar_from_constant
from .common import ExprTable
from .common import infer_shape as _infer_shape

Expand Down Expand Up @@ -2219,6 +2218,17 @@ def get_expr(self, input_tensor_idx):
def has_expr(self, input_tensor_idx):
return self.exp_tab.has_expr(get_tensor_name(self.subgraph, input_tensor_idx))


def get_scalar_from_constant(expr):
""" Returns scalar value from Relay constant scalar. """
assert isinstance(expr, _expr.Constant) and not expr.data.shape, \
"Expr is not a constant scalar."
value = expr.data.asnumpy()
assert value.dtype == np.dtype(np.int32) or value.dtype == np.dtype(np.float32), \
"value must be float32/int32"
return np.asscalar(value)


def build_str_map(obj):
"""Build string map of TFLite enum int value

Expand Down
33 changes: 0 additions & 33 deletions python/tvm/relay/frontend/util.py

This file was deleted.

11 changes: 10 additions & 1 deletion python/tvm/relay/qnn/op/legalizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import tvm
from tvm import relay
import numpy as np
Copy link
Contributor

Choose a reason for hiding this comment

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

A minor problem: Lint reports python/tvm/relay/qnn/op/legalizations.py:23: [C0411(wrong-import-order), ] third party import "import numpy as np" should be placed before "import tvm" on my platform. I have no idea why this PR can pass CI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not seeing this and CI doesn't appear to be failing on any other patches, can you post what command you're using to perform the linting?

Copy link
Contributor

Choose a reason for hiding this comment

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

I run ./tests/scripts/task_lint.sh directly from the repository root.

My pylint version:

pylint 2.4.4
astroid 2.3.3
Python 3.7.0 (default, Mar 12 2019, 20:10:09)
[GCC 7.3.0]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you take a look here:
https://github.com/apache/incubator-tvm/blob/063ba63a4448432a1e17ec8b793152cd8bba7c2c/docker/install/ubuntu_install_python_package.sh#L24
CI runs with pylint 1.9.4 and I imagine that's where the difference is coming from.

from .. import op as reg
from ...frontend.util import get_scalar_from_constant

#################################################
# Register the functions for different operators.
Expand Down Expand Up @@ -54,6 +54,15 @@ def qnn_dense_legalize(attrs, inputs, types):
# Helper functions.
###################

def get_scalar_from_constant(expr):
""" Returns scalar value from Relay constant scalar. """
assert isinstance(expr, relay.Constant) and not expr.data.shape, \
"Expr is not a constant scalar."
value = expr.data.asnumpy()
assert value.dtype == np.dtype(np.int32) or value.dtype == np.dtype(np.float32), \
"value must be float32/int32"
return np.asscalar(value)

# Helper function for lowering in the abscence of fast Int8 arithmetic units.
def helper_no_fast_int8_hw_legalization(attrs, inputs, types, relay_op):
""" Converts QNN operators into a sequence of Relay operators that are friendly to HW that do
Expand Down