-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[testing][py_converter] Enhance py_converter to better support entire modules #13769
Conversation
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.
Generated by tvm-bot |
Please review @junrushao (or tag other reviewers) |
Hm, this test worked in my fork. Wonder why it fails in mainline |
The problem seems to be that this cast on mainline will not convince Python that the result is an opaque Object rather than a PackedFunc. Not sure how to change it: TVM_REGISTER_GLOBAL("runtime.CastPackedFuncToObject").set_body_typed([](const PackedFunc& pf) {
return Downcast<ObjectRef>(pf);
}); Any advice? |
@tqchen helpfully advised that the issue stems from passing a list containing a PackedFunc to the constructor. Calling the |
The CI error appears to be spurious. |
@tvm-bot rerun |
I think there's been another spurious failure. |
@tvm-bot rerun |
c7ee534
to
edd3ee3
Compare
CC @Hzfengsy would you like to review this PR? Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks a lot, @slyubomirsky!
This PR makes a few improvements to
py_converter
to make it more useful for fuzz testing, especially when running larger modules.In particular, these changes are to support returning the definition of a global var directly (e.g., if you do
run_as_python(main_var, mod=mod)
, the result will be a function corresponding tomod["main"]
) and to correct two bugs in the previous implementation:PackedFunc
s. However, another fix was also needed: Even thoughPackedFunc
is anObjectRef
in C++, the Python bindings do not recognizePackedFunc
s asObject
s, so the code now calls the FFI API tuple constructor directly.IRModule.from_expr
to wrap passed in expressions in a module. However,from_expr
will not overwrite themain
function if one is passed in via thefunctions
argument. Thus, if the user passed in a module that already had amain
function defined, the wrapping would be done incorrectly and result in themain
being copied many times. This PR corrects this error by not assuming that the namemain
will be available and instead constructing a new module with a reserved name for the target.None of the cases above had been tested before (there are now tests included)