@@ -113,6 +113,7 @@ def start(self):
113
113
execute ("torchserve --stop" , wait = True )
114
114
click .secho ("*Setting up model store..." , fg = "green" )
115
115
self ._prepare_local_dependency ()
116
+ self ._clear_neuron_cache_if_exists ()
116
117
click .secho ("*Starting local Torchserve instance..." , fg = "green" )
117
118
118
119
ts_cmd = (
@@ -141,6 +142,31 @@ def start(self):
141
142
if "Model server started" in str (line ).strip ():
142
143
break
143
144
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
+
144
170
def stop (self ):
145
171
click .secho ("*Terminating Torchserve instance..." , fg = "green" )
146
172
execute ("torchserve --stop" , wait = True )
0 commit comments