{"action":"created","issue":{"url":"https://api.github.com/repos/pytorch/pytorch/issues/8553","repository_url":"https://api.github.com/repos/pytorch/pytorch","labels_url":"https://api.github.com/repos/pytorch/pytorch/issues/8553/labels{/name}","comments_url":"https://api.github.com/repos/pytorch/pytorch/issues/8553/comments","events_url":"https://api.github.com/repos/pytorch/pytorch/issues/8553/events","html_url":"https://github.com/pytorch/pytorch/issues/8553","id":332800635,"node_id":"MDU6SXNzdWUzMzI4MDA2MzU=","number":8553,"title":"import torch._thnn during initial setup transitively triggers import of C extension, leading to module 'torch' has no attribute","user":{"login":"ezyang","id":13564,"node_id":"MDQ6VXNlcjEzNTY0","avatar_url":"https://avatars0.githubusercontent.com/u/13564?v=4","gravatar_id":"","url":"https://api.github.com/users/ezyang","html_url":"https://github.com/ezyang","followers_url":"https://api.github.com/users/ezyang/followers","following_url":"https://api.github.com/users/ezyang/following{/other_user}","gists_url":"https://api.github.com/users/ezyang/gists{/gist_id}","starred_url":"https://api.github.com/users/ezyang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ezyang/subscriptions","organizations_url":"https://api.github.com/users/ezyang/orgs","repos_url":"https://api.github.com/users/ezyang/repos","events_url":"https://api.github.com/users/ezyang/events{/privacy}","received_events_url":"https://api.github.com/users/ezyang/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"anderspapitto","id":1388690,"node_id":"MDQ6VXNlcjEzODg2OTA=","avatar_url":"https://avatars3.githubusercontent.com/u/1388690?v=4","gravatar_id":"","url":"https://api.github.com/users/anderspapitto","html_url":"https://github.com/anderspapitto","followers_url":"https://api.github.com/users/anderspapitto/followers","following_url":"https://api.github.com/users/anderspapitto/following{/other_user}","gists_url":"https://api.github.com/users/anderspapitto/gists{/gist_id}","starred_url":"https://api.github.com/users/anderspapitto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anderspapitto/subscriptions","organizations_url":"https://api.github.com/users/anderspapitto/orgs","repos_url":"https://api.github.com/users/anderspapitto/repos","events_url":"https://api.github.com/users/anderspapitto/events{/privacy}","received_events_url":"https://api.github.com/users/anderspapitto/received_events","type":"User","site_admin":false},"assignees":[{"login":"anderspapitto","id":1388690,"node_id":"MDQ6VXNlcjEzODg2OTA=","avatar_url":"https://avatars3.githubusercontent.com/u/1388690?v=4","gravatar_id":"","url":"https://api.github.com/users/anderspapitto","html_url":"https://github.com/anderspapitto","followers_url":"https://api.github.com/users/anderspapitto/followers","following_url":"https://api.github.com/users/anderspapitto/following{/other_user}","gists_url":"https://api.github.com/users/anderspapitto/gists{/gist_id}","starred_url":"https://api.github.com/users/anderspapitto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anderspapitto/subscriptions","organizations_url":"https://api.github.com/users/anderspapitto/orgs","repos_url":"https://api.github.com/users/anderspapitto/repos","events_url":"https://api.github.com/users/anderspapitto/events{/privacy}","received_events_url":"https://api.github.com/users/anderspapitto/received_events","type":"User","site_admin":false}],"milestone":null,"comments":0,"created_at":"2018-06-15T14:37:27Z","updated_at":"2018-06-18T17:07:20Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Steps to reproduce:\r\n1. Build PyTorch\r\n2. Add a new native function and a docstring for it in `torch._torch_docs` (the key is that, there should be a new symbol added to `torch._C`, and a function in `_torch_docs` which relies on this symbol being defined)\r\n3. Rebuild PyTorch\r\n\r\nExpected result: It works\r\n\r\nActual result: In my most recent build, I get:\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"tools/setup_helpers/generate_code.py\", line 110, in <module>\r\n    main()\r\n  File \"tools/setup_helpers/generate_code.py\", line 106, in main\r\n    options.install_dir)\r\n  File \"tools/setup_helpers/generate_code.py\", line 80, in generate_code\r\n    from tools.nnwrap import generate_wrappers as generate_nn_wrappers\r\n  File \"/data/users/ezyang/pytorch-tmp/tools/nnwrap/__init__.py\", line 1, in <module>\r\n    from .generate_wrappers import generate_wrappers, wrap_function\r\n  File \"/data/users/ezyang/pytorch-tmp/tools/nnwrap/generate_wrappers.py\", line 13, in <module>\r\n    from torch._thnn import utils as thnn_utils\r\n  File \"/data/users/ezyang/pytorch-tmp/torch/__init__.py\", line 292, in <module>\r\n    from . import _torch_docs, _tensor_docs, _storage_docs\r\n  File \"/data/users/ezyang/pytorch-tmp/torch/_torch_docs.py\", line 600, in <module>\r\n    add_docstr(torch.bincount,\r\nAttributeError: module 'torch' has no attribute 'bincount'\r\n```\r\n\r\nI believe the reason is the following diff in fcd9af8a257f83450ba82cccd227fe43bde7c879 (#8397):\r\n\r\n```\r\n-thnn_utils = import_module('torch._thnn.utils', THNN_UTILS_PATH)\r\n+try:\r\n+    from torch._thnn import utils as thnn_utils\r\n+except ImportError:\r\n+    from ..shared import import_module\r\n+    thnn_utils = import_module('torch._thnn.utils', THNN_UTILS_PATH)\r\n```\r\n\r\n`torch._thnn` is inside `torch`, which means that a regular (non `import_module`) import will first try to load `torch/__init__.py`, which is what sets up the docstrings. But this is happening before we've built the C extension, so not everything you want is there."},"comment":{"url":"https://api.github.com/repos/pytorch/pytorch/issues/comments/398126274","html_url":"https://github.com/pytorch/pytorch/issues/8553#issuecomment-398126274","issue_url":"https://api.github.com/repos/pytorch/pytorch/issues/8553","id":398126274,"node_id":"MDEyOklzc3VlQ29tbWVudDM5ODEyNjI3NA==","user":{"login":"zdevito","id":370202,"node_id":"MDQ6VXNlcjM3MDIwMg==","avatar_url":"https://avatars0.githubusercontent.com/u/370202?v=4","gravatar_id":"","url":"https://api.github.com/users/zdevito","html_url":"https://github.com/zdevito","followers_url":"https://api.github.com/users/zdevito/followers","following_url":"https://api.github.com/users/zdevito/following{/other_user}","gists_url":"https://api.github.com/users/zdevito/gists{/gist_id}","starred_url":"https://api.github.com/users/zdevito/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zdevito/subscriptions","organizations_url":"https://api.github.com/users/zdevito/orgs","repos_url":"https://api.github.com/users/zdevito/repos","events_url":"https://api.github.com/users/zdevito/events{/privacy}","received_events_url":"https://api.github.com/users/zdevito/received_events","type":"User","site_admin":false},"created_at":"2018-06-18T17:07:20Z","updated_at":"2018-06-18T17:07:20Z","author_association":"CONTRIBUTOR","body":"Related: If you introduce a segfault or exception throw in _C.so while developing, the build will break and will require the manual removal of _C.so to get working again."}}
{"actor":{"display_login":"zdevito"}}