{"action":"created","issue":{"url":"https://api.github.com/repos/pytorch/pytorch/issues/11725","repository_url":"https://api.github.com/repos/pytorch/pytorch","labels_url":"https://api.github.com/repos/pytorch/pytorch/issues/11725/labels{/name}","comments_url":"https://api.github.com/repos/pytorch/pytorch/issues/11725/comments","events_url":"https://api.github.com/repos/pytorch/pytorch/issues/11725/events","html_url":"https://github.com/pytorch/pytorch/pull/11725","id":360487034,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE1NzM2MTM5","number":11725,"title":"Introduce ExtensionVersioner for C++ extensions","user":{"login":"goldsborough","id":6429851,"node_id":"MDQ6VXNlcjY0Mjk4NTE=","avatar_url":"https://avatars3.githubusercontent.com/u/6429851?v=4","gravatar_id":"","url":"https://api.github.com/users/goldsborough","html_url":"https://github.com/goldsborough","followers_url":"https://api.github.com/users/goldsborough/followers","following_url":"https://api.github.com/users/goldsborough/following{/other_user}","gists_url":"https://api.github.com/users/goldsborough/gists{/gist_id}","starred_url":"https://api.github.com/users/goldsborough/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/goldsborough/subscriptions","organizations_url":"https://api.github.com/users/goldsborough/orgs","repos_url":"https://api.github.com/users/goldsborough/repos","events_url":"https://api.github.com/users/goldsborough/events{/privacy}","received_events_url":"https://api.github.com/users/goldsborough/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-09-14T23:59:45Z","updated_at":"2018-09-18T04:29:48Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/pytorch/pytorch/pulls/11725","html_url":"https://github.com/pytorch/pytorch/pull/11725","diff_url":"https://github.com/pytorch/pytorch/pull/11725.diff","patch_url":"https://github.com/pytorch/pytorch/pull/11725.patch"},"body":"Python never closes shared library it `dlopen`s. This means that calling `load` or `load_inline` (i.e. building a JIT C++ extension) with the same C++ extension name twice in the same Python process will never re-load the library, even if the compiled source code and the underlying shared library have changed. The only way to circumvent this is to create a new library and load it under a new module name.\r\n\r\nI fix this, of course, by introducing a layer of indirection. Loading a JIT C++ extension now goes through an `ExtensionVersioner`, which hashes the contents of the source files as well as build flags, and if this hash changed, bumps an internal version stored for each module name. A bump in the version will result in the ninja file being edited and a new shared library and effectively a new C++ extension to be compiled. For this the version name is appended as `_v<version>` to the extension name for all versions greater zero.\r\n\r\nOne caveat is that if you were to update your code many times and always re-load it in the same process, you may end up with quite a lot of shared library objects in your extension's folder under `/tmp`. I imagine this isn't too bad, since extensions are typically small and there isn't really a good way for us to garbage collect old libraries, since we don't know what still has handles to them.\r\n\r\nFixes https://github.com/pytorch/pytorch/issues/11398 CC @t-vi \r\n\r\n@ezyang @gchanan @soumith @fmassa "},"comment":{"url":"https://api.github.com/repos/pytorch/pytorch/issues/comments/422251729","html_url":"https://github.com/pytorch/pytorch/pull/11725#issuecomment-422251729","issue_url":"https://api.github.com/repos/pytorch/pytorch/issues/11725","id":422251729,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMjI1MTcyOQ==","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},"created_at":"2018-09-18T04:29:48Z","updated_at":"2018-09-18T04:29:48Z","author_association":"CONTRIBUTOR","body":"One day, someone is going to deploy hot loadable C++ extensions with PyTorch in prod, and then wonder why after a week the Python process crashes XD"}}
{"actor":{"display_login":"ezyang"}}