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

[microNPU] Allow constants to be given as input to an operator #9515

Merged
merged 2 commits into from
Nov 17, 2021

Conversation

lhutton1
Copy link
Contributor

Currently the expectation is that all constants need to be encoded, however, this is not always the case for scalar inputs. This PR ensures that constants that don't need encoding are not treated like encoded constants by the EncodeConstants pass.

cc @mbaret @manupa-arm @ekalda @NicolaLancellotti @dchauhan-arm

Copy link
Contributor

@ekalda ekalda left a comment

Choose a reason for hiding this comment

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

Thanks @lhutton1 for the fix! Just some clarifying questions...

Comment on lines +443 to +456
def create_relay_graph():
inp = relay.var("input", shape=ifm_shape, dtype=dtype)
scalar = relay.const(np.ones((1, 1, 1, 1), dtype=dtype), dtype=dtype)
add = relay.qnn.op.add(
inp,
scalar,
relay.const(1.0, dtype="float32"),
relay.const(0, dtype="int32"),
relay.const(1.0, dtype="float32"),
relay.const(0, dtype="int32"),
relay.const(1.0, dtype="float32"),
relay.const(0, dtype="int32"),
)
func = relay.Function(relay.analysis.free_vars(add), add)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we start from Relay there instead of TFLite?

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 wasn't sure if there was a way to generate similar relay from TFLite, although admittedly I didn't really check. I'll have a look into it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, Relay is also needed due to the uint8 restriction so I'll leave this for now

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok yes, that makes sense!

