tlparse

0.4.3 · active · verified Thu Apr 16

tlparse is a command-line utility for parsing structured `TORCH_LOG` logs generated by PyTorch's `torch.compile`. It analyzes these logs and outputs rich HTML reports, aiding in understanding the compilation process, identifying graph breaks, recompilations, and debugging dynamic shape issues. The current version is 0.4.3, and it is actively maintained within the PyTorch ecosystem.

Common errors

Warnings

Install

Quickstart

To use `tlparse`, first run your PyTorch script with the `TORCH_TRACE` environment variable set to a desired log directory. Then, execute the `tlparse` command-line tool on that directory to generate an HTML report. This example demonstrates how to set up log generation and provides the subsequent `tlparse` command.

import os
import torch

@torch.compile
def my_model(x):
    return x + x

def run_model_with_trace():
    log_dir = os.path.join(os.getcwd(), "my_traced_log_dir")
    os.makedirs(log_dir, exist_ok=True)
    
    # Set TORCH_TRACE environment variable to collect logs
    os.environ['TORCH_TRACE'] = log_dir
    
    try:
        x = torch.randn(10, 10)
        _ = my_model(x)
        print(f"Logs generated in: {log_dir}")
        print(f"Now run: tlparse {log_dir} -o tl_out/ --latest")
    finally:
        # Clean up the environment variable after use
        del os.environ['TORCH_TRACE']

if __name__ == "__main__":
    run_model_with_trace()

view raw JSON →