GDB for Pytorch

I want to know how I can see the stack trace of PyTorch functions written in C++.

Can anyone help with how I can use GDB or any other debugger?

Any help would be appreciated.

gdb should directly work and I would recommend to use a debug source build for an easier debugging.
E.g. assuming you would like to debug the adaptive_avg_pool2d method, you could use:

gdb --args python
(gdb) break cpu_adaptive_avg_pool
Function "cpu_adaptive_avg_pool" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (cpu_adaptive_avg_pool) pending.
(gdb) run

which allows you to step, continue, set other breakpoints etc.