test: cover CP HiCache metadata validation edges
This commit is contained in:
@@ -53,13 +53,33 @@ class TestCpHiCacheNodeMetadata(CustomTestCase):
|
||||
def test_zero_owned_metadata_is_valid(self):
|
||||
metadata = CpHiCacheNodeMetadata(
|
||||
logical_len=64,
|
||||
owned_positions=torch.empty((0,), dtype=torch.int64),
|
||||
host_indices=torch.empty((0,), dtype=torch.int64),
|
||||
owned_positions=torch.empty((0,), dtype=torch.int32),
|
||||
host_indices=torch.empty((0,), dtype=torch.int32),
|
||||
)
|
||||
|
||||
self.assertEqual(metadata.logical_len, 64)
|
||||
self.assertEqual(metadata.owned_positions.device.type, "cpu")
|
||||
self.assertEqual(metadata.host_indices.device.type, "cpu")
|
||||
self.assertEqual(metadata.owned_positions.dtype, torch.int64)
|
||||
self.assertEqual(metadata.host_indices.dtype, torch.int64)
|
||||
|
||||
def test_non_int64_inputs_are_converted(self):
|
||||
metadata = CpHiCacheNodeMetadata(
|
||||
logical_len=4,
|
||||
owned_positions=torch.tensor([1, 3], dtype=torch.int32),
|
||||
host_indices=torch.tensor([10, 11], dtype=torch.int32),
|
||||
)
|
||||
|
||||
self.assertEqual(metadata.owned_positions.dtype, torch.int64)
|
||||
self.assertEqual(metadata.host_indices.dtype, torch.int64)
|
||||
|
||||
def test_negative_logical_len_raises(self):
|
||||
with self.assertRaisesRegex(ValueError, "logical_len"):
|
||||
CpHiCacheNodeMetadata(
|
||||
logical_len=-1,
|
||||
owned_positions=torch.empty((0,), dtype=torch.int64),
|
||||
host_indices=torch.empty((0,), dtype=torch.int64),
|
||||
)
|
||||
|
||||
def test_metadata_does_not_alias_input_tensors(self):
|
||||
owned_positions = torch.tensor([1, 3], dtype=torch.int64)
|
||||
|
||||
Reference in New Issue
Block a user