Skip to content

Commit

Permalink
[BugFix] Fix output of SipHash(as_tensor=False) (#2664)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtamohler authored Dec 18, 2024
1 parent 7bbd7e3 commit 1fc9577
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions test/test_storage_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ def test_sip_hash(self):
hash_b = torch.tensor(hash_module(b))
assert (hash_a == hash_b).all()

def test_sip_hash_nontensor(self):
a = torch.rand((3, 2))
b = a.clone()
hash_module = SipHash(as_tensor=False)
hash_a = hash_module(a)
hash_b = hash_module(b)
assert len(hash_a) == 3
assert hash_a == hash_b

@pytest.mark.parametrize("n_components", [None, 14])
@pytest.mark.parametrize("scale", [0.001, 0.01, 1, 100, 1000])
def test_randomprojection_hash(self, n_components, scale):
Expand Down
2 changes: 1 addition & 1 deletion torchrl/data/map/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor | List[bytes]:
hash_value = x_i.tobytes()
hash_values.append(hash_value)
if not self.as_tensor:
return hash_value
return hash_values
result = torch.tensor([hash(x) for x in hash_values], dtype=torch.int64)
return result

Expand Down

1 comment on commit 1fc9577

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'CPU Benchmark Results'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 1fc9577 Previous: 7bbd7e3 Ratio
benchmarks/test_replaybuffer_benchmark.py::test_rb_populate[TensorDictReplayBuffer-ListStorage-SamplerWithoutReplacement-400] 37.70801490676322 iter/sec (stddev: 0.15547523238960334) 213.04788870444077 iter/sec (stddev: 0.001039962217437747) 5.65

This comment was automatically generated by workflow using github-action-benchmark.

CC: @vmoens

Please sign in to comment.