Skip to content

Commit

Permalink
Added the code for FakeQuantization project
Browse files Browse the repository at this point in the history
  • Loading branch information
ranbir-sharma committed Sep 3, 2024
1 parent 4edbf12 commit 7ce8f48
Show file tree
Hide file tree
Showing 7 changed files with 1,050 additions and 6 deletions.
20 changes: 20 additions & 0 deletions bin/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
# basedir is assigned in parseArgs(args)
basedir = ""

fakeQuant = None

# llfibd = os.path.join(basedir, "llfi")
# if os.path.exists(llfibd):
# shutil.rmtree(llfibd)
Expand Down Expand Up @@ -317,6 +319,14 @@ def readCompileOption():
if (str(cOpt["tracingPropagationOption"]["generateCDFG"]).lower() == "true"):
options["genDotGraph"] = True

if 'fakeQuant' in cOpt and (cOpt['fakeQuant']['targetLayer'] == 'conv' or cOpt['fakeQuant']['targetLayer'] == 'matmul'):
minPercentileOutlierThreshold = cOpt['fakeQuant'].get('minPercentileOutlierThreshold', 0)
maxPercentileOutlierThreshold = cOpt['fakeQuant'].get('maxPercentileOutlierThreshold', 100)
bitWidth = cOpt['fakeQuant'].get('bitWidth')

global fakeQuant
fakeQuant = [cOpt['fakeQuant']['targetLayer'], minPercentileOutlierThreshold, maxPercentileOutlierThreshold, bitWidth]

################################################################################
def _suffixOfIR():
if options["readable"]:
Expand Down Expand Up @@ -351,6 +361,12 @@ def compileProg():
execlist.append("-S")
if options["enableMLFIStats"]:
execlist.append("-mlfistats")
if fakeQuant != None:
execlist.append(f'-fakeQuant={fakeQuant[0]}')
execlist.append(f'-minPercentileThreshold={fakeQuant[1]}')
execlist.append(f'-maxPercentileThreshold={fakeQuant[2]}')
execlist.append(f'-bitWidth={fakeQuant[3]}')

retcode = execCompilation(execlist)

if retcode == 0:
Expand All @@ -361,6 +377,10 @@ def compileProg():
#print(execlist)
if options["readable"]:
execlist.append("-S")
if fakeQuant != None:
print("Executed 2")
execlist.append(f'-fakeQuant={fakeQuant[0]}')

retcode = execCompilation(execlist)

if retcode != 0:
Expand Down
Loading

0 comments on commit 7ce8f48

Please sign in to comment.