# \[Error about InformerForPredict\]\[Bug\]

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ferror-about-informerforpredict-bug%2F158873%3E%5C
**Category:** 🤗Transformers\
**Created:** [June 11, 2025, 7:19am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ferror-about-informerforpredict-bug%2F158873 "2025-06-11T07:19:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![2004learner](https://avatars.discourse-cdn.com/v4/letter/2/6a8cbe/32.png) [@2004learner](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2F2004learner)%5C
**Post date:** [June 11, 2025, 7:19am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ferror-about-informerforpredict-bug%2F158873%2F1 "2025-06-11T07:19:09Z")

</div>

When I set the infomerconfig.input\_size = 1, I find a bug, but I don’t know how to fix it.

- Function Name : `create_network_inputs`

```auto
time_feat = (
            torch.cat(
                (
                    past_time_features[:, self._past_length - self.config.context_length :, ...],
                    future_time_features,
                ),
                dim=1,
            )
            if future_values is not None
            else past_time_features[:, self._past_length - self.config.context_length :, ...]
        )

        print(self._past_length)
        # target
        if past_observed_mask is None:
            past_observed_mask = torch.ones_like(past_values)

        context = past_values[:, -self.config.context_length :]
        observed_context = past_observed_mask[:, -self.config.context_length :]
        _, loc, scale = self.scaler(context, observed_context)

        inputs = (
            (torch.cat((past_values, future_values), dim=1) - loc) / scale
            if future_values is not None
            else (past_values - loc) / scale
        )
        print(loc.shape, scale.shape, inputs.shape)

        # static features
        log_abs_loc = loc.abs().log1p() if self.config.input_size == 1 else loc.squeeze(1).abs().log1p()
        log_scale = scale.log() if self.config.input_size == 1 else scale.squeeze(1).log()
        print(f"log_abs_loc: {log_abs_loc.shape}, {log_scale.shape}")
        print(time_feat.shape, self.config.input_size)
        static_feat = torch.cat((log_abs_loc, log_scale), dim=1)
        print(time_feat.shape, static_feat.shape)
        if static_real_features is not None:
            static_feat = torch.cat((static_real_features, static_feat), dim=1)
        if static_categorical_features is not None:
            embedded_cat = self.embedder(static_categorical_features)
            static_feat = torch.cat((embedded_cat, static_feat), dim=1)
        print(time_feat.shape, static_feat.shape)
        expanded_static_feat = static_feat.unsqueeze(1).expand(-1, time_feat.shape[1], -1)

        # all features
        features = torch.cat((expanded_static_feat, time_feat), dim=-1)

        # lagged features
        subsequences_length = (
            self.config.context_length + self.config.prediction_length
            if future_values is not None
            else self.config.context_length
        )
        lagged_sequence = self.get_lagged_subsequences(sequence=inputs, subsequences_length=subsequences_length)
        lags_shape = lagged_sequence.shape
        reshaped_lagged_sequence = lagged_sequence.reshape(lags_shape[0], lags_shape[1], -1)

        if reshaped_lagged_sequence.shape[1] != time_feat.shape[1]:
            raise ValueError(
                f"input length {reshaped_lagged_sequence.shape[1]} and time feature lengths {time_feat.shape[1]} does not match"
            )

        # transformer inputs
        transformer_inputs = torch.cat((reshaped_lagged_sequence, features), dim=-1)

        return transformer_inputs, loc, scale, static_feat

```

As we can see, I add some `print` sentence in the library to see the shape, now the bug is:

```auto
Traceback (most recent call last):
  File "/home/wjt/luck/FinalWork/alert_models/informer_based_model_3_cpu.py", line 820, in <module>
    pipline.train_model()
  File "/home/wjt/luck/FinalWork/alert_models/informer_based_model_3_cpu.py", line 466, in train_model
    outputs = model(
  File "/home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages/transformers/models/informer/modeling_informer.py", line 1844, in forward
    outputs = self.model(
  File "/home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages/transformers/models/informer/modeling_informer.py", line 1568, in forward
    transformer_inputs, loc, scale, static_feat = self.create_network_inputs(
  File "/home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages/transformers/models/informer/modeling_informer.py", line 1386, in create_network_inputs
    expanded_static_feat = static_feat.unsqueeze(1).expand(-1, time_feat.shape[1], -1)
RuntimeError: expand(torch.cuda.FloatTensor{[32, 1, 2, 1]}, size=[-1, 27, -1]): the number of sizes provided (3) must be greater or equal to the number of dimensions in the tensor (4)

```

- First

```auto
log_abs_loc = loc.abs().log1p() if self.config.input_size == 1 else loc.squeeze(1).abs().log1p() log_scale = scale.log() if self.config.input_size == 1 else scale.squeeze(1).log()

```

If the input\_size is 1, `loc.squeeze` will not execute, but now the loc.shape is `(bsz, 1, 1)`, so it will be a hidden issue, and

- second

```auto
static_feat.unsqueeze(1) will execute, then the error will be reported

```

I don’t know whether it’s clear to clarify the problem, but I really need a help.

- environment

```auto
Name: transformers
Version: 4.52.3
Summary: State-of-the-art Machine Learning for JAX, PyTorch and TensorFlow
Home-page: https://github.com/huggingface/transformers
Author: The Hugging Face team (past and future) with the help of all our contributors (https://github.com/huggingface/transformers/graphs/contributors)
Author-email: transformers@huggingface.co
License: Apache 2.0 License
Location: /home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages
Requires: filelock, huggingface-hub, numpy, pack

Linux

python3.9.21

```

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [June 11, 2025, 10:19am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ferror-about-informerforpredict-bug%2F158873%2F2 "2025-06-11T10:19:21Z")

</div>

It looks like you have a reply.

> <https://github.com/huggingface/transformers/issues/38745#issuecomment-2962007715>
>
> \### System Info
> 
> When I set the infomerconfig.input\_size = 1, I find a bug, but …I don't know how to fix it.
> 
> \- Function Name : \`create\_network\_inputs\`
> \`\`\`
> time\_feat = (
> torch.cat(
> (
> past\_time\_features\[:, self.\_past\_length - self.config.context\_length :, ...\],
> future\_time\_features,
> ),
> dim=1,
> )
> if future\_values is not None
> else past\_time\_features\[:, self.\_past\_length - self.config.context\_length :, ...\]
> )
> 
> print(self.\_past\_length)
> # target
> if past\_observed\_mask is None:
> past\_observed\_mask = torch.ones\_like(past\_values)
> 
> context = past\_values\[:, -self.config.context\_length :\]
> observed\_context = past\_observed\_mask\[:, -self.config.context\_length :\]
> \_, loc, scale = self.scaler(context, observed\_context)
> 
> inputs = (
> (torch.cat((past\_values, future\_values), dim=1) - loc) / scale
> if future\_values is not None
> else (past\_values - loc) / scale
> )
> print(loc.shape, scale.shape, inputs.shape)
> 
> # static features
> log\_abs\_loc = loc.abs().log1p() if self.config.input\_size == 1 else loc.squeeze(1).abs().log1p()
> log\_scale = scale.log() if self.config.input\_size == 1 else scale.squeeze(1).log()
> print(f"log\_abs\_loc: {log\_abs\_loc.shape}, {log\_scale.shape}")
> print(time\_feat.shape, self.config.input\_size)
> static\_feat = torch.cat((log\_abs\_loc, log\_scale), dim=1)
> print(time\_feat.shape, static\_feat.shape)
> if static\_real\_features is not None:
> static\_feat = torch.cat((static\_real\_features, static\_feat), dim=1)
> if static\_categorical\_features is not None:
> embedded\_cat = self.embedder(static\_categorical\_features)
> static\_feat = torch.cat((embedded\_cat, static\_feat), dim=1)
> print(time\_feat.shape, static\_feat.shape)
> expanded\_static\_feat = static\_feat.unsqueeze(1).expand(-1, time\_feat.shape\[1\], -1)
> 
> # all features
> features = torch.cat((expanded\_static\_feat, time\_feat), dim=-1)
> 
> # lagged features
> subsequences\_length = (
> self.config.context\_length + self.config.prediction\_length
> if future\_values is not None
> else self.config.context\_length
> )
> lagged\_sequence = self.get\_lagged\_subsequences(sequence=inputs, subsequences\_length=subsequences\_length)
> lags\_shape = lagged\_sequence.shape
> reshaped\_lagged\_sequence = lagged\_sequence.reshape(lags\_shape\[0\], lags\_shape\[1\], -1)
> 
> if reshaped\_lagged\_sequence.shape\[1\] != time\_feat.shape\[1\]:
> raise ValueError(
> f"input length {reshaped\_lagged\_sequence.shape\[1\]} and time feature lengths {time\_feat.shape\[1\]} does not match"
> )
> 
> # transformer inputs
> transformer\_inputs = torch.cat((reshaped\_lagged\_sequence, features), dim=-1)
> 
> return transformer\_inputs, loc, scale, static\_feat
> \`\`\`
> 
> As we can see, I add some \`print\` sentence in the library to see the shape, now the bug is:
> \`\`\`
> Traceback (most recent call last):
> File "/home/wjt/luck/FinalWork/alert\_models/informer\_based\_model\_3\_cpu.py", line 820, in \<module\>
> pipline.train\_model()
> File "/home/wjt/luck/FinalWork/alert\_models/informer\_based\_model\_3\_cpu.py", line 466, in train\_model
> outputs = model(
> File "/home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1751, in \_wrapped\_call\_impl
> return self.\_call\_impl(\*args, \*\*kwargs)
> File "/home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1762, in \_call\_impl
> return forward\_call(\*args, \*\*kwargs)
> File "/home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages/transformers/models/informer/modeling\_informer.py", line 1844, in forward
> outputs = self.model(
> File "/home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1751, in \_wrapped\_call\_impl
> return self.\_call\_impl(\*args, \*\*kwargs)
> File "/home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1762, in \_call\_impl
> return forward\_call(\*args, \*\*kwargs)
> File "/home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages/transformers/models/informer/modeling\_informer.py", line 1568, in forward
> transformer\_inputs, loc, scale, static\_feat = self.create\_network\_inputs(
> File "/home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages/transformers/models/informer/modeling\_informer.py", line 1386, in create\_network\_inputs
> expanded\_static\_feat = static\_feat.unsqueeze(1).expand(-1, time\_feat.shape\[1\], -1)
> RuntimeError: expand(torch.cuda.FloatTensor{\[32, 1, 2, 1\]}, size=\[-1, 27, -1\]): the number of sizes provided (3) must be greater or equal to the number of dimensions in the tensor (4)
> \`\`\`
> \- First
> \`\`\`
> log\_abs\_loc = loc.abs().log1p() if self.config.input\_size == 1 else loc.squeeze(1).abs().log1p() log\_scale = scale.log() if self.config.input\_size == 1 else scale.squeeze(1).log()
> \`\`\`
> If the input\_size is 1, \`loc.squeeze\` will not execute, but now the loc.shape is \`(bsz, 1, 1)\`, so it will be a hidden issue, and 
> 
> \- second
> \`\`\`
> static\_feat.unsqueeze(1) will execute, then the error will be reported
> \`\`\`
> 
> I don't know whether it's clear to clarify the problem, but I really need a help.
> 
> \- environment
> \`\`\`
> Name: transformers
> Version: 4.52.3
> Summary: State-of-the-art Machine Learning for JAX, PyTorch and TensorFlow
> Home-page: https://github.com/huggingface/transformers
> Author: The Hugging Face team (past and future) with the help of all our contributors (https://github.com/huggingface/transformers/graphs/contributors)
> Author-email: transformers@huggingface.co
> License: Apache 2.0 License
> Location: /home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages
> Requires: filelock, huggingface-hub, numpy, pack
> 
> Linux
> 
> python3.9.21
> \`\`\`
> 
> 
> 
> \### Who can help?
> 
> \_No response\_
> 
> \### Information
> 
> \- \[\] The official example scripts
> \- \[\] My own modified scripts
> 
> \### Tasks
> 
> \- \[\] An officially supported task in the \`examples\` folder (such as GLUE/SQuAD, ...)
> \- \[\] My own task or dataset (give details below)
> 
> \### Reproduction
> 
> 1. set the InformerConfig.size = 1
> 2. maybe do not include any other static features
> 3. maybe InformerConfig.scale = None
> 
> 
> \### Expected behavior
> 
> Traceback (most recent call last):
> File "/home/wjt/luck/FinalWork/alert\_models/informer\_based\_model\_3\_cpu.py", line 820, in \<module\>
> pipline.train\_model()
> File "/home/wjt/luck/FinalWork/alert\_models/informer\_based\_model\_3\_cpu.py", line 466, in train\_model
> outputs = model(
> File "/home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1751, in \_wrapped\_call\_impl
> return self.\_call\_impl(\*args, \*\*kwargs)
> File "/home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1762, in \_call\_impl
> return forward\_call(\*args, \*\*kwargs)
> File "/home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages/transformers/models/informer/modeling\_informer.py", line 1844, in forward
> outputs = self.model(
> File "/home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1751, in \_wrapped\_call\_impl
> return self.\_call\_impl(\*args, \*\*kwargs)
> File "/home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1762, in \_call\_impl
> return forward\_call(\*args, \*\*kwargs)
> File "/home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages/transformers/models/informer/modeling\_informer.py", line 1568, in forward
> transformer\_inputs, loc, scale, static\_feat = self.create\_network\_inputs(
> File "/home/wjt/.conda/envs/luckluck/lib/python3.9/site-packages/transformers/models/informer/modeling\_informer.py", line 1386, in create\_network\_inputs
> expanded\_static\_feat = static\_feat.unsqueeze(1).expand(-1, time\_feat.shape\[1\], -1)
> RuntimeError: expand(torch.cuda.FloatTensor{\[32, 1, 2, 1\]}, size=\[-1, 27, -1\]): the number of sizes provided (3) must be greater or equal to the number of dimensions in the tensor (4)
