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

Public Member Functions

 StartAnalysis (self, args)
 
 EndNetworkExecution (self, list outputs)
 
 DefaultOpPost (self, name, opcode, inputs, outputs)
 
 EndAnalysis (self)
 

Protected Attributes

 _dir
 
 _num_data
 
 _tname_to_tid
 
 _scale_map
 

Detailed Description

Definition at line 49 of file DumpFakeQuantFM.py.

Member Function Documentation

◆ DefaultOpPost()

DumpFakeQuantFM.DumpFakeQuantFM.DefaultOpPost (   self,
  name,
  opcode,
  inputs,
  outputs 
)

Definition at line 61 of file DumpFakeQuantFM.py.

61 def DefaultOpPost(self, name, opcode, inputs, outputs):
62 if opcode == 'Dequantize':
63 for output in outputs:
64 name = output['name']
65 data = output['data']
66 orig_name = _name_before_fq(name)
67 if orig_name in self._tname_to_tid:
68 tid = self._tname_to_tid[orig_name]
69 data_path = self._dir / str(self._num_data)
70 data_path.mkdir(parents=False, exist_ok=True)
71 np.save(str(data_path / str(tid)), data)
72 # Save scales (scale is fixed, so saving once)
73 if orig_name not in self._scale_map:
74 assert len(inputs) == 1
75 assert 'quantparam' in inputs[0]
76 assert 'scale' in inputs[0]['quantparam']
77 assert len(inputs[0]['quantparam']['scale']) == 1
78 scale = inputs[0]['quantparam']['scale'][0]
79 self._scale_map[orig_name] = scale
80

References DumpFakeQuantFM.DumpFakeQuantFM._dir, DumpFP32FM.DumpFP32FM._dir, DumpFakeQuantFM._name_before_fq(), circle_eval_diff::MAEPrinter._num_data, circle_eval_diff::MSEPrinter._num_data, circle_eval_diff::MAPEPrinter._num_data, circle_eval_diff::MPEIRPrinter._num_data, circle_eval_diff::TopKMatchPrinter._num_data, record_minmax::HDF5Iterator._num_data, record_minmax::RandomIterator._num_data, DumpFakeQuantFM.DumpFakeQuantFM._num_data, DumpFP32FM.DumpFP32FM._num_data, QErrorComputer.QErrorComputer._num_data, DumpFakeQuantFM.DumpFakeQuantFM._scale_map, DumpFakeQuantFM.DumpFakeQuantFM._tname_to_tid, and DumpFP32FM.DumpFP32FM._tname_to_tid.

◆ EndAnalysis()

DumpFakeQuantFM.DumpFakeQuantFM.EndAnalysis (   self)

Definition at line 81 of file DumpFakeQuantFM.py.

81 def EndAnalysis(self):
82 # Dump saved scales into scales.txt
83 with open(self._dir / 'scales.txt', 'w') as f:
84 json.dump(self._scale_map, f)

References DumpFakeQuantFM.DumpFakeQuantFM._dir, DumpFP32FM.DumpFP32FM._dir, and DumpFakeQuantFM.DumpFakeQuantFM._scale_map.

◆ EndNetworkExecution()

◆ StartAnalysis()

DumpFakeQuantFM.DumpFakeQuantFM.StartAnalysis (   self,
  args 
)

Definition at line 50 of file DumpFakeQuantFM.py.

50 def StartAnalysis(self, args):
51 self._dir = Path(args)
52 self._num_data = 0
53 with open(self._dir / 'tensors.json') as f:
54 self._tname_to_tid = json.load(f)
55 self._scale_map = {}
56

Field Documentation

◆ _dir

◆ _num_data

◆ _scale_map

DumpFakeQuantFM.DumpFakeQuantFM._scale_map
protected

◆ _tname_to_tid

DumpFakeQuantFM.DumpFakeQuantFM._tname_to_tid
protected

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