**Learning:** When checking if rows in an attention mask are entirely zero during a pooling operation, if the target pooling index (like `last_token_indices`) is already computed, using an O(1) boolean lookup at that index (e.g., `attention_mask[batch_indices, last_token_indices] != 0`) is significantly faster than using an O(N) scan across the entire row (e.g., `attention_mask.any(axis=1)`). If the `last_token_index` holds a valid padding index, checking its exact value verifies if any valid tokens existed in the row.
0 commit comments