Skip to content

Commit

Permalink
Added revisions in accordance to the PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ranbir-sharma committed Sep 18, 2024
1 parent 1efd649 commit 7ad8293
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions bin/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ def readCompileOption():
assert 0 < bitWidth, "BitWidth must be a integer greater than 0"
assert math.log2(bitWidth).is_integer(), "BitWidth must be a exponent of power 2"
assert 0 <= minPercentileOutlierThreshold and minPercentileOutlierThreshold <= 100, "Minimum Percentile Value for Percentile should be greater than or equal to 0"
assert 0 <= maxPercentileOutlierThreshold and maxPercentileOutlierThreshold <= 100, "Maximum Percentile Value for Percentile should be greater than or equal to 0 and lesser than or equal to 100"
assert minPercentileOutlierThreshold <= maxPercentileOutlierThreshold, "Minimum Percentile Value should be lesser than Maximum Percentile Value"
assert 0 <= maxPercentileOutlierThreshold and maxPercentileOutlierThreshold <= 100, "Maximum Percentile Value for Percentile should be greater than or equal to 0 and less than or equal to 100"
assert minPercentileOutlierThreshold <= maxPercentileOutlierThreshold, "Minimum Percentile Value should be less than Maximum Percentile Value"

global fakeQuant
fakeQuant = [targetLayer, minPercentileOutlierThreshold, maxPercentileOutlierThreshold, bitWidth]
Expand Down
4 changes: 2 additions & 2 deletions docs/input_masterlist_ml.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ compileOption:
bitWidth: 8


# Fake Qunatization parameters comes within compileOption. In here, you need to mention the targer layer - conv or matmul (currently only supporting these)
# Fake Quantization parameters comes within compileOption. In here, you need to mention the targer layer - conv or matmul (currently only supporting these)
# minPercentileOutlierThreshold and maxPercentileOutlierThreshold are optional parameters. On not mentioning these parameters, they are autoamtically set to
# minPercentileOutlierThreshold = 0 and maxPercentileOutlierThreshold = 100
# bitWidth needs to be mentioned and is the bit width of the Quantized Int numbers which needs to be a exponent of power 2
# bitWidth needs to be mentioned and is the bit width of the Quantized Int numbers which needs to be a exponent of power 2
9 changes: 4 additions & 5 deletions llvm_passes/core/FakeQuantizationPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <unordered_set>

#include "llvm/Support/CommandLine.h"
// #include "Controller.h"

using namespace llvm;
using namespace std;
Expand Down Expand Up @@ -262,8 +261,8 @@ namespace llfi
"FakeQuantIntegerBasedAddition", Type::getFloatTy(Context), Type::getFloatTy(Context),
Type::getFloatTy(Context));

FunctionCallee FakeQunatDequnatizeAndBiasAdditionFunction = M->getOrInsertFunction(
"FakeQunatDequnatizeAndBiasAddition", Type::getFloatTy(Context), Type::getFloatTy(Context),
FunctionCallee FakeQunatDequantizeAndBiasAdditionFunction = M->getOrInsertFunction(
"FakeQunatDequantizeAndBiasAddition", Type::getFloatTy(Context), Type::getFloatTy(Context),
Type::getFloatTy(Context));

bool foundLayerDef = false;
Expand Down Expand Up @@ -329,7 +328,7 @@ namespace llfi


// Replacing the old float to new float obtained from Fake
// Qunatization
// Quantization
op->replaceAllUsesWith(newInst);
deleteInst.insert(op);
}
Expand All @@ -343,7 +342,7 @@ namespace llfi
Value *op1 = op->getOperand(0);
Value *op2 = op->getOperand(1);

Value *newInst = Builder.CreateCall(FakeQunatDequnatizeAndBiasAdditionFunction, {op1, op2});
Value *newInst = Builder.CreateCall(FakeQuantDequnatizeAndBiasAdditionFunction, {op1, op2});
op->replaceAllUsesWith(newInst);
deleteInst.insert(op);
}
Expand Down
2 changes: 1 addition & 1 deletion llvm_passes/core/FakeQuantizationPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ std::string getOperandName(llvm::Instruction *I);

} // namespace llfi

#endif // LLFI_H
#endif // LLFI_H
6 changes: 3 additions & 3 deletions runtime_lib/FakeQuantizationLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,12 @@ float Quantize(float w1, float x1, int currentLayerIndex, int totalNumberOfLayer
}
}

void finished(int currentLayerIndex, int totalNumberOfLayers, int minPercentileThreshold, int maxPercetileThreshold, int bitWidth)
void finished(int currentLayerIndex, int totalNumberOfLayers, int minPercentileThreshold, int maxPercentileThreshold, int bitWidth)
{
bit_width = bitWidth;
max_number = 2 ^ bit_width;
printf("In this Layer - %i\n", currentLayerIndex);
FindPercentile(minPercentileThreshold, maxPercetileThreshold);
FindPercentile(minPercentileThreshold, maxPercentileThreshold);
printf("Got called in finished!\n");
printf("Index for w %i and Index for x %i\n", w_index, x_index);
printf("Actual Min for x %f and Actual Max %f\n", x_values[0], x_values[x_index - 1]);
Expand Down Expand Up @@ -402,7 +402,7 @@ float FakeQuantIntegerBasedAddition(float num1, float num2)
return (float)(intNum1 + intNum2);
}

float FakeQunatDequnatizeAndBiasAddition(float QunatizeNum, float Basis)
float FakeQuantDequantizeAndBiasAddition(float QunatizeNum, float Basis)
{
int QunatizeIntNum = (int)QunatizeNum;
float dequnatizedFloat = dequantize(QunatizeIntNum);
Expand Down
6 changes: 3 additions & 3 deletions runtime_lib/FakeQuantizationLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
extern "C" {
#endif
float getWAndX(float w1, float x1, int currentLayerIndex, int totalNumberOfLayers);
void finished(int currentLayerIndex, int totalNumberOfLayers, int minPercentileThreshold, int maxPercetileThreshold, int bitWidth);
void finished(int currentLayerIndex, int totalNumberOfLayers, int minPercentileThreshold, int maxPercentileThreshold, int bitWidth);
float dequantize(int q);
float Quantize(float w1, float x1, int currentLayerIndex, int totalNumberOfLayers);
float QuantizeMatMul(float w1, float x1, int currentLayerIndex, int totalNumberOfLayers);
float FakeQuantIntegerBasedAddition(float num1, float num2);
float FakeQunatDequnatizeAndBiasAddition(float num1, float num2);
float FakeQuantDequantizeAndBiasAddition(float num1, float num2);
void getBias(float a, float b);
#ifdef __cplusplus
}
#endif

#endif // FAKE_QUANTIZATION_H
#endif // FAKE_QUANTIZATION_H

0 comments on commit 7ad8293

Please sign in to comment.