ONE - On-device Neural Engine
Loading...
Searching...
No Matches
QErrorComputer.QErrorComputer Class Reference

Public Member Functions

 __init__ (self, fp32_dir, fq_dir)
 
 collect_data_path (self, fp32_dir, fq_dir)
 
 run (self)
 

Data Fields

 qerror_map
 

Protected Attributes

 _fp32_dir
 
 _fq_dir
 
 _num_processed_data
 
 _num_data
 
 _tid_to_tname
 

Detailed Description

Definition at line 24 of file QErrorComputer.py.

Constructor & Destructor Documentation

◆ __init__()

QErrorComputer.QErrorComputer.__init__ (   self,
  fp32_dir,
  fq_dir 
)

Reimplemented in QErrorComputer.MPEIRComputer, QErrorComputer.MSEComputer, QErrorComputer.TAEComputer, and QErrorComputer.SRMSEComputer.

Definition at line 25 of file QErrorComputer.py.

25 def __init__(self, fp32_dir, fq_dir):
26 self._fp32_dir = fp32_dir
27 self._fq_dir = fq_dir
28 self.qerror_map = defaultdict(float)
29 self._num_processed_data = 0
30

Member Function Documentation

◆ collect_data_path()

QErrorComputer.QErrorComputer.collect_data_path (   self,
  fp32_dir,
  fq_dir 
)

Definition at line 31 of file QErrorComputer.py.

31 def collect_data_path(self, fp32_dir, fq_dir):
32 # Assumption: FM data are saved as follows
33 #
34 # fp32_dir/
35 # tensors.json
36 # <DATA_INDEX>/
37 # <TENSOR_ID>.npy
38 #
39 # fq_dir/
40 # tensors.json
41 # <DATA_INDEX>/
42 # <TENSOR_ID>.npy
43 #
44 # NOTE tensors.json has a dictionary {TENSOR_NAME -> TENSOR_ID}
45 self._num_data = len(list(filter(os.path.isdir, glob.glob(fp32_dir + '/*'))))
46 if self._num_data != len(list(filter(os.path.isdir, glob.glob(fq_dir + '/*')))):
47 raise RuntimeError("Number of data mistmatches")
48
49 self._num_processed_data += self._num_data
50
51 self._tid_to_tname = dict() # {tensor id -> tensor name}
52 with open(Path(fp32_dir) / 'tensors.json') as f:
53 tname_to_tid = json.load(f)
54
55 for tname, tid in tname_to_tid.items():
56 self._tid_to_tname[tid] = tname
57
58 # Save paths to fp32 data and fq data for each tensor
59 # dict
60 # {
61 # <tensor_name>: (fp32_path, fq_path),
62 # <tensor_name>: (fp32_path, fq_path),
63 # ...
64 # }
65 data_paths = dict()
66 for data_idx in range(self._num_data):
67 fp32_results = glob.glob(fp32_dir + '/' + str(data_idx) + '/*.npy')
68 for fp32_data_path in fp32_results:
69 fp32_path = Path(fp32_data_path)
70 fq_data_path = fq_dir + '/' + str(data_idx) + '/' + fp32_path.with_suffix(
71 '.npy').name
72 fq_path = Path(fq_data_path)
73 tid = int(fp32_path.stem)
74 tensor_name = self._tid_to_tname[tid]
75
76 # Only save the tensors which have both fp32 data and fq data
77 if fq_path.is_file() and fp32_path.is_file():
78 if tensor_name in data_paths:
79 data_paths[tensor_name].append((fp32_data_path, fq_data_path))
80 else:
81 data_paths[tensor_name] = [(fp32_data_path, fq_data_path)]
82
83 return data_paths
84

Referenced by QErrorComputer.MPEIRComputer.advance_on(), QErrorComputer.MSEComputer.advance_on(), and QErrorComputer.TAEComputer.advance_on().

◆ run()

QErrorComputer.QErrorComputer.run (   self)
Return qerror map (dict: tensor_name(string) -> qerror(float)).

Reimplemented in QErrorComputer.MPEIRComputer, QErrorComputer.MSEComputer, QErrorComputer.TAEComputer, and QErrorComputer.SRMSEComputer.

Definition at line 85 of file QErrorComputer.py.

85 def run(self):
86 '''Return qerror map (dict: tensor_name(string) -> qerror(float)).'''
87 raise NotImplementedError # Child must implement this
88
89
void run(std::ofstream &os, const circle::Model *model)

Field Documentation

◆ _fp32_dir

QErrorComputer.QErrorComputer._fp32_dir
protected

Definition at line 26 of file QErrorComputer.py.

◆ _fq_dir

QErrorComputer.QErrorComputer._fq_dir
protected

Definition at line 27 of file QErrorComputer.py.

◆ _num_data

◆ _num_processed_data

◆ _tid_to_tname

QErrorComputer.QErrorComputer._tid_to_tname
protected

Definition at line 51 of file QErrorComputer.py.

◆ qerror_map


The documentation for this class was generated from the following file: