diff --git a/sdm/tensor/categorical.py b/sdm/tensor/categorical.py index e9466fee7..2d2172762 100644 --- a/sdm/tensor/categorical.py +++ b/sdm/tensor/categorical.py @@ -329,6 +329,10 @@ def from_tensor(cls, tensor: Tensor) -> Self: for column in tensor.unbind(dim=-1) ] ) + # Tell torch.compile that nonempty columns have at least one category. + if tensor.numel() > 0: + for category in categories: + torch._check(category.numel() > 0) return cls( code=torch.stack(values, dim=-1), categories=categories,