Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Attention mask being None crashes distillation #58

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion model2vec/distill/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ def create_output_embeddings_from_model_name(
for batch_idx in tqdm(range(0, len(stacked), _DEFAULT_BATCH_SIZE)):
batch = stacked[batch_idx : batch_idx + _DEFAULT_BATCH_SIZE].to(model.device)
with torch.no_grad():
encoded: BaseModelOutputWithPoolingAndCrossAttentions = model(input_ids=batch.to(device))
# NOTE: we create these masks because nomic embed requires them.
# Normally, we could set them to None
token_type_ids = torch.zeros_like(batch)
attention_mask = torch.ones_like(batch)
encoded: BaseModelOutputWithPoolingAndCrossAttentions = model(
input_ids=batch.to(device), attention_mask=attention_mask, token_type_ids=token_type_ids
)
out: torch.Tensor = encoded.last_hidden_state
# NOTE: If the dtype is bfloat 16, we convert to float32,
# because numpy does not suport bfloat16
Expand Down