Skip to content

fix attn_mask not updated error for informer model - #49038

Closed
kaixuanliu wants to merge 4 commits into
huggingface:mainfrom
kaixuanliu:informer-fix
Closed

kaixuanliu wants to merge 4 commits into
huggingface:mainfrom
kaixuanliu:informer-fix

Conversation

@kaixuanliu

@kaixuanliu kaixuanliu commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

CPU CI GPU run-slow

Fix Informer encoder attention-mask handling when distillation is enabled.

The distillation convolution halves the encoder sequence length, but the attention mask previously retained its original length, causing a shape mismatch in later encoder layers under torch.compile.

The mask is now downsampled with the same pooling configuration as InformerConvLayer.maxPool and rebuilt after every distillation step. pls help review, thx! @zucchini-nlp

Signed-off-by: kaixuanliu <kaixuan.liu@intel.com>
Signed-off-by: kaixuanliu <kaixuan.liu@intel.com>
Signed-off-by: kaixuanliu <kaixuan.liu@intel.com>
Comment on lines +835 to 838
# Keep the 2D padding mask around: the distillation conv layers halve the sequence length,
# so the attention mask has to be downsampled together with the hidden states.
padding_mask = attention_mask if attention_mask is None or attention_mask.dim() == 2 else None
attention_mask = create_bidirectional_mask(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

padding_mask = attention_mask if attention_mask is not None and attention_mask.dim() == 2 else None maybe so we keep only 2D masks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment on lines +228 to +245
def test_distillation_updates_encoder_attention_mask(self):
config, inputs_dict = self.model_tester.prepare_config_and_inputs()
config.distil = True
model = InformerModel(config).to(torch_device).eval()

transformer_inputs, _, _, _ = model.create_network_inputs(**inputs_dict)
encoder_inputs = transformer_inputs[:, : config.context_length]
attention_mask = torch.ones(encoder_inputs.shape[:2], device=torch_device, dtype=torch.long)

with torch.no_grad():
outputs = model.encoder(inputs_embeds=encoder_inputs, attention_mask=attention_mask)

expected_sequence_length = (config.context_length + 1) // 2
self.assertEqual(
outputs.last_hidden_state.shape[:2],
(self.model_tester.batch_size, expected_sequence_length),
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, it would have failed loud with shape mismatch - do we have no tests with ConvLayers ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems no...

Signed-off-by: kaixuanliu <kaixuan.liu@intel.com>
@github-actions

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: informer

@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 35830976674:2
Result: success | Jobs: 4 | Tests: 285 | Failures: 0 | Duration: 2m 53s

@zucchini-nlp

Copy link
Copy Markdown
Member

Sorry, forgot to reply. Seems like the slow CI ckpt has distil=True saved and the slow tests are all green on main. TBH i am not following why it would fail in your use-case unless the inputs are being passed wrong or smth like that

If it's just poor docs for old model, i'd say we don't need a fix, so could you verify it

@kaixuanliu

Copy link
Copy Markdown
Contributor Author

@zucchini-nlp , well I checked it through carefully again, it should be the same root cause as what is solved in #48975 , under compile mode the mask was wrongly created and lead to the error. After the fix the bug is gone, can close this PR now.

@kaixuanliu kaixuanliu closed this Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants