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

[TRANSFORM] Fix virtual device annotation issue with BYOC subgraphs #13325

Merged
merged 2 commits into from
Dec 19, 2022

Conversation

srkreddy1238
Copy link
Contributor

Heterogeneous module partitioned by BYOC has functions nodes without any VirtualDevice definition (having FullyUnconstrained device). Ignoring the device here causes expr_virtual_devices_ being empty when PopVirtualDevice is called assuming above PushVirtualDevice is succeeded. PushVirtualDevice and PopVirtualDevice occurs as pairs across function body, hence it's better to insert the The Virtual Device for Uncontrained and Pop it subsequently.

Heterogeneous module partitioned by BYOC has functions nodes without any VirtualDevice
definition (having FullyUnconstrained device). Ignoring the device here causes
expr_virtual_devices_ being empty when PopVirtualDevice is called assuming above PushVirtualDevice
is succeeded. PushVirtualDevice and PopVirtualDevice occurs as pairs across function body,
hence it's better to insert the The Virtual Device for Uncontrained and Pop it subsequently.
@tvm-bot
Copy link
Collaborator

tvm-bot commented Nov 8, 2022

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

  • No users to tag found in teams: transform See #10317 for details
  • Built docs for commit e24e5ea can be found here.

Generated by tvm-bot

Copy link
Contributor

@csullivan csullivan left a comment

Choose a reason for hiding this comment

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

Hi @srkreddy1238, I didn't quite understand the conclusion you make,

PushVirtualDevice and PopVirtualDevice occurs as pairs across function body, hence it's better to insert the The Virtual Device for Uncontrained and Pop it subsequently

Naively I can understand why we skip pushing an unconstrained virtual device: If something is fully unconstrained then it's virtual device shouldn't influence the function body visitation. What issue is this causing in BYOC?

Is there a unit test you can consider contributing that can help illustrate the issue?

@srkreddy1238
Copy link
Contributor Author

srkreddy1238 commented Nov 9, 2022

PushVirtualDevice and PopVirtualDevice maintains the current VirtualDevice information on stack expr_virtual_devices_ . These calls are invoked across a block parsing (FunctionNodes, CallNode ..etc). The stack (expr_virtual_devices_) grows as we nest into the functions.

def @tvmgen_default_clml_main_17(%clml_17_i0: Tensor[(1, 2048), float32] /* ty=Tensor[(1, 2048), float32] */, Inline=1, Compiler="clml", global_symbol="tvmgen_default_clml_main_17", Primitive=1) -> Tensor[(1, 1000), float32] {
  %245 = fn (%FunctionVar_0_01: Tensor[(1, 2048), float32] /* ty=Tensor[(1, 2048), float32] */, PartitionedFromPattern="nn.dense_nn.bias_add_", Composite="clml.dense") -> Tensor[(1, 1000), float32] {
    %244 = nn.dense(%FunctionVar_0_01, meta[relay.Constant][257] /* ty=Tensor[(1000, 2048), float32] */, units=1000) /* ty=Tensor[(1, 1000), float32] */;
    add(%244, meta[relay.Constant][258] /* ty=Tensor[(1, 1000), float32] */) /* ty=Tensor[(1, 1000), float32] */
  } /* ty=fn (Tensor[(1, 2048), float32]) -> Tensor[(1, 1000), float32] */;
  %245(%clml_17_i0) /* ty=Tensor[(1, 1000), float32] */
}

In the above IR the composite function %245 = fn (%FunctionVar_0_01 will not have a VirtualDevice definition ( VirtualDevice(?)) and the PushVirtualDevice fails. Whereas at end of this function parsing the PopVirtualDevice removes the VirtualDevice corresponding to the outer scope function. From here all annotations fail due to empty stack.

I figured it out as part of large network. I am working on to facilitate a test case for the same.

@srkreddy1238
Copy link
Contributor Author

@mbs-octoml

@srkreddy1238 srkreddy1238 force-pushed the byoc_device_visitor branch 2 times, most recently from 02a8c8a to e24e5ea Compare November 16, 2022 04:45
Copy link
Contributor

@csullivan csullivan left a comment

Choose a reason for hiding this comment

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

Thanks @srkreddy1238, LGTM

@srkreddy1238
Copy link
Contributor Author

@junrushao can you take a look on this ?

@csullivan
Copy link
Contributor

cc @echuraev @elvin-n does this change look good to you and pass internal texture tests?

Copy link
Contributor

@echuraev echuraev left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks

@elvin-n
Copy link
Contributor

elvin-n commented Nov 30, 2022

cc @echuraev @elvin-n does this change look good to you and pass internal texture

Our tests runs in CI and if we see green CI it means this change does not affect them and whole flow. I cannot answer if this change affects origin Mark's idea and if it does not brake anything in other places. Again, assuming that we have many tests for VirtualDevices and they passed, this change should be safe.

@srkreddy1238
Copy link
Contributor Author

@junrushao can you conclude this PR ? There are some follow up on this.

@junrushao
Copy link
Member

Sure! It’s been approved for a while already. Not sure why it’s not merged yet

@junrushao junrushao merged commit ddb006e into apache:main Dec 19, 2022
fzi-peccia pushed a commit to fzi-peccia/tvm that referenced this pull request Mar 27, 2023
…pache#13325)

* [TRANSFORM] Fix virtual device anaotation issue with BYOC subgraphs

Heterogeneous module partitioned by BYOC has functions nodes without any VirtualDevice
definition (having FullyUnconstrained device). Ignoring the device here causes
expr_virtual_devices_ being empty when PopVirtualDevice is called assuming above PushVirtualDevice
is succeeded. PushVirtualDevice and PopVirtualDevice occurs as pairs across function body,
hence it's better to insert the The Virtual Device for Uncontrained and Pop it subsequently.

* * Test case

Co-authored-by: Siva Rama Krishna Reddy B <sivb@blr-ubuntu-ripper.qualcomm.com>
mikeseven pushed a commit to mikeseven/tvm that referenced this pull request Sep 27, 2023
…pache#13325)

* [TRANSFORM] Fix virtual device anaotation issue with BYOC subgraphs

Heterogeneous module partitioned by BYOC has functions nodes without any VirtualDevice
definition (having FullyUnconstrained device). Ignoring the device here causes
expr_virtual_devices_ being empty when PopVirtualDevice is called assuming above PushVirtualDevice
is succeeded. PushVirtualDevice and PopVirtualDevice occurs as pairs across function body,
hence it's better to insert the The Virtual Device for Uncontrained and Pop it subsequently.

* * Test case

Co-authored-by: Siva Rama Krishna Reddy B <sivb@blr-ubuntu-ripper.qualcomm.com>
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.

6 participants