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

[FIX,RPC] Skip RPC tests when using multiprocessing's spawn method #6858

Merged
merged 1 commit into from Nov 6, 2020

Conversation

tkonolige
Copy link
Contributor

The rpc tests are broken when running under pytest with multiprocessing using spawn. I suspect this is because pytest tests each function in a separate process and does not import the full module.

@tqchen

The rpc tests are broken when running under pytest with multiprocessing
using spawn. I suspect this is because pytest tests each function in a
separate process and does not import the full module.
@tqchen
Copy link
Member

tqchen commented Nov 6, 2020

I think it is fine as it is. A better way is to also fix the testcases so that we don't have to rely on the forking behavior in many rpc tests

@junrushao
Copy link
Member

Thanks for the contribution! I didn't actually understand where the issue comes from? Is it because some of the register_funcs are not correctly executed?

@tqchen
Copy link
Member

tqchen commented Nov 6, 2020

This is because some of the register_func are in local function scope instead of global, so they won't be executed right after spawn. Globally registered packedfunc will be preserved.

If we move most of the rpc testing function registration to tvm.testing. Or enable a env setup function that passes to the spawn method(via cloud pickle) which registers the function during rpc startup, it should work.

@tkonolige
Copy link
Contributor Author

This is because some of the register_func are in local function scope instead of global, so they won't be executed right after spawn. Globally registered packedfunc will be preserved

This is what I thought initially, but something weirder is going on. The globally registered packedfunc works when you run the test script on its own (without pytest). But when running under pytest, the registered functions cannot be found. I commented about it in the source code:

# tkonolige: The issue as I understand it is this: multiprocessing's spawn
 # method launches a new process and then imports the relevant modules. This
 # means that all registered functions must exist at the top level scope. In
 # this file they are, so all is well when we run this file directly.
 # However, when run under pytest, the functions aren't registered on the
 # server. I believe this is because pytest is also using multiprocessing to
 # run individual functions. Somewhere along the way, the imports are being
 # lost, so the server ends up not registering the functions.

@tqchen
Copy link
Member

tqchen commented Nov 6, 2020

I think this is because of the location of the "main" file. The python spawn might automatically run the global reg in the main file. but not other places. Pytest itself have a different main file.

Putting the registeration under tvm.testing means they are imported regardless. Alternatively, passing an startup env callback to RPCServer would mean the startup env function get called explicitly(and registers the function). My guess is that the startup env might be an attractive approach we can try.

@tqchen tqchen merged commit 3ea0686 into apache:main Nov 6, 2020
@tqchen
Copy link
Member

tqchen commented Nov 6, 2020

merge this for now, we should re-enable after we rewrite test to use startup env callback

trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Dec 2, 2020
…pache#6858)

The rpc tests are broken when running under pytest with multiprocessing
using spawn. I suspect this is because pytest tests each function in a
separate process and does not import the full module.
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Dec 4, 2020
…pache#6858)

The rpc tests are broken when running under pytest with multiprocessing
using spawn. I suspect this is because pytest tests each function in a
separate process and does not import the full module.
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Dec 4, 2020
…pache#6858)

The rpc tests are broken when running under pytest with multiprocessing
using spawn. I suspect this is because pytest tests each function in a
separate process and does not import the full module.
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.

None yet

3 participants