forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[inductor] Copy RedisRemoteCacheBackend into pytorch (pytorch#127480)
Summary: We need an implementation of RedisRemoteCacheBackend with the same API that we're using for FbMemcacheRemoteFxGraphCacheBackend. So we'll stop using the Triton implementation and adapt a version for use by inductor. I also renamed parameters and cache entries to match our cache terminology. Test Plan: Ran this command twice and inspected log output to ensure I got cache hits: ``` TORCH_LOGS=+torch._inductor.codecache TORCHINDUCTOR_FX_GRAPH_REMOTE_CACHE=1 python benchmarks/dynamo/torchbench.py --performance --inductor --device cuda --training --amp --print-compilation-time --only dcgan ``` Pull Request resolved: pytorch#127480 Approved by: https://github.com/oulgen
- Loading branch information
1 parent
cdeb242
commit 3f5d863
Showing
6 changed files
with
65 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import os | ||
from abc import abstractmethod | ||
|
||
|
||
class RemoteCacheBackend: | ||
""" | ||
A backend implementation for accessing a remote/distributed cache. | ||
""" | ||
|
||
def __init__(self, cache_id: str): | ||
pass | ||
|
||
@abstractmethod | ||
def get(self, key: str): | ||
pass | ||
|
||
@abstractmethod | ||
def put(self, key: str, data: bytes): | ||
pass | ||
|
||
|
||
class RedisRemoteCacheBackend(RemoteCacheBackend): | ||
""" | ||
A Redis implementation of a remote/distributed cache. | ||
""" | ||
|
||
def __init__(self, cache_id: str): | ||
import redis | ||
|
||
self._cache_id = cache_id | ||
self._key_fmt = os.environ.get( | ||
"TORCHINDUCTOR_REDIS_KEY_FORMAT", "pt2:{cache_id}:{key}" | ||
) | ||
self._redis = redis.Redis( | ||
host=os.environ.get("TRITON_REDIS_HOST", "localhost"), | ||
port=int(os.environ.get("TRITON_REDIS_PORT", 6379)), | ||
) | ||
|
||
def _get_key(self, key: str) -> str: | ||
return self._key_fmt.format(cache_id=self._cache_id, key=key) | ||
|
||
def get(self, key: str): | ||
return self._redis.get(self._get_key(key)) | ||
|
||
def put(self, key: str, data: bytes): | ||
return self._redis.set(self._get_key(key), data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters