pyhf icon indicating copy to clipboard operation
pyhf copied to clipboard

Warnings with pytorch backend and simplemodels

Open alexander-held opened this issue 2 years ago • 1 comments

Summary

I ran into two warnings with the pytorch backend, see below. I have not tried to look at where exactly they come from so far.

OS / Environment

n/a

Steps to Reproduce

Run the following with python -Wd:

import pyhf

pyhf.set_backend("pytorch")
model = pyhf.simplemodels.uncorrelated_background(
    signal=[24.0, 22.0], bkg=[50.0, 52.0], bkg_uncertainty=[3.0, 7.0]
)

File Upload (optional)

No response

Expected Results

no warnings

Actual Results

[...]/pyhf/src/pyhf/tensor/pytorch_backend.py:201: DeprecationWarning: In future, it will be an error for 'np.bool_' scalars to be interpreted as an index
  return torch.as_tensor(tensor_in, dtype=dtype)
[...]/pyhf/src/pyhf/tensor/pytorch_backend.py:201: UserWarning: Creating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with numpy.array() before converting to a tensor. (Triggered internally at  /Users/runner/work/pytorch/pytorch/pytorch/torch/csrc/utils/tensor_new.cpp:204.)
  return torch.as_tensor(tensor_in, dtype=dtype)

pyhf Version

pyhf, version 0.7.0rc2.dev18

Code of Conduct

  • [X] I agree to follow the Code of Conduct

alexander-held avatar Aug 14 '22 17:08 alexander-held

[...]/pyhf/src/pyhf/tensor/pytorch_backend.py:201: DeprecationWarning: In future, it will be an error for 'np.bool_' scalars to be interpreted as an index
  return torch.as_tensor(tensor_in, dtype=dtype)

I need to look if we have an Issue for this. If not, then I should probably make one and update the PyTorch API and also figure out what a new lower bound on torch should be.

[...]/pyhf/src/pyhf/tensor/pytorch_backend.py:201: UserWarning: Creating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with numpy.array() before converting to a tensor. (Triggered internally at  /Users/runner/work/pytorch/pytorch/pytorch/torch/csrc/utils/tensor_new.cpp:204.)
  return torch.as_tensor(tensor_in, dtype=dtype)

This is known as it was added to

https://github.com/scikit-hep/pyhf/blob/a6186405ae5acee472133874e9a477dc41def7df/pyproject.toml#L89

in PR #1773. This should get fixed at some point if possible, but isn't a huge pain point.

matthewfeickert avatar Aug 18 '22 17:08 matthewfeickert