You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, i have issues when trying test cases on customized backend. actually i copy tflitecpu backend for my customized backend but cause i want to implement in my laptop (using Linux Environtment). so i edited the shell commands and profiler commands as needed.
MyProfiler :
# Copyright (c) Microsoft Corporation.# Licensed under the MIT license.importosfromnn_meter.builder.backendsimportBaseProfilerclassTFLiteProfiler(BaseProfiler):
use_gpu=Nonedef__init__(self, dst_kernel_path, benchmark_model_path, graph_path='', dst_graph_path='', num_threads=1, num_runs=50, warm_ups=10):
""" @params: graph_path: graph file. path on host server dst_graph_path: graph file. path on device kernel_path: dest kernel output file. path on device benchmark_model_path: path to benchmark_model """self._graph_path=graph_pathself._dst_graph_path=dst_graph_pathself._dst_kernel_path=dst_kernel_pathself._benchmark_model_path=benchmark_model_pathself._num_threads=num_threadsself._num_runs=num_runsself._warm_ups=warm_upsdefprofile(self, graph_path, preserve=False, clean=True, close_xnnpack=False, **kwargs):
""" @params: preserve: tflite file exists in remote dir. No need to push it again. clean: remove tflite file after running. """model_name=os.path.basename(graph_path)
remote_graph_path=os.path.join(self._dst_graph_path, model_name)
kernel_cmd=f'--kernel_path={self._dst_kernel_path}'ifself._dst_kernel_pathelse''close_xnnpack_cmd=f'--use_xnnpack=false'ifclose_xnnpackelse''try:
kernel_cmd=f'--kernel_path={self._dst_kernel_path}'ifself._dst_kernel_pathelse''close_xnnpack_cmd=f'--use_xnnpack=false'ifclose_xnnpackelse''res=os.system(f' {self._benchmark_model_path}{kernel_cmd}{close_xnnpack_cmd}' \
f' --num_threads={self._num_threads}' \
f' --num_runs={self._num_runs}' \
f' --warmup_runs={self._warm_ups}' \
f' --graph={remote_graph_path}' \
f' --enable_op_profiling=true' \
f' --use_gpu={"true"ifself.use_gpuelse"false"}')
except:
raisefinally:
ifclean:
os.system(f"rm {remote_graph_path}")
returnres
MyBackend :
# Copyright (c) Microsoft Corporation.# Licensed under the MIT license.importosimportshutilimportloggingfromnn_meter.builder.backendsimportBaseBackendfromnn_meter.utils.pathimportget_filename_without_extlogging=logging.getLogger("nn-Meter")
classTFLiteBackend(BaseBackend):
parser_class=Noneprofiler_class=Nonedefupdate_configs(self):
"""update the config parameters for TFLite platform """super().update_configs()
self.profiler_kwargs.update({
'dst_graph_path': self.configs['REMOTE_MODEL_DIR'],
'benchmark_model_path': self.configs['BENCHMARK_MODEL_PATH'],
'dst_kernel_path': self.configs['KERNEL_PATH']
})
defconvert_model(self, model_path, save_path, input_shape=None):
"""convert the Keras model instance to ``.tflite`` and return model path """importtensorflowastfmodel_name=get_filename_without_ext(model_path)
model=tf.keras.models.load_model(model_path)
converter=tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model=converter.convert()
converted_model=os.path.join(save_path, model_name+'.tflite')
open(converted_model, 'wb').write(tflite_model)
shutil.rmtree(model_path)
returnconverted_modeldeftest_connection(self):
"""check the status of backend interface connection """
...
logging.keyinfo("hello TFLitex64 backend !")
my custom backend is able to be registered in my laptop but i have issue when i try test fusion rules. i got profile_error.log that error 'int' object has no attribute 'splitlines'. so i try to debug content above line 27 cpu.py because in line 27 call splitlines and the result is 0 (it's integer) so i think that is the issue of error 'int' object has no attribute 'splitlines' but i don't know what is wrong in my configuration or code.
And also i got the issue WARNING:tensorflow:No training configuration found in save file, so the model was *not* compiled. Compile it manually. when i try test fusion rules. which configuration and where should I save the configuration file ?
and i have a question again, does REMOTE_MODEL_DIR must to have any model when running profile_model ?
Thanks
The text was updated successfully, but these errors were encountered:
so the issue is from my profiler when running benchmark. i change from os.system to subsprocess,check_output because os.system cannot return shell output. that the code :
res=subprocess.check_output(f' {self._benchmark_model_path}{kernel_cmd}{close_xnnpack_cmd}' \
f' --num_threads={self._num_threads}' \
f' --num_runs={self._num_runs}' \
f' --warmup_runs={self._warm_ups}' \
f' --graph={remote_graph_path}' \
f' --enable_op_profiling=true' \
f' --use_gpu={"true"ifself.use_gpuelse"false"}', shell=True)
Hello, i have issues when trying test cases on customized backend. actually i copy tflitecpu backend for my customized backend but cause i want to implement in my laptop (using Linux Environtment). so i edited the shell commands and profiler commands as needed.
MyProfiler :
MyBackend :
my backend register config :
my backend default config :
and i used cpu.py in this repo
my custom backend is able to be registered in my laptop but i have issue when i try test fusion rules. i got profile_error.log that error
'int' object has no attribute 'splitlines'
. so i try to debug content above line 27 cpu.py because in line 27 call splitlines and the result is 0 (it's integer) so i think that is the issue of error'int' object has no attribute 'splitlines'
but i don't know what is wrong in my configuration or code.And also i got the issue
WARNING:tensorflow:No training configuration found in save file, so the model was *not* compiled. Compile it manually.
when i try test fusion rules. which configuration and where should I save the configuration file ?and i have a question again, does REMOTE_MODEL_DIR must to have any model when running profile_model ?
Thanks
The text was updated successfully, but these errors were encountered: