@@ -207,15 +207,15 @@ def mask_token_id(self) -> int:
207207 @torch .compiler .disable
208208 def _create_attention_mask (
209209 self ,
210- lengths : torch .Tensor ,
210+ document_ids : torch .Tensor ,
211211 total_seq_len : int ,
212212 anchor_positions : torch .Tensor ,
213213 device : torch .device ,
214214 sliding_window : int | None = None ,
215215 sliding_window_non_causal : bool = False ,
216216 ):
217217 mask_mod , q_len , kv_len = create_anchor_block_mask_mod (
218- lengths = lengths .to (device ),
218+ document_ids = document_ids . squeeze ( 0 ) .to (device ),
219219 total_seq_len = total_seq_len ,
220220 anchor_positions = anchor_positions ,
221221 block_size = self .block_size ,
@@ -232,7 +232,7 @@ def _create_attention_mask(
232232 )
233233
234234 @torch .compiler .disable
235- def _build_attention_mask (self , loss_mask , lengths , device ):
235+ def _build_attention_mask (self , loss_mask , document_ids , device ):
236236 total_seq_len = loss_mask .shape [1 ]
237237
238238 anchor_positions , anchor_valid = select_anchors (
@@ -242,7 +242,7 @@ def _build_attention_mask(self, loss_mask, lengths, device):
242242 full_attn_mask = None
243243 if self .uses_full_attn :
244244 full_attn_mask = self ._create_attention_mask (
245- lengths = lengths ,
245+ document_ids = document_ids ,
246246 total_seq_len = total_seq_len ,
247247 anchor_positions = anchor_positions ,
248248 device = device ,
@@ -252,7 +252,7 @@ def _build_attention_mask(self, loss_mask, lengths, device):
252252 sliding_window_attn_mask = None
253253 if self .uses_sliding_window_attn :
254254 sliding_window_attn_mask = self ._create_attention_mask (
255- lengths = lengths ,
255+ document_ids = document_ids ,
256256 total_seq_len = total_seq_len ,
257257 anchor_positions = anchor_positions ,
258258 device = device ,
@@ -269,7 +269,7 @@ def forward(
269269 input_ids : torch .Tensor , # shape: [1, total_seq_len]
270270 loss_mask : torch .Tensor , # shape: [1, total_seq_len]
271271 verifier_last_hidden_states : torch .Tensor , # shape: [1, total_seq_len, hidden_size] # noqa: E501
272- lengths : torch .Tensor | None = None , # shape: [batch_size ]
272+ document_ids : torch .Tensor , # shape: [1, total_seq_len ]
273273 position_ids : torch .Tensor | None = None , # shape: [1, total_seq_len]
274274 loss_fn = kl_div_loss ,
275275 ** kwargs ,
@@ -278,15 +278,13 @@ def forward(
278278 total_seq_len = hidden_states .shape [1 ]
279279 num_anchors = self .config .max_anchors
280280
281- if lengths is None :
282- lengths = torch .tensor ([total_seq_len ], dtype = torch .long , device = device )
283281 if position_ids is None :
284282 position_ids = 1 + torch .arange (
285283 total_seq_len , dtype = torch .long , device = device
286284 ).unsqueeze (0 )
287285
288286 full_attn_mask , sliding_window_attn_mask , anchor_positions , anchor_valid = (
289- self ._build_attention_mask (loss_mask , lengths , device )
287+ self ._build_attention_mask (loss_mask , document_ids , device )
290288 )
291289
292290 mask_tokens_size = num_anchors * self .block_size
0 commit comments