This is a user manual on how to use AOT Inductor Intermediate Value Debug Printer tool which is a utility tool that can help pinpoint CUDA IMA kernels / numerical discrepancies when uses AOT Inductor to compile a PyTorch model.
The main functionality of this tool is to automatically print out / or dump the value info of all intermediate tensor arguments before and after each kernel launch call in AOT Inductor.
How to use
The debug printer can be configured via environment variable. The following flags are both supported to run with internal fbcode buck commands and OSS.
# options for debug printing/saving for intermediate tensor values for aot inductor0:disabledebugdumping1
:
enable
saving
intermediate
tensor
values
2
:
enable
printing
intermediate
tensor
values
3
:
enable
printing
kernel
names
only
(
useful
for
pinpointing
troublesome
kernels
)
To enable default mode debug printing:
Add flag AOT_INDUCTOR_DEBUG_INTERMEDIATE_VALUE_PRINTER=2 (PRINT_ONLY mode) for default printing all supported kernel tensor arg values.
Add flag AOT_INDUCTOR_FILTERED_KERNELS_TO_PRINT={kernel_name_1,kernel_name_2,...} for selectively printing tensor values associated with the specified kernels. (suggest to do a run with generating full printing logs first)
Useful when you want to repro the error in a standalone kernel debugging repro. The saved intermediate tensor values can be used as debugging inputs to the problematic kernel.
Set AOT_INDUCTOR_DEBUG_INTERMEDIATE_VALUE_PRINTER=1 (SAVE_ONLY mode) for default saving all supported kernel tensor arg values to .pt in a tmp folder.
Similarly, add AOT_INDUCTOR_FILTERED_KERNELS_TO_PRINT={kernel_name_1,kernel_name_2,...} for selectively saving tensor values associated with the specified kernels.
The saved tensor values will be dumped in a format: <before/after_launch>_<kernel_name>_<arg_name>_<device>.pt
The dumped .pt tensors can be further loaded and used like this:
def_load_tensor(path):returntorch.load(path,weights_only=True)tensor=_load_tensor("../tmp/aoti_torch/before_launch_aoti_torch_cuda_addmm_out_buf1_cuda:0.pt")# Simply print tensor to view the full valueprint(tensor)