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

[Relay] VM prunes global functions with no direct calls. #4697

Closed
abergeron opened this issue Jan 13, 2020 · 2 comments
Closed

[Relay] VM prunes global functions with no direct calls. #4697

abergeron opened this issue Jan 13, 2020 · 2 comments

Comments

@abergeron
Copy link
Contributor

It seems there is a problem in the VM compiler for indirect calls to global functions that aren't used elsewhere.

I have a simple code block that reproduces it:

import tvm
from tvm import relay

ctx = tvm.ndarray.context('cpu', 0)

mod = relay.Module({})

fn1 = relay.Function([], relay.const(1))
fn2 = relay.Function([], relay.const(2))

g1 = relay.GlobalVar('g1')
g2 = relay.GlobalVar('g2')
mod[g1] = fn1
mod[g2] = fn2

p = relay.var('p', 'bool')
mod['main'] = relay.Function([p], relay.Call(relay.If(p, g1, g2), []))

print(str(mod))

vm = relay.create_executor(mod=mod, ctx=ctx, target='llvm', kind="vm")

relay_out = vm.evaluate()(True)

print("Relay result:\n", relay_out)

This errors at the relay.create_executor line saying there is no definition for g1.

  • If you change the calls in the main functions to use the fn1 and fn2 instead of the global variables, it works.
  • If you move the Call inside the If it works.

So it seems that because g1 and g2 don't get directly called they get removed at some point.

@abergeron abergeron changed the title VM prunes global functions with no direct calls. [Relay] VM prunes global functions with no direct calls. Jan 13, 2020
@zhiics
Copy link
Member

zhiics commented Jan 13, 2020

@abergeron Thanks for reporting this. There is pass in VM that removes the "unused" global functions. It probably removed these functions.

@zhiics
Copy link
Member

zhiics commented Jan 13, 2020

@abergeron #4700 fixes this.

@zhiics zhiics closed this as completed Jan 14, 2020
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

No branches or pull requests

2 participants