interpreted as an encoded constant."""

def get_graph():
dtype = "uint8"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does the constant need to beuint8? (just asking for enlightenment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now this needs to be uint8 due to https://github.com/apache/tvm/blob/main/python/tvm/relay/backend/contrib/ethosu/tir_to_cs_translator.py#L254. Removing this opens up another can of worms that I'll address in another PR :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, makes sense, thanks for clarifying! :)

Currently the expectation is that all constants need to be encoded,
however, this is not always the case for scalar inputs. This PR
ensures that constants that don't need encoding are not treated
like encoded constants by the EncodeConstants pass.

Change-Id: I79cf4aa10d01c4ae9ce9cdafb6f21ebb2d028126
Change-Id: I67b61a2d2f67de25c47d2ace0e3a22c59ba8ea15
@lhutton1 lhutton1 force-pushed the dont-compress-input-constants branch from 889bd5f to e1458c5 Compare November 16, 2021 18:09
Copy link
Contributor

@manupak manupak left a comment

Choose a reason for hiding this comment

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

LGTM! @ekalda could you take another look ?

Copy link
Contributor

@ekalda ekalda left a comment

Choose a reason for hiding this comment

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

LGTM! :)

@manupak manupak merged commit 95ff358 into apache:main Nov 17, 2021
@manupak
Copy link
Contributor

manupak commented Nov 17, 2021

Thanks @lhutton1 @ekalda

@lhutton1 lhutton1 deleted the dont-compress-input-constants branch November 17, 2021 12:51
mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request Dec 1, 2021
…e#9515)

* [microNPU] Allow constants to be given as input to an operator

Currently the expectation is that all constants need to be encoded,
however, this is not always the case for scalar inputs. This PR
ensures that constants that don't need encoding are not treated
like encoded constants by the EncodeConstants pass.

Change-Id: I79cf4aa10d01c4ae9ce9cdafb6f21ebb2d028126

* address comments

Change-Id: I67b61a2d2f67de25c47d2ace0e3a22c59ba8ea15
mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request Dec 1, 2021
…e#9515)

* [microNPU] Allow constants to be given as input to an operator

Currently the expectation is that all constants need to be encoded,
however, this is not always the case for scalar inputs. This PR
ensures that constants that don't need encoding are not treated
like encoded constants by the EncodeConstants pass.

Change-Id: I79cf4aa10d01c4ae9ce9cdafb6f21ebb2d028126

* address comments

Change-Id: I67b61a2d2f67de25c47d2ace0e3a22c59ba8ea15
lhutton1 added a commit to lhutton1/tvm that referenced this pull request Dec 22, 2021
PR apache#9515 enabled support for scalar constants, but didn't consider the
case of a scalar value where the underlying constant data does not have
a shape i.e. `constant.shape == []`. See the test case for a visual
differece when the scalar value is 1.

Change-Id: Id7a238cb5bf999dd5a8428c097202f9fb940a5f0
lhutton1 added a commit to lhutton1/tvm that referenced this pull request Jan 4, 2022
PR apache#9515 enabled support for scalar constants, but didn't consider the
case of a scalar value where the underlying constant data does not have
a shape i.e. `constant.shape == []`. See the test case for a visual
differece when the scalar value is 1.

Change-Id: Id7a238cb5bf999dd5a8428c097202f9fb940a5f0
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 7, 2022
…e#9515)

* [microNPU] Allow constants to be given as input to an operator

Currently the expectation is that all constants need to be encoded,
however, this is not always the case for scalar inputs. This PR
ensures that constants that don't need encoding are not treated
like encoded constants by the EncodeConstants pass.

Change-Id: I79cf4aa10d01c4ae9ce9cdafb6f21ebb2d028126

* address comments

Change-Id: I67b61a2d2f67de25c47d2ace0e3a22c59ba8ea15
yangulei pushed a commit to yangulei/tvm that referenced this pull request Jan 11, 2022
…e#9515)

* [microNPU] Allow constants to be given as input to an operator

Currently the expectation is that all constants need to be encoded,
however, this is not always the case for scalar inputs. This PR
ensures that constants that don't need encoding are not treated
like encoded constants by the EncodeConstants pass.

Change-Id: I79cf4aa10d01c4ae9ce9cdafb6f21ebb2d028126

* address comments

Change-Id: I67b61a2d2f67de25c47d2ace0e3a22c59ba8ea15
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 13, 2022
…e#9515)

* [microNPU] Allow constants to be given as input to an operator

Currently the expectation is that all constants need to be encoded,
however, this is not always the case for scalar inputs. This PR
ensures that constants that don't need encoding are not treated
like encoded constants by the EncodeConstants pass.

Change-Id: I79cf4aa10d01c4ae9ce9cdafb6f21ebb2d028126

* address comments

Change-Id: I67b61a2d2f67de25c47d2ace0e3a22c59ba8ea15
lhutton1 added a commit to lhutton1/tvm that referenced this pull request Jan 17, 2022
PR apache#9515 enabled support for scalar constants, but didn't consider the
case of a scalar value where the underlying constant data does not have
a shape i.e. `constant.shape == []`. See the test case for a visual
differece when the scalar value is 1.

Change-Id: Id7a238cb5bf999dd5a8428c097202f9fb940a5f0
manupak pushed a commit that referenced this pull request Jan 18, 2022
* [microNPU] Add support for scalar values

PR #9515 enabled support for scalar constants, but didn't consider the
case of a scalar value where the underlying constant data does not have
a shape i.e. `constant.shape == []`. See the test case for a visual
differece when the scalar value is 1.

Change-Id: Id7a238cb5bf999dd5a8428c097202f9fb940a5f0

* Fix failing test by removing constant

Before this PR scalar constants were handled differently so this test
was able to pass. Now that scalar constants are handled in the same
manner as tensor constants, the test fails since unexpected tir is
produced in the compilation pipeline. Since the relay used in this test
case is not expected to be produced by higher levels of the compiler,
removing this constant for now.

Change-Id: I4ea5155778809041339e6faac05af3f72c3e3ea5

* clean up finding tensor from inputs

Change-Id: Ideccf84f8c9149148ff23e2406229cf637c982a3
yuanfz98 pushed a commit to yuanfz98/tvm that referenced this pull request Jan 24, 2022
* [microNPU] Add support for scalar values

PR apache#9515 enabled support for scalar constants, but didn't consider the
case of a scalar value where the underlying constant data does not have
a shape i.e. `constant.shape == []`. See the test case for a visual
differece when the scalar value is 1.

Change-Id: Id7a238cb5bf999dd5a8428c097202f9fb940a5f0

* Fix failing test by removing constant

Before this PR scalar constants were handled differently so this test
was able to pass. Now that scalar constants are handled in the same
manner as tensor constants, the test fails since unexpected tir is
produced in the compilation pipeline. Since the relay used in this test
case is not expected to be produced by higher levels of the compiler,
removing this constant for now.

Change-Id: I4ea5155778809041339e6faac05af3f72c3e3ea5

* clean up finding tensor from inputs

Change-Id: Ideccf84f8c9149148ff23e2406229cf637c982a3
crazydemo pushed a commit to crazydemo/tvm that referenced this pull request Jan 27, 2022
* [microNPU] Add support for scalar values

PR apache#9515 enabled support for scalar constants, but didn't consider the
case of a scalar value where the underlying constant data does not have
a shape i.e. `constant.shape == []`. See the test case for a visual
differece when the scalar value is 1.

Change-Id: Id7a238cb5bf999dd5a8428c097202f9fb940a5f0

* Fix failing test by removing constant

Before this PR scalar constants were handled differently so this test
was able to pass. Now that scalar constants are handled in the same
manner as tensor constants, the test fails since unexpected tir is
produced in the compilation pipeline. Since the relay used in this test
case is not expected to be produced by higher levels of the compiler,
removing this constant for now.

Change-Id: I4ea5155778809041339e6faac05af3f72c3e3ea5

* clean up finding tensor from inputs

Change-Id: Ideccf84f8c9149148ff23e2406229cf637c982a3
ylc pushed a commit to ylc/tvm that referenced this pull request Feb 16, 2022
* [microNPU] Add support for scalar values

PR apache#9515 enabled support for scalar constants, but didn't consider the
case of a scalar value where the underlying constant data does not have
a shape i.e. `constant.shape == []`. See the test case for a visual
differece when the scalar value is 1.

Change-Id: Id7a238cb5bf999dd5a8428c097202f9fb940a5f0

* Fix failing test by removing constant

Before this PR scalar constants were handled differently so this test
was able to pass. Now that scalar constants are handled in the same
manner as tensor constants, the test fails since unexpected tir is
produced in the compilation pipeline. Since the relay used in this test
case is not expected to be produced by higher levels of the compiler,
removing this constant for now.

Change-Id: I4ea5155778809041339e6faac05af3f72c3e3ea5

* clean up finding tensor from inputs

Change-Id: Ideccf84f8c9149148ff23e2406229cf637c982a3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants