AttributeError: 'AutoformerModel' object has no attribute 'embedder'
Author: pourmatin
Pull request: no

### System Info

Darwin Kernel Version 22.4.0: Mon Mar  6 21:00:41 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T8103


### Who can help?

@ydshieh

### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [X] My own task or dataset (give details below)

### Reproduction

1. declare the model:
`config = AutoformerConfig()
config.prediction_length = 5
config.context_length = 55
config.lags_sequence = [1,2, 3, 4, 5]
model = AutoformerModel(config)`
2. invoke the forward method of the model by calling it:
`outputs = model(
    past_values=batches["past_values"][:16],
    past_time_features=batches["past_time_features"][:16],
    past_observed_mask=batches["past_observed_mask"][:16],
    static_categorical_features=batches["static_categorical_features"][:16],
    future_values=batches["future_values"][:16],
    future_time_features=batches["future_time_features"][:16],
)`


### Expected behavior

I'd expect the model to run forward method successfully. Instead, I get the following error:
```
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/var/folders/2n/p53ld4x51l1_yhdkj7q4y3t00000gr/T/ipykernel_49714/3104772270.py in <module>
----> 1 outputs = model(
      2     past_values=batches["past_values"][:16],
      3     past_time_features=batches["past_time_features"][:16],
      4     past_observed_mask=batches["past_observed_mask"][:16],
      5     static_categorical_features=batches["static_categorical_features"][:16],

~/opt/anaconda3/lib/python3.9/site-packages/torch/nn/modules/module.py in _call_impl(self, *args, **kwargs)
   1499                 or _global_backward_pre_hooks or _global_backward_hooks
   1500                 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1501             return forward_call(*args, **kwargs)
   1502         # Do not call functions when jit is used
   1503         full_backward_hooks, non_full_backward_hooks = [], []

~/opt/anaconda3/lib/python3.9/site-packages/transformers/models/autoformer/modeling_autoformer.py in forward(self, past_values, past_time_features, past_observed_mask, static_categorical_features, static_real_features, future_values, future_time_features, decoder_attention_mask, head_mask, decoder_head_mask, cross_attn_head_mask, encoder_outputs, past_key_values, output_hidden_states, output_attentions, use_cache, return_dict)
   1725         return_dict = return_dict if return_dict is not None else self.config.use_return_dict
   1726 
-> 1727         transformer_inputs, temporal_features, loc, scale, static_feat = self.create_network_inputs(
   1728             past_values=past_values,
   1729             past_time_features=past_time_features,

~/opt/anaconda3/lib/python3.9/site-packages/transformers/models/autoformer/modeling_autoformer.py in create_network_inputs(self, past_values, past_time_features, static_categorical_features, static_real_features, past_observed_mask, future_values, future_time_features)
   1637             static_feat = torch.cat((static_real_features, static_feat), dim=1)
   1638         if static_categorical_features is not None:
-> 1639             embedded_cat = self.embedder(static_categorical_features)
   1640             static_feat = torch.cat((embedded_cat, static_feat), dim=1)
   1641         expanded_static_feat = static_feat.unsqueeze(1).expand(-1, time_feat.shape[1], -1)

~/opt/anaconda3/lib/python3.9/site-packages/torch/nn/modules/module.py in __getattr__(self, name)
   1612             if name in modules:
   1613                 return modules[name]
-> 1614         raise AttributeError("'{}' object has no attribute '{}'".format(
   1615             type(self).__name__, name))
   1616 

AttributeError: 'AutoformerModel' object has no attribute 'embedder' 
```

Comments:
cc @kashif 

While waiting our expert @kashif , the code in 

```python
        if config.num_static_categorical_features > 0:
            self.embedder = AutoformerFeatureEmbedder(
                cardinalities=config.cardinality, embedding_dims=config.embedding_dimension
            )
```
together
```
        if static_categorical_features is not None:
            embedded_cat = self.embedder(static_categorical_features)
```

Since you pass `static_categorical_features` to the model's forward, you can check your config's `num_static_categorical_features ` attribute. Probably it is 0 and `self.embedder` is not created. In this case, I  think we should not pass `static_categorical_features` to the model.


thanks @ydshieh having a look!

@pourmatin that is correct, if you do not specify any categorical features, then you should not pass the model a list of categorical features... I believe we had a check for this, let me confirm!

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.