gemini-2.5-pro-exp-03-25| input-price: 1.25 output-price: 10.0 max-context-length: 128_000 (cost: $0.10) Β· Anfrage: 2025-04-20T22:18:15.004781
Generated by rs-summarizer Version unbekannt
Abstract:
This transcript captures a live Q&A session featuring Richard Zoo from the PyTorch compiler team, discussing torch.compile. The session addresses common performance pitfalls such as graph breaks, recompilations, and the handling of non-native custom kernels, offering advice on writing compile-friendly code. Detailed explanations cover integrating third-party kernels, including C++, Python-based operators, and user-defined Trident kernels, highlighting how torch.compile treats them (often as black boxes, with special handling for Trident). Richard outlines the internal architecture (Dynamo for graph capture, AOTDispatcher for normalization/functionalization/autograd, and Inductor for backend optimization/code generation). Key optimizations like operator fusion, dead code elimination, and partitioning are discussed, alongside methods for inspecting the compilation process using logs and the TL parse tool. The future roadmap, focusing on performance, usability (error messages, escape hatches), reducing compile times (including AOT compilation), and expanding library support, is presented. Finally, guidance is given on community contributions to PyTorch and torch.compile.
PyTorch Compile Q&A: Performance, Custom Kernels, Internals, and Future Directions
torch.compile hosted by Mark, featuring Richard Zoo from the PyTorch compiler team. Format involves answering pre-submitted and live chat questions.torch.compile and how to write code it can optimize effectively.torch.compile breaks the function into subgraphs when it encounters unsupported operations (like print). This incurs overhead and prevents optimizations across breaks. Recommendation: Eliminate breaks or use fullgraph=True to identify them.torch.compile treats them as black boxes and cannot optimize inside them. Suggestion: Rewrite kernels using native PyTorch ops where possible for better fusion opportunities.mode='reduce_overhead' to enable CUDAGraphs (reduces kernel launch overhead on NVIDIA GPUs). Use autotuning (inductor.config.autotune_pointwise=True, etc.) to let the compiler benchmark and choose the fastest kernel implementation, at the cost of increased compilation time.torch.compile recompiles when inputs change characteristics (e.g., tensor shapes, strides, Python scalar values used in the graph). Excessive recompilation hurts performance. Monitor recompiles and consider using dynamic shapes features if needed.torch.compile.@torch.library.custom_op (Python) or C++ registration APIs. Crucially, provide a meta kernel (or shape inference function) to tell torch.compile how output shapes are derived from input shapes, needed for tracing.torch.compile cannot handle.torch.compile recognizes Trident kernels, wraps them in a black box node, and includes their source code in its generated output. It aims to support most Trident features but sometimes needs updates for new ones (e.g., host TMA, specific autotuning).torch.compile does analyze Trident kernels slightly (unlike regular custom ops) to determine which inputs are mutated (for functionalization) and integrates with Trident's autotuning.torch.compile:diffusers, LLM inference/serving frameworks (vLLM, SGLang).torch.compile:sin, cos, add) and reductions are commonly fused. Use TORCH_LOGS=output_code to inspect.TL parse tool on logs generated with TORCH_LOGS=+dynamo,+aot,+inductor to view the graph at different stages (Dynamo output, AOT output, Inductor output) and the final generated code in a human-readable format.torch.compile Design Overview:FX Graph). Handles graph breaks.torch.export + AOT Inductor workflow primarily targets inference and produces an artifact loadable in C++ but typically without gradient support.functorch.make_fx to trace a combined forward-and-backward function into a single graph, then export/compile that graph using AOT Inductor. This artifact can be run in C++, effectively executing both forward and backward.torch._dynamo.config.fast_fp_precision = "higher" might help align behavior. Minimize the compiled region to isolate the source.torch.compile: Find "good first issue" or "actionable" issues on GitHub. Read the contribution guide and core onboarding wiki. Engage in discussions on issues/PRs. Help is welcome.fullgraph=True, providing non_strict_trace (a JAX-like tracing mode as an alternative to Dynamo), and mechanisms to override faulty caching behavior.