AttributeError: 'NoneType' object has no attribute 'dim

Getting this error when running tabular runner with the below config on fastai 2

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_42/742899212.py in <module>
      3 #                            layers=  [36, 36, 64],
      4 #                            metrics=[[mae(),rmse(),error_rate])
----> 5 final_predictions_fastai = model_trainer("fastai",params,5)

/tmp/ipykernel_42/816397195.py in model_trainer(name, params, folds, _X, _Y, X_test_m, useful_features, metric)
     32                             layers=params['layers'], metrics=[mae,error_rate])
     33         print(tab_learn.model)
---> 34         tab_learn.lr_find()
     35         tab_learn.fit_one_cycle(params['cycle'] ,params['lr'], wd=0.2, cbs=[lr,es])
     36         #tab_learn.fit(params['cycle'] ,params['lr'], wd=0.2, cbs=[lr,es])

/opt/conda/lib/python3.7/site-packages/fastai/callback/schedule.py in lr_find(self, start_lr, end_lr, num_it, stop_div, show_plot, suggest_funcs)
    280     n_epoch = num_it//len(self.dls.train) + 1
    281     cb=LRFinder(start_lr=start_lr, end_lr=end_lr, num_it=num_it, stop_div=stop_div)
--> 282     with self.no_logging(): self.fit(n_epoch, cbs=cb)
    283     if suggest_funcs is not None:
    284         lrs, losses = tensor(self.recorder.lrs[num_it//10:-5]), tensor(self.recorder.losses[num_it//10:-5])

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in fit(self, n_epoch, lr, wd, cbs, reset_opt)
    219             self.opt.set_hypers(lr=self.lr if lr is None else lr)
    220             self.n_epoch = n_epoch
--> 221             self._with_events(self._do_fit, 'fit', CancelFitException, self._end_cleanup)
    222 
    223     def _end_cleanup(self): self.dl,self.xb,self.yb,self.pred,self.loss = None,(None,),(None,),None,None

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
    161 
    162     def _with_events(self, f, event_type, ex, final=noop):
--> 163         try: self(f'before_{event_type}');  f()
    164         except ex: self(f'after_cancel_{event_type}')
    165         self(f'after_{event_type}');  final()

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _do_fit(self)
    210         for epoch in range(self.n_epoch):
    211             self.epoch=epoch
--> 212             self._with_events(self._do_epoch, 'epoch', CancelEpochException)
    213 
    214     def fit(self, n_epoch, lr=None, wd=None, cbs=None, reset_opt=False):

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
    161 
    162     def _with_events(self, f, event_type, ex, final=noop):
--> 163         try: self(f'before_{event_type}');  f()
    164         except ex: self(f'after_cancel_{event_type}')
    165         self(f'after_{event_type}');  final()

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _do_epoch(self)
    204 
    205     def _do_epoch(self):
--> 206         self._do_epoch_train()
    207         self._do_epoch_validate()
    208 

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _do_epoch_train(self)
    196     def _do_epoch_train(self):
    197         self.dl = self.dls.train
--> 198         self._with_events(self.all_batches, 'train', CancelTrainException)
    199 
    200     def _do_epoch_validate(self, ds_idx=1, dl=None):

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
    161 
    162     def _with_events(self, f, event_type, ex, final=noop):
--> 163         try: self(f'before_{event_type}');  f()
    164         except ex: self(f'after_cancel_{event_type}')
    165         self(f'after_{event_type}');  final()

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in all_batches(self)
    167     def all_batches(self):
    168         self.n_iter = len(self.dl)
--> 169         for o in enumerate(self.dl): self.one_batch(*o)
    170 
    171     def _do_one_batch(self):

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in one_batch(self, i, b)
    192         b = self._set_device(b)
    193         self._split(b)
--> 194         self._with_events(self._do_one_batch, 'batch', CancelBatchException)
    195 
    196     def _do_epoch_train(self):

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
    161 
    162     def _with_events(self, f, event_type, ex, final=noop):
--> 163         try: self(f'before_{event_type}');  f()
    164         except ex: self(f'after_cancel_{event_type}')
    165         self(f'after_{event_type}');  final()

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _do_one_batch(self)
    170 
    171     def _do_one_batch(self):
--> 172         self.pred = self.model(*self.xb)
    173         self('after_pred')
    174         if len(self.yb):

/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
    725             result = self._slow_forward(*input, **kwargs)
    726         else:
--> 727             result = self.forward(*input, **kwargs)
    728         for hook in itertools.chain(
    729                 _global_forward_hooks.values(),

/opt/conda/lib/python3.7/site-packages/fastai/tabular/model.py in forward(self, x_cat, x_cont)
     51             x = self.emb_drop(x)
     52         if self.n_cont != 0:
---> 53             if self.bn_cont is not None: x_cont = self.bn_cont(x_cont)
     54             x = torch.cat([x, x_cont], 1) if self.n_emb != 0 else x_cont
     55         return self.layers(x)

/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
    725             result = self._slow_forward(*input, **kwargs)
    726         else:
--> 727             result = self.forward(*input, **kwargs)
    728         for hook in itertools.chain(
    729                 _global_forward_hooks.values(),

/opt/conda/lib/python3.7/site-packages/torch/nn/modules/batchnorm.py in forward(self, input)
     96 
     97     def forward(self, input: Tensor) -> Tensor:
---> 98         self._check_input_dim(input)
     99 
    100         # exponential_average_factor is set to self.momentum

/opt/conda/lib/python3.7/site-packages/torch/nn/modules/batchnorm.py in _check_input_dim(self, input)
    205 
    206     def _check_input_dim(self, input):
--> 207         if input.dim() != 2 and input.dim() != 3:
    208             raise ValueError('expected 2D or 3D input (got {}D input)'
    209                              .format(input.dim()))

Actual code being run

 nn_df = TabularDataLoaders.from_df(_X[useful_features], cat_names=cat_names,
                                           cont_names=cont_features,bs=BATCH_SIZE,
                              procs=processing_funcs, y_names=TARGET_VAR,
                              valid_idx=list(X_valid.index),
                              y_block = RegressionBlock())
        print(nn_df.cont_names)
        print(nn_df.cat_names)
        lr = ReduceLROnPlateau(monitor="valid_loss", factor=0.5, patience=10)
        es = EarlyStoppingCallback(monitor="valid_loss", patience=60)
        tab_learn = tabular_learner(nn_df, opt_func=Adam,loss_func=nn.L1Loss,#y_range=[0,0.99999999],
                            layers=params['layers'], metrics=[mae,error_rate])
        print(tab_learn.model)
        tab_learn.lr_find()
        tab_learn.fit(params['cycle'] ,params['lr'], wd=0.2, cbs=[lr,es])```

what are the actual values being feed to the model? What is inside this params dictionary?

{‘cycle’: 2, ‘n_layers’: 3, ‘layers’: [1024, 412, 256], ‘lr’: 0.005739346471274064, ‘n_units_layer_0’: 36, ‘dropout_p_layer_0’: 0.5, ‘n_units_layer_1’: 36, ‘dropout_p_layer_1’: 0.9, ‘n_units_layer_2’: 64, ‘dropout_p_layer_2’: 0.4} This is what the params look like … ignore some here .

Can you show the full stack trace? Looks like you’re missing the bottom part of it (which is important)

And are cat and cont_names both lists?

this is the output for cat names and cont names yes these are both lists .

{'cycle': 2, 'n_layers': 3, 'layers': [80, 412, 256], 'lr': 0.005739346471274064, 'n_units_layer_0': 36, 'dropout_p_layer_0': 0.5, 'n_units_layer_1': 36, 'dropout_p_layer_1': 0.9, 'n_units_layer_2': 64, 'dropout_p_layer_2': 0.4}
['time_step', 'u_in', 'u_out', 'area', 'u_in_cumsum', 'u_in_lag1', 'u_out_lag1', 'u_in_lag_back1', 'u_out_lag_back1', 'u_in_lag2', 'u_out_lag2', 'u_in_lag_back2', 'u_out_lag_back2', 'u_in_lag3', 'u_out_lag3', 'u_in_lag_back3', 'u_out_lag_back3', 'u_in_lag4', 'u_out_lag4', 'u_in_lag_back4', 'u_out_lag_back4', 'breath_id__u_in__max', 'breath_id__u_out__max', 'u_in_diff1', 'u_out_diff1', 'u_in_diff2', 'u_out_diff2', 'breath_id__u_in__diffmax', 'breath_id__u_in__diffmean', 'u_in_diff3', 'u_out_diff3', 'u_in_diff4', 'u_out_diff4', 'cross', 'cross2']
['R_20', 'R_5', 'R_50', 'C_10', 'C_20', 'C_50', 'R__C_20__10', 'R__C_20__20', 'R__C_20__50', 'R__C_50__10', 'R__C_50__20', 'R__C_50__50', 'R__C_5__10', 'R__C_5__20', 'R__C_5__50']

there is only one line I think I am missing as was running this on kaggle

/opt/conda/lib/python3.7/site-packages/torch/nn/modules/batchnorm.py in _check_input_dim(self, input)
    205 
    206     def _check_input_dim(self, input):
--> 207         if input.dim() != 2 and input.dim() != 3:
    208             raise ValueError('expected 2D or 3D input (got {}D input)'
    209                              .format(input.dim()))

AttributeError: 'NoneType' object has no attribute 'dim'
'NoneType' object has no attribute 'dim'

installed the latest via !pip install fastai -Uqq .