diff --git a/src/PTQ/CLE.cpp b/src/PTQ/CLE.cpp index 30ddc9e4d0c44f0be66d4cdb880dad414a52927f..33cf14667de7121f93d2804d66e6c8037b643f81 100644 --- a/src/PTQ/CLE.cpp +++ b/src/PTQ/CLE.cpp @@ -57,7 +57,7 @@ static bool nodeHasBias(std::shared_ptr<Node> node) std::shared_ptr<Aidge::Tensor> getScaledWeightTensor(std::shared_ptr<Node> node) { - if (node->getParent(1)->attributes()->hasAttr("quantization.ptq.isProducerScaling")) + if (node->getParent(1)->attributes()->hasAttr("quantization.ptq.isProducerQuantizer")) { auto quantizer = node->getParent(1); diff --git a/src/PTQ/Clipping.cpp b/src/PTQ/Clipping.cpp index 7dd02b3df7b84559db36b46803700408dbd9c9c6..c54bfb07eb303b3a5aacad45914179b7aa10245e 100644 --- a/src/PTQ/Clipping.cpp +++ b/src/PTQ/Clipping.cpp @@ -212,7 +212,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.isActivationScaling")) + if (node->attributes()->hasAttr("quantization.ptq.isActivationQuantizer")) { std::vector<int> histogram = histograms[node]; diff --git a/src/PTQ/PTQ.cpp b/src/PTQ/PTQ.cpp index 95be899a1b29c5885f19611819b8660f08e7864e..a99dc179c35a785fc1a66fb92fe681cd641dacf1 100644 --- a/src/PTQ/PTQ.cpp +++ b/src/PTQ/PTQ.cpp @@ -240,7 +240,7 @@ void foldProducerQuantizers(std::shared_ptr<GraphView> graphView) { std::vector<std::shared_ptr<Node>> producerQuantizers; for (std::shared_ptr<Node> node : graphView->getNodes()) - if (hasAttr(node, "isProducerScaling")) + if (hasAttr(node, "isProducerQuantizer")) producerQuantizers.push_back(node); for (std::shared_ptr<Node> quantizer : producerQuantizers) @@ -298,12 +298,12 @@ void castQuantizedNetwork(std::shared_ptr<GraphView> graphView, Aidge::DataType { if (node->type() == "Quantizer") { - if (hasAttr(node, "isActivationScaling")) + if (hasAttr(node, "isActivationQuantizer")) { removeRound(node); replaceScalingWithBitShift(node); } - else if (hasAttr(node, "isProducerScaling")) + else if (hasAttr(node, "isProducerQuantizer")) castQuantizerIOs(node, targetType); } } @@ -311,7 +311,7 @@ void castQuantizedNetwork(std::shared_ptr<GraphView> graphView, Aidge::DataType // Cast the nodes (excepted the producers and quantizers) to integer precision nodes = graphView->getNodes(); for (std::shared_ptr<Node> node : nodes) - if (node->type() != "Producer" && !hasAttr(node, "isProducerScaling")) // TODO : double check this ! + if (node->type() != "Producer" && !hasAttr(node, "isProducerQuantizer")) // TODO : double check this ! node->getOperator()->setDataType(targetType); } else @@ -423,7 +423,7 @@ std::vector<std::shared_ptr<Node>> retrieveNodeVector(std::shared_ptr<GraphView> std::vector<std::shared_ptr<Node>> remainingNodes; for (std::shared_ptr<Node> node : nodeVector) - if ((node->type() != "Producer") && !hasAttr(node, "isProducerScaling")) + if ((node->type() != "Producer") && !hasAttr(node, "isProducerQuantizer")) remainingNodes.push_back(node); nodeVector = remainingNodes; @@ -467,7 +467,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, "isActivationScaling")) { + while(!hasAttr(currNode, "isActivationQuantizer")) { if (currNode->getParents().size() == 0) { Log::warn(" Warning : No previous Scaling node were found ! "); break; @@ -481,7 +481,7 @@ void insertScalingBelowProducer(std::shared_ptr<Node> producerNode, std::shared_ { std::string scalingNodeName = makeUniqueName(producerNode->name() + "_ProducerScaling", graphView); std::shared_ptr<Node> scalingNode = Quantizer(1.0, scalingNodeName);; - addAttr(scalingNode, "isProducerScaling"); + addAttr(scalingNode, "isProducerQuantizer"); scalingNode->getOperator()->setDataType(DataType::Float64); // getDataType(parentNode) scalingNode->getOperator()->setBackend(determineBackend(producerNode)); // XXX use the producer parent instead ??? @@ -530,10 +530,9 @@ void insertResidualScalingNodes(std::shared_ptr<GraphView> graphView) std::string residualNodeName = makeUniqueName(parentNode->name() + "_Res", graphView); - // XXX XXX XXX + // XXX std::shared_ptr<Node> residualNode = Quantizer(1.0, residualNodeName); - addAttr(residualNode, "isActivationScaling"); - // XXX addAttr(residualNode, "isResidual"); + addAttr(residualNode, "isActivationQuantizer"); residualNode->getOperator()->setDataType(DataType::Float64); // getDataType(parentNode) residualNode->getOperator()->setBackend(determineBackend(parentNode)); @@ -562,7 +561,7 @@ void insertScalingNodes(std::shared_ptr<GraphView> graphView) // XXX XXX XXX std::shared_ptr<Node> scalingNode = Quantizer(1.0, scalingNodeName); - addAttr(scalingNode, "isActivationScaling"); + addAttr(scalingNode, "isActivationQuantizer"); scalingNode->getOperator()->setDataType(DataType::Float64); // getDataType(parentNode) scalingNode->getOperator()->setBackend(determineBackend(parentNode)); @@ -583,7 +582,7 @@ void insertScalingNodes(std::shared_ptr<GraphView> graphView) // XXX XXX XXX std::shared_ptr<Node> prevScalingNode = Quantizer(1.0, prevScalingNodeName); - addAttr(prevScalingNode, "isActivationScaling"); + addAttr(prevScalingNode, "isActivationQuantizer"); prevScalingNode->getOperator()->setDataType(DataType::Float64); // getDataType(parentNode) prevScalingNode->getOperator()->setBackend(determineBackend(parentNode)); @@ -611,7 +610,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, "isActivationScaling") || isSeamless(node)) + if (node->type() == "ReLU" || hasAttr(node, "isActivationQuantizer") || isSeamless(node)) { if (node != firstNode) { @@ -723,7 +722,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, "isActivationScaling")) || (!scalingNodesOnly && (node->type() != "Producer"))) + if ((scalingNodesOnly && hasAttr(node, "isActivationQuantizer")) || (!scalingNodesOnly && (node->type() != "Producer"))) valueRanges.insert(std::make_pair(node, 0)); if (useCuda) @@ -750,7 +749,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, "isActivationScaling")) || (!scalingNodesOnly && (node->type() != "Producer"))) + if ((scalingNodesOnly && hasAttr(node, "isActivationQuantizer")) || (!scalingNodesOnly && (node->type() != "Producer"))) { std::shared_ptr<Operator> nodeOperator = node->getOperator(); std::shared_ptr<Tensor> valueTensor = std::static_pointer_cast<Tensor> (nodeOperator->getRawOutput(0)); @@ -772,7 +771,7 @@ std::unordered_map<std::shared_ptr<Node>, double> computeRanges(std::shared_ptr< for (std::shared_ptr<Node> node : nodeSet) { - if ((scalingNodesOnly && hasAttr(node, "isActivationScaling")) || (!scalingNodesOnly && (node->type() != "Producer"))) + if ((scalingNodesOnly && hasAttr(node, "isActivationQuantizer")) || (!scalingNodesOnly && (node->type() != "Producer"))) if (sampleRanges[node] > valueRanges[node]) valueRanges[node] = sampleRanges[node]; } @@ -818,7 +817,7 @@ void normalizeActivations(std::shared_ptr<GraphView> graphView, std::unordered_m // Use the Scaling nodes to rescale the ranges ... - if (hasAttr(node, "isActivationScaling")) + if (hasAttr(node, "isActivationQuantizer")) { std::shared_ptr<Node> prevNode = node->getParent(0); @@ -917,7 +916,7 @@ std::unordered_map<std::shared_ptr<Node>, std::pair<bool, bool>> computeSignMap( signMap[node].second = false; } - if (hasAttr(node, "isActivationScaling")) + if (hasAttr(node, "isActivationQuantizer")) { signMap[node].second = false; @@ -964,7 +963,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, "isActivationScaling")) + while (!hasAttr(parent, "isActivationQuantizer")) { signMap[parent] = std::make_pair(false, false); // We are on a branch so nodes always have 1 parent ... @@ -1111,7 +1110,7 @@ void quantizeNormalizedNetwork(std::shared_ptr<GraphView> graphView, std::uint8_ // Handle the Scaling Nodes ... - if (hasAttr(node, "isActivationScaling")) + if (hasAttr(node, "isActivationQuantizer")) { // Don't touch the scalings that precede non-linearities ... @@ -1245,7 +1244,7 @@ void performSingleShiftApproximation(std::shared_ptr<GraphView> graphView) static void printScalingFactors(std::shared_ptr<GraphView> graphView) { for (auto node : retrieveNodeVector(graphView)) - if (hasAttr(node, "isActivationScaling") || node->type() == "Quantizer") + if (hasAttr(node, "isActivationQuantizer") || node->type() == "Quantizer") { double scalingFactor = getScalingFactor(node); Log::notice(" SCALING FACTOR : {} ({})", scalingFactor, node->name()); diff --git a/src/operator/PTQMetaOps.cpp b/src/operator/PTQMetaOps.cpp index a9fad64897a6777b89e3d4fc6165f0fbbfcd8934..0f59d842a9b70ab14bea798d4a19d2938899ab0e 100644 --- a/src/operator/PTQMetaOps.cpp +++ b/src/operator/PTQMetaOps.cpp @@ -48,11 +48,11 @@ static void addAttr(std::shared_ptr<Aidge::Node> node, std::string attr, double // XXX TODO : rework this static void copyDynamicAttributes(std::shared_ptr<Aidge::Node> prevNode, std::shared_ptr<Aidge::Node> newNode) { - if (hasAttr(prevNode, "isProducerScaling")) - addAttr(newNode, "isProducerScaling"); + if (hasAttr(prevNode, "isProducerQuantizer")) + addAttr(newNode, "isProducerQuantizer"); - if (hasAttr(prevNode, "isActivationScaling")) - addAttr(newNode, "isActivationScaling"); + if (hasAttr(prevNode, "isActivationQuantizer")) + addAttr(newNode, "isActivationQuantizer"); } std::shared_ptr<Node> Quantizer(double scalingFactor, const std::string& name)