Cannot constantFolding with an export backend
Required prerequisites
- Custom backend like "export_cmsis_nn" from aidge.export_arm_cortex_m or dummy of unit_test from !336
What commit version of aidge do you use
-
aidge_core
: 0.5.1
Problem description
You can't use the constantFolding() function when you have a different backend than cpu. An example is given in the unit test in MR !336 . Technically (i think), the forward between a “custom” backend and backend_cpu is supposed to remain the same. So I'm opening the discussion to a hybrid solution that can keep the “custom” backend while being able to execute a forward with the backend_cpu. In my case, this would allow me to use constant_folding without having to switch to backend_cpu.
[INFO] - Folding node Transpose_1 (of type Transpose)
[FATAL] - forward() not implemented yet for operator of type Transpose
Traceback (most recent call last):
File "/local2/is148265/wb274724/STM32_dev/dev/superpoint/aidge_test/aidge/aidge/aidge_export_arm_cortexm/test_cmsis_nn.py", line 193, in <module>
aidge_core.constant_folding(model)
RuntimeError: forward() not implemented yet for operator of type Transpose
Reproducible example code
import aidge_core
import numpy as np
from aidge_export_arm_cortexm.export_registry import ExportLibAidgeARM, ExportLibCMSISNN
SEED = 123
np.random.seed(SEED)
# PARAMETERS
INPUT_DIMS = [1, 3, 5, 5]
KERNEL_DIMS = [1, 1]
STRIDE_DIMS = [1, 1]
DILATION_DIMS = [1, 1]
IN_CHANNELS = 2
OUT_CHANNELS = 2
NO_BIAS = False
DATA_TYPE = aidge_core.dtype.int8
MIN_VAL = -128
MAX_VAL = 127
# INPUT
input_array = np.random.randint(MIN_VAL, MAX_VAL, size=INPUT_DIMS)
#Creation du model
model = aidge_core.sequential([
aidge_core.Producer(aidge_core.Tensor(dims=INPUT_DIMS), name="dataProvider"),
aidge_core.Conv2D(in_channels=3, out_channels=OUT_CHANNELS, kernel_dims=KERNEL_DIMS, name='conv', stride_dims=STRIDE_DIMS, dilation_dims=DILATION_DIMS, no_bias=NO_BIAS),
aidge_core.ReLU()
])
model.forward_dims(allow_data_dependency=True)
# Init weight
for n in model.get_nodes() :
print( "Node : " + str(n))
if n.type() == "Producer" and n.name() != "dataProvider":
dims = n.get_operator().get_output(0).dims()
print(dims)
array = np.random.randint(MIN_VAL, MAX_VAL, size=dims)
n.get_operator().set_output(0, aidge_core.Tensor(array))
# fuse
aidge_core.fuse_to_metaops(model, "Conv2D->ReLU", "PaddedConvScalingRelu")
# Set constant
for node in model.get_nodes():
if node.type() == "Producer" and node.name() != "dataProvider":
node.get_operator().attr.constant = True
# Set Backend
model.set_backend("export_cmsisnn")
aidge_core.adapt_to_backend(model)
# Constant Folding
aidge_core.constant_folding(model)
# Generate Scheduling
model.forward_dims( allow_data_dependency=True)
scheduler = aidge_core.SequentialScheduler(model)
scheduler.generate_scheduling()
scheduler.generate_memory()
print("DONE")