Add the bound check for flatten with out_dim (#120894)
Fixes #120762
The bound is not valid in the example but unchecked.
```
a = torch.tensor([1, 2, 3])
a.flatten(start_dim=0, end_dim=1, out_dim='a')
```
The same is checked for the case
```
a = torch.tensor([1, 2, 3])
a.flatten(start_dim=0, end_dim=1)
```
- Therefore, just apply the same check.
@malfet @janeyx99
Co-authored-by: Nikita Shulga <2453524+malfet@users.noreply.github.com>
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120894
Approved by: https://github.com/malfet, https://github.com/spzala