0

I want to step into the linear function using VS Code's step-in , but it skips automatically when I click "step into". Could anyone help me with this? I used DEBUG=1 when compiling PyTorch.

I can't step into the linear function using either python launch or gdb attach.

However, strangely, if I set a breakpoint on the line const KernelFunction& kernel = op.operatorDef_->op.lookup(dispatchKeySet); in the directory /home/sss/WORK/PYTORCH/pytorch/aten/src/ATen/core/dispatch/Dispatcher.h, I can step into or enter that line.

It doesn't work without the breakpoint. Is this normal? Is there any way to solve this?

my test code:

import torch
import torch.nn.functional as F
x = torch.tensor([[1.0, 2.0]]).to('cuda')
weight = torch.tensor([[0.5, 0.5], [0.5, 0.5]]).to('cuda')
y = F.linear(x, weight)

My launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "/home/sss/WORK/PYTORCH/test.py",
            "console": "integratedTerminal",
            "justMyCode": false ,
        },
        {
            "name": "(gdb) Attach to Process",
            "type": "cppdbg",
            "request": "attach",
            "program": "/home/sss/WORK/VLLM/vllm/.venv/bin/python",
            "processId": "${command:pickProcess}",
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true 
                }
            ]
        }
    ],
    "compounds": [
        {
            "name": "Python + C++ (Attach)",
            "configurations": ["Python: Current File", "(gdb) Attach to Process"]
        }
    ]
}

1 Answer 1

0

You can't be cause under the hood, the calculation is now out of Python scope (it's dispatched to C++ or CUDA code for actual execution), therefore the Python Debugger cannot catch what the function is doing.

On the other hand, if you set a breakpoint in C++ code, the C++ debugger now catch it and you can enter the code. This is because GDB (C++ debugger) does not actively catch all native call events. It's like in Python if you use step over it will run all the lines after and don't listen to what they do until it hit another breakpoint or an exception.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.