fastai / fastai_dev

fast.ai early development experiments
Apache License 2.0
638 stars 350 forks source link

Possible regression when declaring a SequentialRNN #283

Closed tacchinotacchi closed 4 years ago

tacchinotacchi commented 4 years ago

I'm running this code

import fastai2.text.models as models

config = models.awd_lstm_clas_config.copy()
update = {
    "emb_sz": 300,
    "n_layers": 1,
    "bidir": True,
}
config.update(update)
model = models.get_text_classifier(models.AWD_LSTM, len(vocab), 2, config=config, lin_ftrs=[400])

It works fine at commit https://github.com/fastai/fastai_dev/commit/03e59c4e29e687adc29ae8619d59ea96e8f9fde7, but I get this error on master:

I'm getting this error while in models.get_text_classifier:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-5-faed1ecbfc39> in <module>
     20 config.update(update)
     21 
---> 22 model = models.get_text_classifier(models.AWD_LSTM, len(vocab), 2, config=config, lin_ftrs=[400])

~/Documents/fastai_dev/fastai2/text/models/core.py in get_text_classifier(arch, vocab_sz, n_class, bptt, config, drop_mult, lin_ftrs, ps, pad_idx)
    129     init = config.pop('init') if 'init' in config else None
    130     encoder = SentenceEncoder(bptt, arch(vocab_sz, **config), pad_idx=pad_idx)
--> 131     model = SequentialRNN(encoder, PoolingLinearClassifier(layers, ps))
    132     return model if init is None else model.apply(init)

~/Documents/fastai_dev/fastai2/core/foundation.py in __call__(cls, *args, **kwargs)
     28         if type(res)==cls:
     29             if hasattr(res,'__pre_init__'): res.__pre_init__(*args,**kwargs)
---> 30             res.__init__(*args,**kwargs)
     31             if hasattr(res,'__post_init__'): res.__post_init__(*args,**kwargs)
     32         return res

~/Documents/fastai_dev/fastai2/text/models/core.py in __init__(self, dims, ps)
    106         if len(ps) != len(dims)-1: raise ValueError("Number of layers and dropout values do not match.")
    107         acts = [nn.ReLU(inplace=True)] * (len(dims) - 2) + [None]
--> 108         layers = [BnDropLin(i, o, p=p, act=a) for i,o,p,a in zip(dims[:-1], dims[1:], ps, acts)]
    109         self.layers = nn.Sequential(*layers)
    110 

~/Documents/fastai_dev/fastai2/text/models/core.py in <listcomp>(.0)
    106         if len(ps) != len(dims)-1: raise ValueError("Number of layers and dropout values do not match.")
    107         acts = [nn.ReLU(inplace=True)] * (len(dims) - 2) + [None]
--> 108         layers = [BnDropLin(i, o, p=p, act=a) for i,o,p,a in zip(dims[:-1], dims[1:], ps, acts)]
    109         self.layers = nn.Sequential(*layers)
    110 

NameError: name 'BnDropLin' is not defined

EDIT: my bad, I was pulling from my own fork instead of this repo and I missed the fix