Skip to content

Conversation

@echuraev
Copy link
Contributor

Tuning doesn't work after #12969.
It reports the following error:

ImportError: cannot import name 'get_const_float' from partially initialized module 'tvm.topi.utils' (most likely due to a circular import)

In this commit, I moved import relay to a function which used in a test. And it helps to fix this circular import.

To reproduce this issue, you can run the following tutorial and will see this error.

cc: @guberti, @areusch, @ekalda

@tvm-bot
Copy link
Collaborator

tvm-bot commented Oct 17, 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.

Generated by tvm-bot

Tuning doesn't work after apache#12969.
It reports the following error:

```
ImportError: cannot import name 'get_const_float' from partially initialized module 'tvm.topi.utils' (most likely due to a circular import)
```

In this commit I moved import relay to a function which used in a test.
And it helps to fix this circular import
@echuraev echuraev force-pushed the echuraev/fix_tuning branch from b1dfea4 to e31b648 Compare October 17, 2022 13:56
@guberti
Copy link
Member

guberti commented Oct 17, 2022

If tuning doesn't work, that's a pretty big oversight on my part and a hotfix like this makes sense.

I can't seem to reproduce the issue though - here's a log of what I get when I run on the latest TVM revision.

We also have a unit test that (I believe) compiles and re-deploys the docs, with output, whenever changes are made. Here's a link to the tutorial in question - the output there looks fine.

Any ideas why I can't seem to reproduce this?

@echuraev
Copy link
Contributor Author

Hmmm. Looks interesting. I was able to reproduce this issue on the commit: 3f0d3f2
I run on Ubuntu 20.04 with python 3.8.8. Here is my output for this script from the tutorial. And you can see that tuning doesn't work. @guberti which environment do you use?

@echuraev
Copy link
Contributor Author

I see that someone else has the same issue: https://discuss.tvm.apache.org/t/error-of-import-topi-utils-during-autotune/13728

@guberti
Copy link
Member

guberti commented Oct 17, 2022

I'm on almost the exact same environment - Ubuntu 20.04 and Python 3.8.10 (see log). I wonder if this is an issue with your Python PATH environment, but I don't have any way to investigate.

I suspect the error will go away once #13051 merges, but I'm very curious what the underlying problem is - we should add a test for this.

@driazati
Copy link
Member

I suspect this also might be related to how tvm doesn't initialize/import all nested modules, so you can end up with situations like:

>>> import tvm
>>> tvm.relay.Var
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'tvm' has no attribute 'relay'
>>> from tvm import relay
>>> tvm.relay.Var
<class 'tvm.relay.expr.Var'>

We do run the tutorials as part of the post-merge ci jobs for main, the latest successful one is here which looks like it was able to run the tutorial, though it does it in a Docker environment (you might be able to re-create that locally with python tests/scripts/ci.py docs --tutorial-pattern 'autotvm_relay_x86.py')

Copy link
Member

@junrushao junrushao left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@guberti guberti left a comment

Choose a reason for hiding this comment

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

The changes themselves seem reasonable, but I'm hesitant to merge a hotfix for an issue we can't reproduce. Any chance this issue can be reproduced on Google Colab or something similar?

@masahi
Copy link
Member

masahi commented Oct 17, 2022

It's not just tuning, I got this error yesterday when running https://github.com/apache/tvm/blob/main/tests/python/unittest/test_meta_schedule_schedule_rule_mlt.py by python. The error doesn't happen if the script is invoked by pytest.

@masahi masahi merged commit 8d2e887 into apache:main Oct 17, 2022
@echuraev echuraev deleted the echuraev/fix_tuning branch October 18, 2022 05:34
comaniac added a commit to awslabs/raf that referenced this pull request Oct 18, 2022
comaniac added a commit to awslabs/raf that referenced this pull request Oct 18, 2022
* [TVM] Update Submodule

* Bring apache/tvm#13099

* Compatible apache/tvm#12923

* lint

* trigger

Co-authored-by: SubmoduleUpdaterBot <submodule-updater-bot@users.noreply.github.com>
Co-authored-by: Cody Yu <comaniac0422@gmail.com>
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 10, 2022
* [HotFix] Fix python import

Tuning doesn't work after apache#12969.
It reports the following error:

```
ImportError: cannot import name 'get_const_float' from partially initialized module 'tvm.topi.utils' (most likely due to a circular import)
```

In this commit I moved import relay to a function which used in a test.
And it helps to fix this circular import

* Fix lint
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
* [HotFix] Fix python import

Tuning doesn't work after apache#12969.
It reports the following error:

```
ImportError: cannot import name 'get_const_float' from partially initialized module 'tvm.topi.utils' (most likely due to a circular import)
```

In this commit I moved import relay to a function which used in a test.
And it helps to fix this circular import

* Fix lint
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