Also, you may try batch_map.smm(sparse_weights).mm(P), where batch_map - sparse binary tensor of shape (batch_size,len(group_ids)). That’s just a clunky way to index sparse_weights, not sure if there are better ways…