Skip to content

Commit 84db7df

Browse files
jurevreca12Jure Vreca (jure.vreca@ijs.si
andauthored
Qonnx only c4ml (#22)
* Removed brevitas as main dependency. * brevitas tests working by comparing qonnx/c4ml * Removed qkeras and tensorflow stuff. * Generate now takes only lbir. added stub functional equivalnce op checker. audio tests now use qonnx models, but are failing becouse of custom ops * Made fft into an PyOp disabled fft tests until qonnx is updated. * Commented out op with onnxrt-extensions. * Fixed linting issues. * Updated gh workflows for newly added audio option at installation. --------- Co-authored-by: jvreca <jure.vreca@ijs.si> Co-authored-by: Jure Vreca (jure.vreca@ijs.si <jvreca@jastreb.ijs.si>
1 parent 59acad3 commit 84db7df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+185
-2822
lines changed

.github/workflows/publish-to-pypi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Install python dependencies
3030
run: |
3131
python -m pip install --upgrade pip
32-
python -m pip install .[dev]
32+
python -m pip install .[dev,audio]
3333
3434
- name: Make protobuf
3535
run: make protobuf

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Install python dependencies
3636
run: |
3737
python -m pip install --upgrade pip
38-
python -m pip install .[dev]
38+
python -m pip install .[dev,audio]
3939
4040
- name: Setup JDK
4141
uses: actions/setup-java@v4
@@ -65,7 +65,7 @@ jobs:
6565
run: java -jar ./out/chisel4ml/assembly.dest/out.jar &> chisel4ml_sever.log &
6666

6767
- name: Lint
68-
run: flake8 -v --max-line-length=88 chisel4ml tests
68+
run: tox -e lint
6969

7070
- name: Run tests
7171
run: python -m pytest -x --use-verilator -n 4

chisel4ml/circuit.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
import numpy as np
1717

1818
import chisel4ml.lbir.services_pb2 as services
19-
from chisel4ml import transforms
2019
from chisel4ml.chisel4ml_server import Chisel4mlServer
2120
from chisel4ml.chisel4ml_server import connect_to_server
2221
from chisel4ml.lbir.qtensor_pb2 import QTensor
22+
from chisel4ml.transforms.numpy_transforms import numpy_to_qtensor
2323
from chisel4ml.transforms.qonnx_utils import qtensor_to_quantizer
2424

2525
log = logging.getLogger(__name__)
@@ -54,9 +54,7 @@ def __init__(
5454

5555
def __call__(self, np_arr, sim_timeout_sec=200):
5656
"Simulate the circuit, timeout in seconds."
57-
qtensors = transforms.numpy_transforms.numpy_to_qtensor(
58-
np_arr, self.input_quantizer, self.input_qtensor
59-
)
57+
qtensors = numpy_to_qtensor(np_arr, self.input_quantizer, self.input_qtensor)
6058
run_sim_params = services.RunSimulationParams(
6159
circuit_id=self.circuit_id, inputs=qtensors
6260
)

chisel4ml/generate.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@
1212
import logging
1313

1414
import numpy as np
15-
import tensorflow as tf
16-
import torch
1715
from ortools.sat.python import cp_model
18-
from qonnx.core.modelwrapper import ModelWrapper
1916

2017
from chisel4ml import chisel4ml_server
21-
from chisel4ml import transform
2218
from chisel4ml.accelerator import ACCELERATORS
2319
from chisel4ml.circuit import Circuit
20+
import chisel4ml.lbir.lbir_pb2 as lbir
2421
from chisel4ml.lbir.services_pb2 import Accelerator
2522
from chisel4ml.lbir.services_pb2 import GenerateCircuitParams
2623
from chisel4ml.lbir.services_pb2 import GenerateCircuitReturn
@@ -80,16 +77,12 @@ def solution_to_accelerators(solution, lbir_layers):
8077
return new_accels
8178

8279

83-
def accelerators(model, ishape=None, num_layers=None, minimize="area", debug=False):
84-
if isinstance(model, tf.keras.Model):
85-
qonnx_model = transform.qkeras_to_qonnx(model)
86-
elif isinstance(model, torch.nn.Module):
87-
qonnx_model = transform.brevitas_to_qonnx(model, ishape)
88-
elif isinstance(model, ModelWrapper):
89-
qonnx_model = model
90-
else:
91-
raise TypeError(f"Model of type {type(model)} not supported.")
92-
lbir_model = transform.qonnx_to_lbir(qonnx_model, debug=debug)
80+
def accelerators(lbir_model, num_layers=None, minimize="area"):
81+
if not isinstance(lbir_model, lbir.Model):
82+
raise TypeError(
83+
f"Model of type {type(lbir_model)} not supported. "
84+
"Please provide a LBIR model."
85+
)
9386
if num_layers is not None:
9487
assert num_layers <= len(lbir_model.layers)
9588
for _ in range(len(lbir_model.layers) - num_layers):
@@ -132,7 +125,7 @@ def accelerators(model, ishape=None, num_layers=None, minimize="area", debug=Fal
132125
assert solution_status in (cp_model.FEASIBLE, cp_model.OPTIMAL)
133126
solution = solution_collector.solution_list[0]
134127
accels = solution_to_accelerators(solution, lbir_model.layers)
135-
return accels, lbir_model
128+
return accels
136129

137130

138131
def circuit(

chisel4ml/optimizations/__init__.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

chisel4ml/optimizations/qkeras_bn_qdense_binary_fuse.py

Lines changed: 0 additions & 56 deletions
This file was deleted.

chisel4ml/optimizations/qkeras_bn_qdense_fuse.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

chisel4ml/optimizations/qkeras_optimization.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

chisel4ml/optimize.py

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)