Skip to content

Commit 74c822e

Browse files
authored
Merge branch 'master' into fix/docker_renamed_fork
2 parents f266667 + 7161c6f commit 74c822e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

benchmarks/utils/system_under_test.py

+26
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ def start(self):
113113
execute("torchserve --stop", wait=True)
114114
click.secho("*Setting up model store...", fg="green")
115115
self._prepare_local_dependency()
116+
self._clear_neuron_cache_if_exists()
116117
click.secho("*Starting local Torchserve instance...", fg="green")
117118

118119
ts_cmd = (
@@ -141,6 +142,31 @@ def start(self):
141142
if "Model server started" in str(line).strip():
142143
break
143144

145+
def _clear_neuron_cache_if_exists(self):
146+
cache_dir = "/var/tmp/neuron-compile-cache/"
147+
148+
# Check if the directory exists
149+
if os.path.exists(cache_dir) and os.path.isdir(cache_dir):
150+
click.secho(
151+
f"Directory {cache_dir} exists. Clearing contents...", fg="green"
152+
)
153+
154+
# Remove the directory contents
155+
for filename in os.listdir(cache_dir):
156+
file_path = os.path.join(cache_dir, filename)
157+
try:
158+
if os.path.isfile(file_path) or os.path.islink(file_path):
159+
os.unlink(file_path)
160+
elif os.path.isdir(file_path):
161+
shutil.rmtree(file_path)
162+
except Exception as e:
163+
click.secho(f"Failed to delete {file_path}. Reason: {e}", fg="red")
164+
click.secho(f"Cache cleared: {cache_dir}", fg="green")
165+
else:
166+
click.secho(
167+
f"Directory {cache_dir} does not exist. No action taken.", fg="green"
168+
)
169+
144170
def stop(self):
145171
click.secho("*Terminating Torchserve instance...", fg="green")
146172
execute("torchserve --stop", wait=True)

0 commit comments

Comments
 (0)