Skip to content

Commit 84c6285

Browse files
authored
Fix SetEncoder forward mask/partial handling
1 parent 0d23a42 commit 84c6285

1 file changed

Lines changed: 3 additions & 16 deletions

File tree

lightning_ir/models/cross_encoders/set_encoder.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,11 @@ def forward(self, encoding: BatchEncoding) -> CrossEncoderOutput:
130130
CrossEncoderOutput: Output of the model.
131131
"""
132132
num_docs = encoding.pop("num_docs", None)
133-
if num_docs is not None:
134-
attention_mask = encoding.get("attention_mask")
135-
if attention_mask is not None:
136-
device = attention_mask.device
137-
eye = (1 - torch.eye(self.config.depth, device=device)).long()
138-
if not self.config.sample_missing_docs:
139-
eye = eye[:, : max(num_docs)]
140-
other_doc_attention_mask = torch.cat([eye[:n] for n in num_docs])
141-
attention_mask = torch.cat(
142-
[attention_mask, other_doc_attention_mask.to(attention_mask)],
143-
dim=-1,
144-
)
145-
encoding["attention_mask"] = attention_mask
146-
147-
self.get_extended_attention_mask = partial(self.get_extended_attention_mask, num_docs=num_docs)
133+
134+
self.get_extended_attention_mask = partial(type(self).get_extended_attention_mask, self, num_docs=num_docs)
148135
for name, module in self.named_modules():
149136
if name.endswith(self.self_attention_pattern):
150-
module.forward = partial(self.attention_forward, self, module, num_docs=num_docs)
137+
module.forward = partial(type(self).attention_forward, self, module, num_docs=num_docs)
151138
return super().forward(encoding)
152139

153140
@staticmethod

0 commit comments

Comments
 (0)