Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Warn user against using torch tensors as arguments of random variables #1639

Conversation

AishwaryaSivaraman
Copy link
Contributor

Summary:
Bean Machine uses the hash value of the arguments of random variables to identify them, which means that foo(1) and foo(tensor(1)) are considered two different random variables. Further in PyTorch, tensors are hashed by memory address instead of by value, so we can have hash(tensor(1)) != hash(tensor(1)). Therefore, it’s not recommended to use tensors as indices of random variables.
In this change,

  1. In rv_identifier.py we identify if tensors are used as arguments to RVs and warn the user against its use.
  2. Added a test case to rv_identifier_test.py to check if the warning is triggered correctly when the user provides a tensor instead of a primitive argument.

Differential Revision: D39169577

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported labels Aug 31, 2022
@facebook-github-bot
Copy link
Collaborator

This pull request was exported from Phabricator. Differential Revision: D39169577

AishwaryaSivaraman added a commit to AishwaryaSivaraman/beanmachine that referenced this pull request Aug 31, 2022
facebookresearch#1639)

Summary:
Pull Request resolved: facebookresearch#1639

Bean Machine uses the hash value of the arguments of random variables to identify them, which means that foo(1) and foo(tensor(1)) are considered two different random variables. Further in PyTorch, tensors are hashed by memory address instead of by value, so we can have hash(tensor(1)) != hash(tensor(1)). Therefore, it’s not recommended to use tensors as indices of random variables.
In this change,
1. In `rv_identifier.py` we identify if tensors are used as arguments to RVs and warn the user against its use.
2. Added a test case to `rv_identifier_test.py` to check if the warning is triggered correctly when the user provides a tensor instead of a primitive argument.

Differential Revision: D39169577

fbshipit-source-id: 487719d5fd66de2936e7e1f6d8885f6edb5498ac
@facebook-github-bot
Copy link
Collaborator

This pull request was exported from Phabricator. Differential Revision: D39169577

facebookresearch#1639)

Summary:
Pull Request resolved: facebookresearch#1639

Bean Machine uses the hash value of the arguments of random variables to identify them, which means that foo(1) and foo(tensor(1)) are considered two different random variables. Further in PyTorch, tensors are hashed by memory address instead of by value, so we can have hash(tensor(1)) != hash(tensor(1)). Therefore, it’s not recommended to use tensors as indices of random variables.
In this change,
1. In `rv_identifier.py` we identify if tensors are used as arguments to RVs and warn the user against its use.
2. Added a test case to `rv_identifier_test.py` to check if the warning is triggered correctly when the user provides a tensor instead of a primitive argument.

Differential Revision: D39169577

fbshipit-source-id: 927af335f605cfc12fae6f3a6ca7784122579559
@facebook-github-bot
Copy link
Collaborator

This pull request was exported from Phabricator. Differential Revision: D39169577

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants