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

Kf/fix pytorch warnings #48

Merged
merged 4 commits into from
Oct 31, 2023
Merged

Kf/fix pytorch warnings #48

merged 4 commits into from
Oct 31, 2023

Conversation

KasperFyhn
Copy link
Contributor

Two warnings are triggered in the Multi2OIE code:

/home/au479461/PycharmProjects/conspiracies/src/conspiracies/docprocessing/relationextraction/multi2oie/other/bio.py:209: UserWarning: Creating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with numpy.array() before converting to a tensor. (Triggered internally at  ../torch/csrc/utils/tensor_new.cpp:210.)
  return [torch.Tensor(pred_tags) for pred_tags in total_pred_tags]
/home/au479461/PycharmProjects/conspiracies/src/conspiracies/docprocessing/relationextraction/multi2oie/other/bio.py:38: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
  return torch.tensor(res, dtype=torch.bool, device=tensor.device)

This PR addresses those two warnings.

  1. vstacks numpy arrays instead of lists in a loop and creates a tensor from the resulting array, as the warning suggests.
  2. Uses tensor.bool() to convert the original tensor straight into a boolean tensor that gets modified based on the contents of the original tensor, thereby skipping one tensor construction and avoiding the warning from the constructor.

@KasperFyhn KasperFyhn enabled auto-merge (squash) October 31, 2023 10:05
@KasperFyhn KasperFyhn disabled auto-merge October 31, 2023 10:05
@KennethEnevoldsen
Copy link
Contributor

Love these changes Kasper!

@KasperFyhn KasperFyhn enabled auto-merge (squash) October 31, 2023 10:21
@KasperFyhn KasperFyhn merged commit 761b533 into main Oct 31, 2023
5 checks passed
@KasperFyhn KasperFyhn deleted the kf/fix-pytorch-warnings branch October 31, 2023 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants