Browse Source

fix(mge/redis_server): fix bug for external connection

GitOrigin-RevId: 0b595712d7
tags/v0.5.0
Megvii Engine Team Xu Xinran 5 years ago
parent
commit
6d0d5e5a75
2 changed files with 13 additions and 44 deletions
  1. +1
    -44
      python_module/megengine/_internal/persistent_cache.py
  2. +12
    -0
      python_module/test/integration/test_fastrun.py

+ 1
- 44
python_module/megengine/_internal/persistent_cache.py View File

@@ -60,14 +60,7 @@ class PersistentCacheOnServer(_PersistentCache):
def _conn(self):
"""get redis connection"""
if self._cached_conn is None:
try:
self._cached_conn = self.make_redis_conn()
except Exception as exc:
get_logger().error(
"failed to connect to cache server: {!r}; fallback to "
"in-memory cache".format(exc)
)
self._cached_conn = _FakeRedisConn()
self._cached_conn = _FakeRedisConn()
self._prefix = self.make_user_prefix()

return self._cached_conn
@@ -76,14 +69,6 @@ class PersistentCacheOnServer(_PersistentCache):
def make_user_prefix(cls):
return "mgbcache:{}".format(getpass.getuser())

@classmethod
def make_redis_conn(cls):
import redis

conn = redis.StrictRedis(
'localhost', 6381,
socket_connect_timeout=2, socket_timeout=1)
return conn

def _make_key(self, category, key):
prefix_with_version = "{}:MGB{}".format(self._prefix, __version__)
@@ -103,31 +88,3 @@ class PersistentCacheOnServer(_PersistentCache):
return self._prev_get_refkeep


def _clean():
match = PersistentCacheOnServer.make_user_prefix() + "*"
conn = PersistentCacheOnServer.make_redis_conn()
cursor = 0
nr_del = 0
while True:
cursor, values = conn.scan(cursor, match)
if values:
conn.delete(*values)
nr_del += len(values)
if not cursor:
break

print("{} cache entries deleted".format(nr_del))


def main():
parser = argparse.ArgumentParser(description="manage persistent cache")
subp = parser.add_subparsers(description="action to be performed", dest="cmd")
subp.required = True
subp_clean = subp.add_parser("clean", help="clean all the cache of current user")
subp_clean.set_defaults(action=_clean)
args = parser.parse_args()
args.action()


if __name__ == "__main__":
main()

+ 12
- 0
python_module/test/integration/test_fastrun.py View File

@@ -0,0 +1,12 @@
import numpy as np

import megengine as mge
from megengine.functional.debug_param import set_conv_execution_strategy
from megengine.module.conv import Conv2d


def test_fastrun():
set_conv_execution_strategy("PROFILE")
x = Conv2d(1, 1, kernel_size=1, bias=True)
a = mge.tensor(np.random.randn(1, 1, 1, 1).astype(np.float32))
a = x(a)

Loading…
Cancel
Save