Profiler reports different # of Calls depending on group_by_stack_n
Labels: oncall: profiler

### 🐛 Describe the bug

The number of calls reported by the profiler to different functions doesn't have the same total when you change how the profiler results are printed.

Example: running the script 
```python
import torch
import torchvision.models as models
from torch.profiler import profile, record_function, ProfilerActivity

model = models.resnet50().cuda()
inputs = torch.randn(5, 3, 224, 224).cuda()
with profile(activities=[ProfilerActivity.CPU, ProfilerActivity.CUDA], with_stack=True, with_modules=False) as prof:
    model(inputs)
print(prof.key_averages(group_by_stack_n=2).table(sort_by="self_cuda_time_total"))
```
the aten::empty function is called 319 times, with the following lines found by grep:
```
                      aten::empty         0.16%       2.199ms         0.16%       2.199ms       8.298us       1.699ms         0.13%       1.699ms       6.411us           265  <built-in method batch_norm of type object at 0x7febe43d8f20>
                      aten::empty         0.04%     572.000us         0.04%     572.000us      10.792us     434.000us         0.03%     434.000us       8.189us            53  <built-in method conv2d of type object at 0x7febe43d8f20>
                      aten::empty         0.00%       1.000us         0.00%       1.000us       1.000us       3.000us         0.00%       3.000us       3.000us             1  <built-in function linear>
```
However, if we change group_by_stack_n to 4, it's only called 47 times!

The output is longer here, so you may find it helpful to use a line like
```bash
python test.py | grep empty | grep -v empty_like | tr -s ' ' | cut -d' ' -f 12 | paste -sd+ - | bc
```
but examining by eye should show that it's clearly far less than 300.

### Versions

Collecting environment information...
PyTorch version: 1.13.0a0+git4b3f1bd
Is debug build: False
CUDA used to build PyTorch: 11.6
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.1 LTS (x86_64)
GCC version: (Ubuntu 9.3.0-10ubuntu2) 9.3.0
Clang version: Could not collect
CMake version: version 3.16.3
Libc version: glibc-2.31

Python version: 3.8.5 (default, Jul 28 2020, 12:59:40)  [GCC 9.3.0] (64-bit runtime)
Python platform: Linux-5.4.0-47-generic-x86_64-with-glibc2.29
Is CUDA available: True
CUDA runtime version: 11.6.124
GPU models and configuration:
GPU 0: NVIDIA GeForce RTX 2080 Ti
GPU 1: NVIDIA GeForce RTX 2080 Ti
GPU 2: NVIDIA GeForce RTX 2080 Ti
GPU 3: NVIDIA GeForce RTX 2080 Ti
GPU 4: NVIDIA GeForce RTX 2080 Ti
GPU 5: NVIDIA GeForce RTX 2080 Ti
GPU 6: NVIDIA GeForce RTX 2080 Ti
GPU 7: NVIDIA GeForce RTX 2080 Ti

Nvidia driver version: 510.73.05
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.0.4
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.0.4
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.0.4
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.0.4
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.0.4
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.0.4
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.0.4
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] numpy==1.23.2
[pip3] torch==1.13.0a0+git4b3f1bd
[pip3] torchvision==0.14.0a0+9c3e2bf
[conda] Could not collect


cc @robieta @chaekit @aaronenyeshi @ngimel @nbcsm @guotuofeng @guyang3532 @gaoteng-git @tiffzhaofb