test: harden CP HiCache metadata invariants
This commit is contained in:
@@ -64,8 +64,12 @@ class CpHiCacheNodeMetadata:
|
||||
def __post_init__(self):
|
||||
if self.logical_len < 0:
|
||||
raise ValueError(f"logical_len must be non-negative, got {self.logical_len}")
|
||||
self.owned_positions = self.owned_positions.to(device="cpu", dtype=torch.int64)
|
||||
self.host_indices = self.host_indices.to(device="cpu", dtype=torch.int64)
|
||||
self.owned_positions = self.owned_positions.to(
|
||||
device="cpu", dtype=torch.int64
|
||||
).detach().clone()
|
||||
self.host_indices = self.host_indices.to(
|
||||
device="cpu", dtype=torch.int64
|
||||
).detach().clone()
|
||||
if self.owned_positions.numel() != self.host_indices.numel():
|
||||
raise ValueError(
|
||||
"owned_positions and host_indices must have same length, got "
|
||||
@@ -76,8 +80,10 @@ class CpHiCacheNodeMetadata:
|
||||
self.owned_positions >= self.logical_len
|
||||
):
|
||||
raise ValueError("owned_positions must be in [0, logical_len)")
|
||||
if torch.any(self.owned_positions[1:] < self.owned_positions[:-1]):
|
||||
raise ValueError("owned_positions must be sorted")
|
||||
if torch.any(self.owned_positions[1:] <= self.owned_positions[:-1]):
|
||||
raise ValueError(
|
||||
"owned_positions must be sorted and strictly increasing"
|
||||
)
|
||||
|
||||
def split(
|
||||
self, split_len: int
|
||||
|
||||
Reference in New Issue
Block a user