I’d just check out master + the non-native/test bits of the PR. (the PR is now merged).
Depending on how large degs is, maybe this would already work well:
degs = torch.randint(0, 10, (20,))
degs_sum = degs.cumsum(0)
data_size = degs_sum[-1].item()
products =torch.randn(data_size, 100, 10, requires_grad=True)
classes = (torch.arange(1,products.size(0)+1)[None]>degs_sum[:,None]).sum(0)  # this is inefficient, but if the number of classes isn't too large...
output = torch.zeros(degs.size(), dtype=products.dtype, device=products.device)
row_means = products.view(products.size(0), -1).mean(1)
output = output.scatter_add_(0, classes, row_means)/degs.clamp(min=1).float()

Best regards
Thomas