If depends how error is calculated and in particular if the operations are differentiable.
E.g. if you’ve calculated the subgroup metrics by using torch.argmax it won’t be differentiable and you would need to define the gradients manually e.g. via a custom backward operation.