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

Require PyTorch v1.0 or newer and fix static TLS load error #380

Merged
merged 1 commit into from
Jan 17, 2019

Conversation

matthewfeickert
Copy link
Member

@matthewfeickert matthewfeickert commented Dec 31, 2018

Description

In requiring the latest version of PyTorch (v1.0) the loading of it after other imports in tests/conftest.py causes there to be an error during setup of the pytest fixtures

ImportError while loading conftest '/home/travis/build/diana-hep/pyhf/tests/conftest.py'.
tests/conftest.py:45: in <module>
    (pyhf.tensor.pytorch_backend(), None),
pyhf/tensor/__init__.py:24: in __getattr__
    e,
E   pyhf.exceptions.ImportBackendError: ('There was a problem importing PyTorch. The pytorch backend cannot be used.', ImportError('dlopen: cannot load any more object with static TLS',))

TLS appears to stand for thread local storage

and seems to be a reoccurring issue with PyTorch. The advice for how to deal with it from PyTorch Issue 2083 and Issue 2575 seems to be to simply change the import order so that

import torch

is always the first import in the files that are causing the issue. The rational for this fix is not understood to me, other then it just makes sure that libraries that (presumably) require a large amount of static TLS are dealt with first.

Checklist Before Requesting Reviewer

  • Tests are passing
  • "WIP" removed from the title of the pull request
  • Selected an Assignee for the PR to be responsible for the log summary

Before Merging

For the PR Assignees:

  • Summarize commit messages into a comprehensive review of the PR
* Require PyTorch v1.0 or newer
* Make torch the first import in tests/conftest.py to solve the "cannot load any more object with static TLS" (thread local storage) error that is common when using PyTorch along with other large libraries. c.f. PyTorch Issue 2083.

@matthewfeickert matthewfeickert added the bug Something isn't working label Dec 31, 2018
@matthewfeickert matthewfeickert self-assigned this Dec 31, 2018
@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.556% when pulling f363825 on fix/pytorch-static-TLS-load-error into a374278 on master.

@coveralls
Copy link

coveralls commented Dec 31, 2018

Coverage Status

Coverage remained the same at 97.556% when pulling 0bc1f64 on fix/pytorch-static-TLS-load-error into c3d06cc on master.

@matthewfeickert matthewfeickert force-pushed the fix/pytorch-static-TLS-load-error branch from f363825 to e49c455 Compare January 2, 2019 17:43
@matthewfeickert matthewfeickert changed the title WIP: Require PyTorch v1.0 or newer and fix static TLS load error Require PyTorch v1.0 or newer and fix static TLS load error Jan 2, 2019
@matthewfeickert
Copy link
Member Author

This PR should wait for PR #381 to be approved and merged and then should be rebased against master.

In requiring the latest version of PyTorch (v1.0) the loading of it
after other imports in tests/conftest.py causes there to be an error
during setup of the pytest fixtures

ImportError while loading conftest
'/home/travis/build/diana-hep/pyhf/tests/conftest.py'.
tests/conftest.py:45: in <module>
    (pyhf.tensor.pytorch_backend(), None),
pyhf/tensor/__init__.py:24: in __getattr__
    e,
E   pyhf.exceptions.ImportBackendError: ('There was a problem importing
PyTorch. The pytorch backend cannot be used.', ImportError('dlopen:
cannot load any more object with static TLS',))

TLS appears to stand for thead local storage

* https://stackoverflow.com/questions/19268293/matlab-error-cannot-open-with-static-tls

and seems to be a reoccuring issue with PyTorch. The advice for how to
deal with it from PyTorch Issue 2083 and 2575 seems to be to simply
change the import order so that

import torch

is always the first import in the files that are causing the issue. The
rational for this fix is not understood to me, other then it just makes
sure that libraries that (presumably) require a large amount of static
TLS are dealt with first.
@matthewfeickert matthewfeickert force-pushed the fix/pytorch-static-TLS-load-error branch from c3dd459 to 0bc1f64 Compare January 17, 2019 04:11
@matthewfeickert matthewfeickert merged commit f6875eb into master Jan 17, 2019
@matthewfeickert matthewfeickert deleted the fix/pytorch-static-TLS-load-error branch January 17, 2019 05:00
@matthewfeickert matthewfeickert mentioned this pull request Jan 17, 2019
4 tasks
@kratsg
Copy link
Contributor

kratsg commented Jan 17, 2019

We still need to understand why this is failing, don't we? Because of the change to how we run pytest isn't satisfactory...

@matthewfeickert
Copy link
Member Author

matthewfeickert commented Jan 17, 2019

We still need to understand why this is failing, don't we? Because of the change to how we run pytest isn't satisfactory...

Yes, we need to understand what is going on in Issue #385. I made branch backup/pytorch-static-TLS-load-error for us to continue doing studies on. However, this PR does still fixe issues that are keeping other work like PR #377 so it doesn't harm anything to merge it in now as PR #388 is apparently a good enough temporary patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants