ezyang / torchdbg

PyTorch centric eager mode debugger

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

torchdbg

torchdbg is two things:

  • A tracer that dumps all PyTorch operations that occur in your program to a structured log (formatted compatibly with tlparse)

  • A React UI for visualizing the traces produced above, in the same style as a single-stepping debugger.

image

This is an Easter vacation hack from @ezyang, I don't currently have plans to keep pushing this further but maybe the community is willing to pick this up and run with it.

How to use

Python tracer

You need a reasonably recent PyTorch nightly (it needs pytorch/pytorch#120289) for this to work.

To use the Python tracer, pip install torchdbg and then in your code:

import torchdbg

with torchdbg.LoggingMode():
    ...  # your code here

By default, we do not log anything: run with TORCH_TRACE=/tmp/trace to specify the log directory. If you are running a distributed training run, multiple trace files will be generated per rank.

React UI

A live version of the UI is here: https://ezyang.github.io/torchdbg/ It is entirely client side, the trace files never leave your browser. Use the slider at the bottom to advance forward/back in the trace.

To run it locally, first, run the development server:

npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev

Open http://localhost:3000 with your browser to see the result.

Upload one of the generated trace files to the UI.

About

PyTorch centric eager mode debugger

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:TypeScript 70.0%Language:Python 24.8%Language:CSS 3.6%Language:JavaScript 1.6%