Skip to content

Commit bfa5900

Browse files
Peng Chen (Dev Infra)facebook-github-bot
authored andcommitted
Fix cache dir import (#2409)
Summary: Pull Request resolved: #2409 Starting from https://github.com/triton-lang/triton/pull/6467/files#diff-1e6a363bbde516739874d46d8ee06c60a7a76f194275b0f4d46638a0b06af8acR45, Triton exposes a different API to get the cache dir. This diff switches the call site to call that conditionally on triton versions. Reviewed By: jerryzh168 Differential Revision: D76929618
1 parent 4e3d019 commit bfa5900

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

torchao/prototype/galore/kernels/custom_autotune.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from typing import Dict
1313

1414
import numpy as np
15-
from triton.runtime.cache import default_cache_dir
1615
from triton.runtime.errors import OutOfResources
1716
from triton.runtime.jit import KernelInterface
1817
from triton.testing import do_bench
@@ -183,7 +182,18 @@ def run(self, *args, **kwargs):
183182
)
184183
_key_suffix = self._get_key_combination(args, sep="-")
185184
autotune_file = f"autotune_{self.kernel_name}_{_key_suffix}.log"
186-
autotune_log_path = os.path.join(default_cache_dir(), autotune_file)
185+
# In newer Triton we always use knobs
186+
# This try-catch is here only to support Triton upgrading
187+
try:
188+
from triton import knobs
189+
190+
# this API takes into consideration env var and redirecting user home dir for fbcode
191+
triton_cache_dir = knobs.cache.dir
192+
except ImportError:
193+
from triton.runtime.cache import default_cache_dir
194+
195+
triton_cache_dir = default_cache_dir()
196+
autotune_log_path = os.path.join(triton_cache_dir, autotune_file)
187197

188198
logger.info(f"\nFinished autotune, writing log to {autotune_log_path}")
189199

0 commit comments

Comments
 (0)