bayesiains / nflows

Normalizing flows in PyTorch
MIT License
845 stars 118 forks source link

AttributeError: module 'nflows' has no attribute 'utils' #7

Closed tuelwer closed 4 years ago

tuelwer commented 4 years ago

Hello,

first of all, thanks for sharing your toolbox!

However, I have a minor problem using it. When I try to import the masked autoregressive flow using from nflows.flows import autoregressive as ar, I get the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-b04b6f7320e6> in <module>()
----> 1 from nflows.flows import autoregressive as ar

5 frames
/usr/local/lib/python3.6/dist-packages/nflows/flows/__init__.py in <module>()
----> 1 from nflows.flows.autoregressive import MaskedAutoregressiveFlow
      2 from nflows.flows.base import Flow
      3 from nflows.flows.realnvp import SimpleRealNVP

/usr/local/lib/python3.6/dist-packages/nflows/flows/autoregressive.py in <module>()
      3 from torch.nn import functional as F
      4 
----> 5 from nflows.distributions.normal import StandardNormal
      6 from nflows.flows.base import Flow
      7 from nflows.transforms.autoregressive import MaskedAffineAutoregressiveTransform

/usr/local/lib/python3.6/dist-packages/nflows/distributions/__init__.py in <module>()
----> 1 from nflows.distributions.base import Distribution, NoMeanException
      2 from nflows.distributions.discrete import ConditionalIndependentBernoulli
      3 from nflows.distributions.mixture import MADEMoG
      4 from nflows.distributions.normal import (
      5     ConditionalDiagonalNormal,

/usr/local/lib/python3.6/dist-packages/nflows/distributions/base.py in <module>()
      4 from torch import nn
      5 
----> 6 from nflows.utils import torchutils
      7 import nflows.utils.typechecks as check
      8 

/usr/local/lib/python3.6/dist-packages/nflows/utils/__init__.py in <module>()
----> 1 from nflows.utils.torchutils import (
      2     cbrt,
      3     create_alternating_binary_mask,
      4     create_mid_split_binary_mask,
      5     create_random_binary_mask,

/usr/local/lib/python3.6/dist-packages/nflows/utils/torchutils.py in <module>()
      1 """Various PyTorch utility functions."""
      2 
----> 3 import nflows.utils.typechecks as check
      4 import numpy as np
      5 import torch

AttributeError: module 'nflows' has no attribute 'utils'

I am using Google Colab and installed the toolbox using !pip3 install nflows. Any help is appreciated. Thank you!

arturbekasov commented 4 years ago

Hello. As far as I can tell, this is due to Google Colab still being on Python 3.6. We're relying on a Python 3.7 feature for some of our imports, as it turns out.

I will look into fixing this, as we don't seem to use any other >=3.7 features, and supporting Colab is a good idea.

Meanwhile using Python 3.7 should do the trick, although it is either hard or impossible to do in Colab, from my quick research. It's a bit strange that they're still on 3.6, but oh well.

imurray commented 4 years ago

A bunch of other users will still have Python 3.6, e.g. those with Ubuntu LTS 18.04, or any distribution more than 2 years old. While it's not that hard to install another version as a user, it seems a bit early to insist on 3.7 unless it's a real pain to be compatible.

arturbekasov commented 4 years ago

I've pushed some code to fix this. from nflows.flows import autoregressive as ar works fine for me now in Python 3.6 (tested in Colab as well). For now you can use the following in Collab to get the latest code:

!pip install git+https://github.com/bayesiains/nflows@master

I think we'll release a new version after #8 is fixed (hopefully soon), and then !pip install nflows will work as expected.

Thanks for reporting, @tuelwer ! If you run into further problems -- do let us know.

tuelwer commented 4 years ago

Thanks for the fast fix, @arturbekasov! Works now without problems.