Issues replicating time series analysis with Transformers

I am trying to replicate one-to-one the univariate time series analysis using the vanilla Transformer provided in this notebook:

I am using Jupyter notebook in VS Code, Python 3.10.9 and Jupyter 6.5.4 in a virtual environment.

Everything runs smoothly until the forward pass, where I get the following error (full traceback):

Traceback (most recent call last)
/var/folders/vq/0s913kg97lv155_r9j2g9qxm0000gn/T/ipykernel_63681/2795771002.py:2 in

[Errno 2] No such file or directory:
‘/var/folders/vq/0s913kg97lv155_r9j2g9qxm0000gn/T/ipykernel_63681/2795771002.py’

/opt/homebrew/lib/python3.10/site-packages/torch/nn/modules/module.py:1190 in _call_impl

│ 1187 │ │ # this function, and just call forward. │
│ 1188 │ │ if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks o │
│ 1189 │ │ │ │ or _global_forward_hooks or _global_forward_pre_hooks): │
│ ❱ 1190 │ │ │ return forward_call(*input, **kwargs) │
│ 1191 │ │ # Do not call functions when jit is used │
│ 1192 │ │ full_backward_hooks, non_full_backward_hooks = ,
│ 1193 │ │ if self._backward_hooks or global_backward_hooks: │
│ │
│ /opt/homebrew/lib/python3.10/site-packages/transformers/models/time_series_transformer/modeling

│ time_series_transformer.py:1813 in forward │
│ │
│ 1810 │ │ if future_values is not None: │
│ 1811 │ │ │ use_cache = False │
│ 1812 │ │ │
│ ❱ 1813 │ │ outputs = self.model( │
│ 1814 │ │ │ past_values=past_values, │
│ 1815 │ │ │ past_time_features=past_time_features, │
│ 1816 │ │ │ past_observed_mask=past_observed_mask, │
│ │
│ /opt/homebrew/lib/python3.10/site-packages/torch/nn/modules/module.py:1190 in _call_impl │
│ │
│ 1187 │ │ # this function, and just call forward. │
│ 1188 │ │ if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks o │
│ 1189 │ │ │ │ or _global_forward_hooks or _global_forward_pre_hooks): │
│ ❱ 1190 │ │ │ return forward_call(*input, **kwargs) │
│ 1191 │ │ # Do not call functions when jit is used │
│ 1192 │ │ full_backward_hooks, non_full_backward_hooks = ,
│ 1193 │ │ if self.backward_hooks or global_backward_hooks: │
│ │
│ /opt/homebrew/lib/python3.10/site-packages/transformers/models/time_series_transformer/modeling

│ time_series_transformer.py:1626 in forward │
│ │
│ 1623 │ │ use_cache = use_cache if use_cache is not None else self.config.use_cache │
│ 1624 │ │ return_dict = return_dict if return_dict is not None else self.config.use_return │
│ 1625 │ │ │
│ ❱ 1626 │ │ transformer_inputs, scale, static_feat = self.create_network_inputs( │
│ 1627 │ │ │ past_values=past_values, │
│ 1628 │ │ │ past_time_features=past_time_features, │
│ 1629 │ │ │ past_observed_mask=past_observed_mask, │
│ │
│ /opt/homebrew/lib/python3.10/site-packages/transformers/models/time_series_transformer/modeling

│ time_series_transformer.py:1535 in create_network_inputs │
│ │
│ 1532 │ │ embedded_cat = self.embedder(static_categorical_features) │
│ 1533 │ │ # static features │
│ 1534 │ │ log_scale = scale.log() if self.config.input_size == 1 else scale.squeeze(1).log │
│ ❱ 1535 │ │ static_feat = torch.cat((embedded_cat, static_real_features, log_scale), dim=1) │
│ 1536 │ │ expanded_static_feat = static_feat.unsqueeze(1).expand(-1, time_feat.shape[1], - │
│ 1537 │ │ │
│ 1538 │ │ # all features │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: expected Tensor as element 1 in argument 0, but got NoneType

I am fairly new to Transformers (and Python in general) but I suspect the issue lies in relation to the error:

[Errno 2] No such file or directory:
‘/var/folders/vq/0s913kg97lv155_r9j2g9qxm0000gn/T/ipykernel_63681/2795771002.py’

I checked the directory, and indeed no such file exists. I tried upgrading ipykernel without success. There seems to be no issues loading all required libraries in their newest versions.

Any suggestions as to what the issue might be?

I found the error for any other user who might run into this issue:
Follow the documentation on Installation and remember to brew install cmake and pkg-config when running on an M1 :smile: