Skip to content

Commit

Permalink
Merge pull request #563 from banoffee-pie/add-help-function
Browse files Browse the repository at this point in the history
Add help function to xformer python module and add example to documentation
  • Loading branch information
andrewstanfordjason authored Mar 11, 2022
2 parents cad50ab + 09bf23b commit 4749ac1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
24 changes: 22 additions & 2 deletions experimental/xformer/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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("example_int8_model.tflite", "xcore_optimised_example_int8_model.tflite", {
"mlir-disable-threading": None,
"xcore-reduce-memory": None,
})
```

To see all available parameters, call
```python
from xmos_ai_tools import xformer as xf

xf.print_help()
```
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
```
Expand All @@ -19,4 +39,4 @@ ie.invoke()
xformer_outputs = []
for i in range(num_of_outputs):
xformer_outputs.append(ie.get_output_tensor(i))
```
```
17 changes: 14 additions & 3 deletions experimental/xformer/python/src/xformer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 print_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

0 comments on commit 4749ac1

Please sign in to comment.