PyTorch 編譯器(torch.compile)會跨呼叫重用快取的編譯產物。判斷能否重用的條件如果漏看模型內部狀態或輸入性質的變化,後面的呼叫就會沿用舊產物,回傳錯的結果,而且不拋例外;同一個呼叫在編譯狀態重置後單獨跑,結果卻是對的。兩個作者不重疊的團隊各自在 PyTorch 記錄到這一型錯誤:一隊用新工具測出 22 個,開發者確認 12 份、修了 8 個;另一隊盤點已關閉的議題,在 116 件開發者確認的正確性錯誤中找到 5 件屬於這一型。兩隊也都指出,要連續呼叫、並在呼叫之間改變模型內部狀態或輸入性質才測得出來,只編譯執行一次就比對輸出的測試測不到。因此,在同一個行程保留 torch.compile 快取並重複呼叫的訓練與推論工作負載,啟用 torch.compile 和 PyTorch 升版時的放行檢查不能只做單次輸出比對,還要加上連續呼叫、並在呼叫之間換輸入形狀或模型狀態後的比對。這一型在已盤點的 torch.compile 正確性錯誤中占少數,真實負載的發生率與觸發頻率沒有人量過;JAX 與 TensorFlow 只有一篇論文測到同型、件數少,不在本判斷射程內。
這不是預測,所以沒有排定哪一天對答案。
什麼會推翻它
各條行尾若有日期,那是相反的證據要在那天前出現才算數的期限,不是對答案的日子。
PyTorch 官方 GitHub 議題區中,屬 torch.compile 元件、經 PyTorch 開發者確認、症狀為「重複呼叫後沿用舊的快取編譯產物而輸出錯誤」的新議題件數(只算 2027-01-01 到 2027-06-30 建立的議題) — 0 件,且這段期間 PyTorch 至少發布兩個小版本 — 若為 0 件,削弱「放行檢查必須加連續呼叫比對」的必要性(代表這一型已少到單次比對就夠),判斷降回 hypothesis 或收窄 — 2027-07-31
兩篇作者團隊以外的第三方公開量測:在真實的訓練或推論工作負載上,對同一行程的 torch.compile 做「保留快取 vs 重置快取」連續呼叫比對,記錄結果不一致的次數 — 至少一份公開量測涵蓋累計 100 萬次以上呼叫,而且 0 件不一致 — 若成立,削弱「真實負載會走到觸發序列、所以放行檢查要加連續呼叫比對」的實務必要性,判斷收窄到會在呼叫之間改權重、屬性或輸入形狀的用法 — 2027-12-31
寫下判斷時的出處
https://arxiv.org/html/2610.22003
「Of the 117 bugs, 35 were stateful compiler bugs, including 22 in PyTorch, 8 in TensorFlow, 2 in JAX, and 3 in MindSpore. In these cases, compiler state from earlier invocations caused an incorrect result in a later invocation.」
「Table 3. Bug detection and reporting results. Numbers in parentheses denote counts for bugs with at least one stateful witness. | Framework | Bugs | Submitted | Confirmed | Fixed | PyTorch | 30 (22) | 15 (14) | 13 (12) | 8 (8)」
「Detecting stateful compiler bugs requires checking outputs, gradients, and observable program state. These bugs can affect any of these results without raising an exception.」
「Triggering these bugs requires invocation sequences that first establish compiler state and then change relevant program state before an invocation that exposes the bug.」
「repeated-invocation tests can expose failures after changes to model state or inputs, but confirming a stateful compiler bug requires separating program state from compiler state.」
Ge et al. — Stateful Testing for Deep Learning Compilers (Rondo, arXiv 2610.22003) · arXiv
「Retained compiler state can make a later invocation incorrect even when it is correct in isolation.」
https://arxiv.org/html/2604.08720v1
「Bug 2: Graph Caching Bugs (5/116). Graph Caching Bugs are defined as correctness bugs caused by the misuse of cached computational graphs. The goal of graph caching in torch.compile is to mitigate redundant compilation processes through the reuse of cached graphs. However, reusing semantically inequivalent cached graphs can lead to incorrect model outputs.」
「The root cause of graph caching bugs is the improper implementation of the guard condition, which verifies the semantic equivalence between the cached graphs and the user-defined models. Incorrect guard conditions may fail to comprehensively model all factors necessary for semantic equivalence verification, thus incorrectly reusing a semantically inequivalent graph for the user-defined model. These missed factors include, but are not limited to: model input properties (e.g., _max_seqlen for NestedTensor inputs, tensor shapes) and mutable internal states of the model.」
「However, torch.compile is prone to correctness bugs, which cause incorrect outputs of compiled DL models without triggering exceptions, crashes, or warnings.」
「The bug-triggering pattern of Graph Caching Bugs includes a specific testing pipeline: repeatedly executing the compiled user-defined model with varying internal model states or input properties.」
「Notably, this pipeline is missed by existing DL compiler fuzzers (Yang et al., 2024; Liu et al., 2023b; Liu et al., 2023a; Shen et al., 2021), which predominantly compile the user-defined model once to detect correctness bugs.」
「All 15 graph-related bugs in our benchmark are missed by studied techniques, including 14 Graph Semantic Capturing Bugs (GSC) and 1 Graph Caching Bug (GCB).」
「Most current DL compiler techniques rely on differential testing as a test oracle, which executes the compiled model once and compares model outputs before and after compilation. However, as highlighted in Section 3, certain graph-related bugs can only be detected by dedicated testing pipelines (i.e., repeated execution), rather than standard differential testing.」