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: convert bfloat16 to float because of numpy incompatibility #53

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions model2vec/distill/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@
with torch.no_grad():
encoded: BaseModelOutputWithPoolingAndCrossAttentions = model(input_ids=batch.to(device))
out: torch.Tensor = encoded.last_hidden_state
# NOTE: If the dtype is bfloat 16, we convert to float32,
# because numpy does not suport bfloat16
# See here: https://github.com/numpy/numpy/issues/19808
if out.dtype == torch.bfloat16:
out = out.float()

Check warning on line 131 in model2vec/distill/inference.py

View check run for this annotation

Codecov / codecov/patch

model2vec/distill/inference.py#L131

Added line #L131 was not covered by tests
intermediate_weights.append(out[:, 1].cpu().numpy())
out_weights = np.concatenate(intermediate_weights)

Expand Down