Skip to content
Snippets Groups Projects
Commit 0322debe authored by Benjamin Halimi's avatar Benjamin Halimi
Browse files

replace 'isScaling' with 'isActivationScaling'

parent d823d61b
No related branches found
No related tags found
2 merge requests!54Update 0.3.1 -> 0.4.0,!50Enhancement : Quantizer only PTQ
Pipeline #69874 failed
......@@ -222,7 +222,7 @@ std::unordered_map<std::shared_ptr<Node>, double> adjustRanges(Clipping clipping
for (std::shared_ptr<Node> node : graphView->getNodes())
{
if (node->attributes()->hasAttr("quantization.ptq.isScaling"))
if (node->attributes()->hasAttr("quantization.ptq.isActivationScaling"))
{
std::vector<int> histogram = histograms[node];
......
......@@ -368,7 +368,7 @@ static bool nodeHasBias(std::shared_ptr<Node> node)
static std::shared_ptr<Node> getPreviousScalingNode(std::shared_ptr<Node> node)
{
std::shared_ptr<Node> currNode = node;
while(!hasAttr(currNode, "isScaling")) {
while(!hasAttr(currNode, "isActivationScaling")) {
if (currNode->getParents().size() == 0) {
Log::warn(" Warning : No previous Scaling node were found ! ");
break;
......@@ -383,7 +383,7 @@ void insertScalingBelowProducer(std::shared_ptr<Node> producerNode, std::shared_
std::string scalingNodeName = makeUniqueName(producerNode->name() + "_ProducerScaling", graphView);
std::shared_ptr<Node> scalingNode = BaseQuantizer(1.0, scalingNodeName);;
addAttr(scalingNode, "isProducerScaling");
// XXX XXX XXX addAttr(scalingNode, "isScaling") ? NO !!!
// XXX XXX XXX addAttr(scalingNode, "isActivationScaling") ? NO !!!
scalingNode->getOperator()->setDataType(DataType::Float64); // getDataType(parentNode)
scalingNode->getOperator()->setBackend(determineBackend(producerNode)); // XXX use the producer parent instead ???
......@@ -434,7 +434,7 @@ void insertResidualScalingNodes(std::shared_ptr<GraphView> graphView)
// XXX XXX XXX
std::shared_ptr<Node> residualNode = BaseQuantizer(1.0, residualNodeName);
addAttr(residualNode, "isScaling");
addAttr(residualNode, "isActivationScaling");
addAttr(residualNode, "isResidual");
residualNode->getOperator()->setDataType(DataType::Float64); // getDataType(parentNode)
......@@ -464,7 +464,7 @@ void insertScalingNodes(std::shared_ptr<GraphView> graphView)
// XXX XXX XXX
std::shared_ptr<Node> scalingNode = BaseQuantizer(1.0, scalingNodeName);
addAttr(scalingNode, "isScaling");
addAttr(scalingNode, "isActivationScaling");
scalingNode->getOperator()->setDataType(DataType::Float64); // getDataType(parentNode)
scalingNode->getOperator()->setBackend(determineBackend(parentNode));
......@@ -485,7 +485,7 @@ void insertScalingNodes(std::shared_ptr<GraphView> graphView)
// XXX XXX XXX
std::shared_ptr<Node> prevScalingNode = BaseQuantizer(1.0, prevScalingNodeName);
addAttr(prevScalingNode, "isScaling");
addAttr(prevScalingNode, "isActivationScaling");
prevScalingNode->getOperator()->setDataType(DataType::Float64); // getDataType(parentNode)
prevScalingNode->getOperator()->setBackend(determineBackend(parentNode));
......@@ -513,7 +513,7 @@ void normalizeParameters(std::shared_ptr<GraphView> graphView)
for (std::shared_ptr<Node> node : nodeVector)
{
// Scaling nodes still have a ratio of 1, so they are seamless ...
if (node->type() == "ReLU" || hasAttr(node, "isScaling") || isSeamless(node))
if (node->type() == "ReLU" || hasAttr(node, "isActivationScaling") || isSeamless(node))
{
if (node != firstNode)
{
......@@ -634,7 +634,7 @@ std::unordered_map<std::shared_ptr<Node>, double> computeRanges(std::shared_ptr<
std::set<std::shared_ptr<Node>> nodeSet = graphView->getNodes();
for (std::shared_ptr<Node> node : nodeSet)
{
if ((scalingNodesOnly && hasAttr(node, "isScaling")) || (!scalingNodesOnly && (node->type() != "Producer")))
if ((scalingNodesOnly && hasAttr(node, "isActivationScaling")) || (!scalingNodesOnly && (node->type() != "Producer")))
{
std::shared_ptr<Operator> nodeOperator = node->getOperator();
std::shared_ptr<Tensor> valueTensor = std::static_pointer_cast<Tensor> (nodeOperator->getRawOutput(0));
......@@ -656,7 +656,7 @@ std::unordered_map<std::shared_ptr<Node>, double> computeRanges(std::shared_ptr<
// std::shared_ptr<Node> inputNode = getFirstNode(graphView);
for (std::shared_ptr<Node> node : nodeSet)
if ((scalingNodesOnly && hasAttr(node, "isScaling")) || (!scalingNodesOnly && (node->type() != "Producer")))
if ((scalingNodesOnly && hasAttr(node, "isActivationScaling")) || (!scalingNodesOnly && (node->type() != "Producer")))
valueRanges.insert(std::make_pair(node, 0));
if (useCuda)
......@@ -683,7 +683,7 @@ std::unordered_map<std::shared_ptr<Node>, double> computeRanges(std::shared_ptr<
std::unordered_map<std::shared_ptr<Node>, double> sampleRanges;
for (std::shared_ptr<Node> node : nodeSet)
{
if ((scalingNodesOnly && hasAttr(node, "isScaling")) || (!scalingNodesOnly && (node->type() != "Producer")))
if ((scalingNodesOnly && hasAttr(node, "isActivationScaling")) || (!scalingNodesOnly && (node->type() != "Producer")))
{
std::shared_ptr<Operator> nodeOperator = node->getOperator();
std::shared_ptr<Tensor> valueTensor = std::static_pointer_cast<Tensor> (nodeOperator->getRawOutput(0));
......@@ -705,7 +705,7 @@ std::unordered_map<std::shared_ptr<Node>, double> computeRanges(std::shared_ptr<
for (std::shared_ptr<Node> node : nodeSet)
{
if ((scalingNodesOnly && hasAttr(node, "isScaling")) || (!scalingNodesOnly && (node->type() != "Producer")))
if ((scalingNodesOnly && hasAttr(node, "isActivationScaling")) || (!scalingNodesOnly && (node->type() != "Producer")))
if (sampleRanges[node] > valueRanges[node])
valueRanges[node] = sampleRanges[node];
}
......@@ -751,7 +751,7 @@ void normalizeActivations(std::shared_ptr<GraphView> graphView, std::unordered_m
// Use the Scaling nodes to rescale the ranges ...
if (hasAttr(node, "isScaling"))
if (hasAttr(node, "isActivationScaling"))
{
std::shared_ptr<Node> prevNode = node->getParent(0);
......@@ -850,7 +850,7 @@ std::unordered_map<std::shared_ptr<Node>, std::pair<bool, bool>> computeSignMap(
signMap[node].second = false;
}
if (hasAttr(node, "isScaling"))
if (hasAttr(node, "isActivationScaling"))
{
signMap[node].second = false;
......@@ -897,7 +897,7 @@ std::unordered_map<std::shared_ptr<Node>, std::pair<bool, bool>> computeSignMap(
// Arbitration : Signed type wins !
for(std::shared_ptr<Node> parent : parentNodes)
{
while (!hasAttr(parent, "isScaling"))
while (!hasAttr(parent, "isActivationScaling"))
{
signMap[parent] = std::make_pair(false, false);
// We are on a branch so nodes always have 1 parent ...
......@@ -1044,7 +1044,7 @@ void quantizeNormalizedNetwork(std::shared_ptr<GraphView> graphView, std::uint8_
// Handle the Scaling Nodes ...
if (hasAttr(node, "isScaling"))
if (hasAttr(node, "isActivationScaling"))
{
// Don't touch the scalings that precede non-linearities ...
......@@ -1177,7 +1177,7 @@ static void performSingleShiftApproximation(std::shared_ptr<GraphView> graphView
static void printScalingFactors(std::shared_ptr<GraphView> graphView)
{
for (auto node : retrieveNodeVector(graphView))
if (hasAttr(node, "isScaling") || node->type() == "BaseQuantizer")
if (hasAttr(node, "isActivationScaling") || node->type() == "BaseQuantizer")
{
double scalingFactor = getScalingFactor(node);
Log::notice(" SCALING FACTOR : {} ({})", scalingFactor, node->name());
......@@ -1217,7 +1217,7 @@ void quantizeNetwork(std::shared_ptr<GraphView> graphView, std::uint8_t nbBits,
Log::notice(" Inserting the scaling nodes ...");
insertScalingNodes(graphView);
// TODO : double check this !
// TODO : double check the CLE ...
crossLayerEqualization(graphView);
Log::notice(" Normalizing the parameters ...");
......@@ -1255,9 +1255,6 @@ void quantizeNetwork(std::shared_ptr<GraphView> graphView, std::uint8_t nbBits,
scheduler.resetScheduling();
Log::notice(" Network is quantized !");
// XXX XXX XXX
printScalingFactors(graphView);
}
std::unordered_map<std::string, double> getWeightRanges(std::shared_ptr<GraphView> graphView)
......
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