From 625611d976e28e03ffdd657281b417781b63fdac Mon Sep 17 00:00:00 2001 From: Salman Khan Date: Wed, 9 Mar 2022 10:34:01 +0000 Subject: [PATCH 1/5] Added help function --- .../xformer/python/src/xformer/__init__.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/experimental/xformer/python/src/xformer/__init__.py b/experimental/xformer/python/src/xformer/__init__.py index 43d109abf..eb73abdc5 100644 --- a/experimental/xformer/python/src/xformer/__init__.py +++ b/experimental/xformer/python/src/xformer/__init__.py @@ -4,8 +4,11 @@ from typing import Union, List, Optional -def convert(filename: Union[str, Path], outfile: Union[str, Path], - params: Optional[typing.Dict[str, Optional[str]]]) -> int: +def convert( + filename: Union[str, Path], + outfile: Union[str, Path], + params: Optional[typing.Dict[str, Optional[str]]], +) -> int: args: List[Optional[str]] = ["xcore-opt", "-o", str(outfile)] if params is not None: @@ -22,5 +25,13 @@ def convert(filename: Union[str, Path], outfile: Union[str, Path], args.append(str(filename)) process_call: subprocess.CompletedProcess = subprocess.run( - [arg for arg in args], check=True) + [arg for arg in args], check=True + ) return process_call.returncode + + +def xformer_help(show_hidden: Optional[bool] = False) -> int: + if show_hidden: + return subprocess.run(["xcore-opt", "--help-list-hidden"]).returncode + + return subprocess.run(["xcore-opt", "--help-list"]).returncode From 0132280ae4a51da41542dc37b1b17a00cc5e7f19 Mon Sep 17 00:00:00 2001 From: Salman Khan Date: Wed, 9 Mar 2022 10:34:20 +0000 Subject: [PATCH 2/5] documented help function and added example passing of parameters --- experimental/xformer/python/README.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/experimental/xformer/python/README.md b/experimental/xformer/python/README.md index c989672e8..5c50ac2a2 100644 --- a/experimental/xformer/python/README.md +++ b/experimental/xformer/python/README.md @@ -3,11 +3,31 @@ ## Usage ### Using xformer -``` +```python from xmos_ai_tools import xformer as xf xf.convert("source model path", "converted model path", params=None) ``` +where `params` is a dictionary of compiler flags and paramters and their values. + +For example: +```python +from xmos_ai_tools import xformer as xf + +xf.convert("/Users/salmankhan/Development/tflite_flatbuffers/weights_full_integer_quant.tflite", "./converted", { + "mlir-disable-threading": None, + "xcore-reduce-memory": None, +}) +``` + +To see all available parameters, call +```python +from xmos_ai_tools import xformer as xf + +xf.xformer_help() +``` +This will print all options available to pass to xformer. To see hidden options, run `xformer_help(show_hidden=True)` + ### Using the xcore tflm host interpreter ``` From 6ca5f504da4cc0f48060d8d3287c74f3b00ba7fd Mon Sep 17 00:00:00 2001 From: Andrew Stanford-Jason Date: Thu, 10 Mar 2022 08:32:18 +0000 Subject: [PATCH 3/5] Update README.md --- experimental/xformer/python/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/experimental/xformer/python/README.md b/experimental/xformer/python/README.md index 5c50ac2a2..b9582e604 100644 --- a/experimental/xformer/python/README.md +++ b/experimental/xformer/python/README.md @@ -14,7 +14,7 @@ For example: ```python from xmos_ai_tools import xformer as xf -xf.convert("/Users/salmankhan/Development/tflite_flatbuffers/weights_full_integer_quant.tflite", "./converted", { +xf.convert("example_int8_model.tflite", "xcore_optimised_example_int8_model.tflite", { "mlir-disable-threading": None, "xcore-reduce-memory": None, }) @@ -39,4 +39,4 @@ ie.invoke() xformer_outputs = [] for i in range(num_of_outputs): xformer_outputs.append(ie.get_output_tensor(i)) -``` \ No newline at end of file +``` From 8ef476d20e1d4ee5fe909df262dd0a389cb44a6d Mon Sep 17 00:00:00 2001 From: Andrew Stanford-Jason Date: Thu, 10 Mar 2022 08:33:31 +0000 Subject: [PATCH 4/5] Update __init__.py --- experimental/xformer/python/src/xformer/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experimental/xformer/python/src/xformer/__init__.py b/experimental/xformer/python/src/xformer/__init__.py index eb73abdc5..02346b9b9 100644 --- a/experimental/xformer/python/src/xformer/__init__.py +++ b/experimental/xformer/python/src/xformer/__init__.py @@ -30,7 +30,7 @@ def convert( return process_call.returncode -def xformer_help(show_hidden: Optional[bool] = False) -> int: +def print_help(show_hidden: Optional[bool] = False) -> int: if show_hidden: return subprocess.run(["xcore-opt", "--help-list-hidden"]).returncode From c51afdd00e93ef52ea6bc4244b2cc8defa62c91a Mon Sep 17 00:00:00 2001 From: Andrew Stanford-Jason Date: Thu, 10 Mar 2022 08:33:59 +0000 Subject: [PATCH 5/5] Update README.md --- experimental/xformer/python/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/experimental/xformer/python/README.md b/experimental/xformer/python/README.md index b9582e604..c9bb0cb8b 100644 --- a/experimental/xformer/python/README.md +++ b/experimental/xformer/python/README.md @@ -24,9 +24,9 @@ To see all available parameters, call ```python from xmos_ai_tools import xformer as xf -xf.xformer_help() +xf.print_help() ``` -This will print all options available to pass to xformer. To see hidden options, run `xformer_help(show_hidden=True)` +This will print all options available to pass to xformer. To see hidden options, run `print_help(show_hidden=True)` ### Using the xcore tflm host interpreter