-
Notifications
You must be signed in to change notification settings - Fork 283
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 decode float #203
base: main
Are you sure you want to change the base?
Fix decode float #203
Conversation
tensor = tensor.float() | ||
if reference.dtype == torch.long: | ||
reference = reference.float() | ||
test_passed = torch.allclose(tensor, reference, rtol=1/2 ** 15) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: Does this look strange? (to use rtol
with 1/2 ** 15)
I think this might also be changed to 1e-4
<-- this is the biggest power of 10 that we could use to "catch" the precision given by 2**16 (< 10^5)
crypten/encoder.py
Outdated
@@ -64,7 +64,7 @@ def decode(self, tensor): | |||
assert is_int_tensor(tensor), "input must be a LongTensor" | |||
if self._scale > 1: | |||
correction = (tensor < 0).long() | |||
dividend = tensor / self._scale - correction | |||
dividend = tensor // self._scale - correction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for noticing this. The definitions of truediv has been changed recently in PyTorch for the torch.long dtype. The previous behavior was identical to floordiv.
Summary: Pull Request resolved: fairinternal/CrypTen#203 - Modified crypten.load to allow the input `f` to be None. - Added assert to ensure exactly one of `f` or `preloaded` is None - Updated unit tests to ensure preloaded loads correctly. Reviewed By: knottb Differential Revision: D21212000 fbshipit-source-id: 82042e208a3a95328ec5472dba9ce964d8033075
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@knottb has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Types of changes
Use
true_div
when decoding a value - this would give "bad" values when decoding float encoded numbers.Ex:
fp.encode(4.6)
-->301465
-->fp.decode(301465)
-->4
Motivation and Context / Related issue
Correct decoding of float encoded values
How Has This Been Tested (if it applies)
Checklist