I would like to have a model that outputs all zeros.
My currently attempt is:
class Zeros(nn.Module):
    def __init__(self, num_predict: int):
        super().__init__()
        # Need at least one trainable parameter in the model
        self._par = nn.Parameter(torch.ones(1, dtype=torch.float), requires_grad=True)
        self._num_predict = num_predict

    def forward(self, batch: Tensor) -> Tensor:
        batch_size = batch.size(0)
        zeros = torch.zeros(batch_size, self._num_predict, dtype=batch.dtype, device=batch.device, requires_grad=True)
        return zeros

But when I try to train it, I get the following error half-way through:
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 18446744072293033697) >= this->size() (which is 3)
[1]    14877 abort (core dumped)  python train_cfg.py configs/zeros.yaml

This error doesn’t happen if I train a proper model.
What can be the problem?