Skip to content

Commit 167ed28

Browse files
authored
Cache NvidiaTool.from_path (#7569)
We're currently updating the internal Triton version at Meta, and one of the things that process has flushed out is that there has been some regression in compile time since 3.2. One of the main culprits is `NvidiaTool.from_path`; we call it all the time under the hood, and each time it spawns a subprocess just to check the version. The benchmark I'm using is a torch.compiled'd model with ~300 kernels, and this change saves about 10% off of the overall compile time. I don't have strong feelings on how defensive to be here. I picked a middle-of-the road level where I guard `PATH`, but don't go crazy guarding against every conceivable level of magic. (I think the existing knobs unit tests are pretty representative of what one might expect of "reasonable" behavior, but let me know if you'd like me to tweak the level of defensiveness.)
1 parent d5de496 commit 167ed28

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

python/triton/knobs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import functools
34
import importlib
45
import os
56
import re
@@ -170,6 +171,7 @@ class NvidiaTool:
170171
version: str
171172

172173
@staticmethod
174+
@functools.lru_cache
173175
def from_path(path: str) -> Optional[NvidiaTool]:
174176
try:
175177
result = subprocess.check_output([path, "--version"], stderr=subprocess.STDOUT)

0 commit comments

Comments
 (0)