Skip to content
Snippets Groups Projects
Commit 71027f81 authored by Axel Farrugia's avatar Axel Farrugia
Browse files

[Refactor] New way to handle how scaling data is retrieved from the Producers...

[Refactor] New way to handle how scaling data is retrieved from the Producers within the export nodes : set_scaling_attributes() function.
parent 9700c2d9
No related branches found
No related tags found
No related merge requests found
import aidge_core
from aidge_core.export_utils import ExportNodeCpp
from aidge_export_cpp import ROOT
from aidge_export_cpp import ExportLibCpp
from aidge_export_cpp import ROOT, ExportLibCpp, set_scaling_attributes
@ExportLibCpp.register_metaop("CppActivation", aidge_core.ImplSpec(aidge_core.IOSpec(aidge_core.dtype.any)))
class CppActivation(ExportNodeCpp):
......@@ -21,17 +20,8 @@ class CppActivation(ExportNodeCpp):
for n in node.get_operator().get_micro_graph().get_nodes():
if n.type() == "ReLU":
self.attributes["activation"] = "Rectifier"
## Get the scaling values
for prod in node.get_parents():
if prod is not None:
if prod.type() == "Producer":
if prod.attributes().has_attr("quantization.ptq.ShiftAmount"):
self.attributes["shift_value"] = prod.attributes().quantization.ptq.ShiftAmount
# elif prod.attributes().has_attr("quantization.ptq.CompensationCoeff"):
# self.attributes["coef_value"] = prod.attributes().quantization.ptq.CompensationCoeff
else:
self.attributes["coef_value"] = prod.get_operator().get_output(0)[0]
elif n.type() == "Quantizer":
set_scaling_attributes(self, n)
## Set the scaling type
if self.attributes["coef_value"] != 1:
......
import aidge_core
from aidge_core.export_utils import ExportNodeCpp
from aidge_export_cpp import ROOT
from aidge_export_cpp import ExportLibCpp
from aidge_export_cpp import ROOT, ExportLibCpp, set_scaling_attributes
@ExportLibCpp.register_metaop("CppConv", aidge_core.ImplSpec(aidge_core.IOSpec(aidge_core.dtype.any)))
class CppConv(ExportNodeCpp):
......@@ -27,13 +26,8 @@ class CppConv(ExportNodeCpp):
self.attributes["kernel_dims"] = n.get_operator().attr.kernel_dims
self.attributes["stride_dims"] = n.get_operator().attr.stride_dims
self.attributes["dilation_dims"] = n.get_operator().attr.dilation_dims
## Get the scaling values
for prod in node.get_parents():
if prod is not None:
if prod.type() == "Producer":
if prod.attributes().has_attr("quantization.ptq.ShiftAmount"):
self.attributes["shift_value"] = prod.attributes().quantization.ptq.ShiftAmount
elif n.type() == "Quantizer":
set_scaling_attributes(self, n)
## Set the scaling type
if self.attributes["shift_value"] != 0:
......
import aidge_core
from aidge_core.export_utils import ExportNodeCpp
from aidge_export_cpp import ROOT
from aidge_export_cpp import ExportLibCpp
from aidge_export_cpp import set_scaling_attributes
from aidge_export_cpp import ROOT, ExportLibCpp, set_scaling_attributes
@ExportLibCpp.register_metaop("CppElemWise", aidge_core.ImplSpec(aidge_core.IOSpec(aidge_core.dtype.any)))
class CppElemWise(ExportNodeCpp):
......@@ -27,17 +25,6 @@ class CppElemWise(ExportNodeCpp):
elif n.type() == "Quantizer":
set_scaling_attributes(self, n)
## Get the scaling values
# for node in node.get_parents():
# if node is not None:
# if node.type() == "Producer":
# if node.attributes().has_attr("quantization.ptq.ShiftAmount"):
# self.attributes["shift_value"] = node.attributes().quantization.ptq.ShiftAmount
# # elif node.attributes().has_attr("quantization.ptq.CompensationCoeff"):
# # self.attributes["coef_value"] = node.attributes().quantization.ptq.CompensationCoeff
# else:
# self.attributes["coef_value"] = node.get_operator().get_output(0)[0]
## Set the scaling type
if self.attributes["coef_value"] != 1:
self.attributes["rescaling"] = "FixedPointScaling"
......
import aidge_core
from aidge_core.export_utils import ExportNodeCpp
from aidge_export_cpp import ROOT
from aidge_export_cpp import ExportLibCpp
from aidge_export_cpp import ROOT, ExportLibCpp, set_scaling_attributes
@ExportLibCpp.register_metaop("CppFc", aidge_core.ImplSpec(aidge_core.IOSpec(aidge_core.dtype.any)))
class CppFc(ExportNodeCpp):
......@@ -25,13 +24,8 @@ class CppFc(ExportNodeCpp):
for n in node.get_operator().get_micro_graph().get_nodes():
if n.type() == "ReLU":
self.attributes["activation"] = "Rectifier"
## Get the scaling values
for prod in node.get_parents():
if prod is not None:
if prod.type() == "Producer":
if prod.attributes().has_attr("quantization.ptq.ShiftAmount"):
self.attributes["shift_value"] = prod.attributes().quantization.ptq.ShiftAmount
elif n.type() == "Quantizer":
set_scaling_attributes(self, n)
## Set the scaling type
if self.attributes["shift_value"] != 0:
......
import aidge_core
from aidge_core.export_utils import ExportNodeCpp
from aidge_export_cpp import ROOT
from aidge_export_cpp import ExportLibCpp
from aidge_export_cpp import ROOT, ExportLibCpp, set_scaling_attributes
@ExportLibCpp.register_metaop("CppRescaling", aidge_core.ImplSpec(aidge_core.IOSpec(aidge_core.dtype.any)))
@ExportLibCpp.register_metaop("Quantizer", aidge_core.ImplSpec(aidge_core.IOSpec(aidge_core.dtype.any)))
class CppRescaling(ExportNodeCpp):
def __init__(self, node, mem_info):
super().__init__(node, mem_info)
......@@ -14,23 +13,13 @@ class CppRescaling(ExportNodeCpp):
self.attributes["shift_value"] = 0
self.attributes["coef_value"] = 1
# Browse the metaop to update kernel attributes
for n in node.get_operator().get_micro_graph().get_nodes():
if n.type() == "ReLU":
self.attributes["activation"] = "Rectifier"
## Get the scaling values
for prod in node.get_parents():
if prod is not None:
if prod.type() == "Producer":
if prod.attributes().has_attr("quantization.ptq.ShiftAmount"):
self.attributes["shift_value"] = prod.attributes().quantization.ptq.ShiftAmount
# elif prod.attributes().has_attr("quantization.ptq.CompensationCoeff"):
# self.attributes["coef_value"] = prod.attributes().quantization.ptq.CompensationCoeff
else:
self.attributes["coef_value"] = prod.get_operator().get_output(0)[0]
# Set scaling attributes
set_scaling_attributes(self, node)
## Set the scaling type
if self.attributes["coef_value"] != 1:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment