Skip to content

Commit

Permalink
Merge branch 'main' into channels_last_branches
Browse files Browse the repository at this point in the history
  • Loading branch information
nghielme authored Dec 20, 2024
2 parents 8ab1f28 + 364f995 commit 177f528
Show file tree
Hide file tree
Showing 51 changed files with 2,993 additions and 400 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Inference cost for CNV_2W2A.onnx
}
```

You can use the `--cost-breakdown` option to generate a more detailed report that covers per-node (by name) and per-op-type information.
You can read more about the BOPS metric in [this paper](https://www.frontiersin.org/articles/10.3389/frai.2021.676564/full), Section 4.2 Bit Operations.

### Convert between different quantization representations
Expand All @@ -114,16 +115,19 @@ Please see the documentation of the `QuantToQCDQ` transformation to learn more a

## Development

Install in editable mode in a venv:
Install in editable mode in a Python virtual environment:

```
git clone https://github.com/fastmachinelearning/qonnx
cd qonnx
virtualenv -p python3.8 venv
source venv/bin/activate
pip install --upgrade pip
pip install -e .[qkeras,testing]
```

### Running tests

Run entire test suite, parallelized across CPU cores:
```
pytest -n auto --verbose
Expand All @@ -134,6 +138,22 @@ Run a particular test and fall into pdb if it fails:
pytest --pdb -k "test_extend_partition.py::test_extend_partition[extend_id1-2]"
```

### Linting

If you plan to make pull requests to the qonnx repo, linting will be required.
We use a pre-commit hook to auto-format Python code and check for issues. See https://pre-commit.com/ for installation. Once you have `pre-commit`,
you can install the hooks into your local clone of the qonnx repo:

```
cd qonnx
source venv/bin/activate
pip install pre-commit
pre-commit install
```

Every time you commit some code, the pre-commit hooks will first run, performing various checks and fixes. In some cases pre-commit won’t be able to
fix the issues and you may have to fix it manually, then run git commit once again. The checks are configured in .pre-commit-config.yaml under the repo root.

## Why QONNX?

The QONNX representation has several advantages compared to other alternatives, as summarized in the table below.
Expand Down
3 changes: 3 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ Install in editable mode in a venv:
pip install -e .[testing, docs, notebooks]


Test suite
++++++++++

Run entire test suite, parallelized across CPU cores:

::
Expand Down
4 changes: 2 additions & 2 deletions docs/license.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. _license:

=======
========
License
=======
========

.. include:: ../LICENSE
20 changes: 19 additions & 1 deletion docs/qonnx-custom-ops/quant_op.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This operator is not part of the ONNX standard and is not currently versioned.
<dt><tt>narrow</tt> : int (default is 0)</dt>
<dd>Defines if the value range should be interpreted as narrow, when signed=1. E.g. at 8b regular=[-128, 127] vs narrow=[-127, 127].</dd>
<dt><tt>rounding_mode</tt> : string (default is "ROUND")</dt>
<dd>Defines how rounding should be applied during quantization. Currently available modes are: "ROUND", "CEIL" and "FLOOR". Here "ROUND" implies a round-to-even operation. Lowercase variants for the rounding mode string are also supported: "round", "ceil", "floor".</dd>
<dd>Defines how rounding should be applied during quantization. Avaiable options are ROUND, CEIL, FLOOR, UP, DOWN, HALF_UP, HALF_DOWN. The rounding modes are described in the table bellow. The names of rounding modes can be upper case or lower case.</dd>
</dl>

#### Inputs
Expand All @@ -46,6 +46,24 @@ This operator is not part of the ONNX standard and is not currently versioned.
</dl>


#### Rounding modes
<details>
<summary>rounding modes</summary>

| **Number \ ROUNDING_MODE** | ROUND=HALF_EVEN | CEIL | FLOOR | UP | DOWN | HALF_UP | HALF_DOWN |
|----------------------------|-----------------|------|-------|----|------|---------|-----------|
| 5.5 | 6 | 6 | 5 | 6 | 5 | 6 | 5 |
| 2.5 | 2 | 3 | 2 | 3 | 2 | 3 | 2 |
| 1.6 | 2 | 2 | 1 | 2 | 1 | 2 | 2 |
| 1.1 | 1 | 2 | 1 | 2 | 1 | 1 | 1 |
| 1.0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| -1.0 | -1 | -1 | -1 | -1 | -1 | -1 | -1 |
| -1.1 | -1 | -1 | -2 | -2 | -1 | -1 | -1 |
| -1.6 | -2 | -1 | -2 | -2 | -1 | -2 | -2 |
| -2.5 | -2 | -2 | -3 | -3 | -2 | -3 | -2 |
| -5.5 | -6 | -5 | -6 | -6 | -5 | -6 | -5 |
</details>

#### Examples
<details>
<summary>Quant</summary>
Expand Down
19 changes: 10 additions & 9 deletions notebooks/0_how_to_work_with_onnx.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,26 @@
" name='Add2',\n",
")\n",
"\n",
"Add3_node = onnx.helper.make_node(\n",
" 'Add',\n",
" inputs=['abs1', 'abs1'],\n",
" outputs=['sum3'],\n",
" name='Add3',\n",
")\n",
"\n",
"Abs_node = onnx.helper.make_node(\n",
" 'Abs',\n",
" inputs=['sum2'],\n",
" outputs=['abs1'],\n",
" name='Abs'\n",
")\n",
"\n",
"Add3_node = onnx.helper.make_node(\n",
" 'Add',\n",
" inputs=['abs1', 'abs1'],\n",
" outputs=['sum3'],\n",
" name='Add3',\n",
")\n",
"\n",
"Round_node = onnx.helper.make_node(\n",
" 'Round',\n",
" inputs=['sum3'],\n",
" outputs=['out1'],\n",
" name='Round',\n",
")\n"
")"
]
},
{
Expand Down Expand Up @@ -253,7 +253,7 @@
"metadata": {},
"outputs": [],
"source": [
"in1_values =np.asarray(np.random.uniform(low=-5, high=5, size=(4,4)), dtype=np.float32)\n",
"in1_values = np.asarray(np.random.uniform(low=-5, high=5, size=(4,4)), dtype=np.float32)\n",
"in2_values = np.asarray(np.random.uniform(low=-5, high=5, size=(4,4)), dtype=np.float32)\n",
"in3_values = np.asarray(np.random.uniform(low=-5, high=5, size=(4,4)), dtype=np.float32)"
]
Expand Down Expand Up @@ -350,6 +350,7 @@
"metadata": {},
"outputs": [],
"source": [
"import qonnx\n",
"from qonnx.core.modelwrapper import ModelWrapper\n",
"finn_model = ModelWrapper(onnx_model)"
]
Expand Down
Loading

0 comments on commit 177f528

Please sign in to comment.