@@ -55,6 +55,11 @@ def write_calibration_cache(self, cache):
55
55
else :
56
56
return b""
57
57
58
+ # deepcopy (which involves pickling) is performed on the compile_spec internally during compilation.
59
+ # We register this __reduce__ function for pickler to identity the calibrator object returned by DataLoaderCalibrator during deepcopy.
60
+ # This should be the object's local name relative to the module https://docs.python.org/3/library/pickle.html#object.__reduce__
61
+ def __reduce__ (self ):
62
+ return self .__class__ .__name__
58
63
59
64
class DataLoaderCalibrator (object ):
60
65
"""
@@ -114,24 +119,25 @@ def __new__(cls, *args, **kwargs):
114
119
"get_batch" : get_cache_mode_batch if use_cache else get_batch ,
115
120
"read_calibration_cache" : read_calibration_cache ,
116
121
"write_calibration_cache" : write_calibration_cache ,
122
+ "__reduce__" : __reduce__ # used when you deepcopy the DataLoaderCalibrator object
117
123
}
118
124
119
125
# Using type metaclass to construct calibrator class based on algorithm type
120
126
if algo_type == CalibrationAlgo .ENTROPY_CALIBRATION :
121
127
return type (
122
- "DataLoaderCalibrator " , (_C .IInt8EntropyCalibrator ,), attribute_mapping
128
+ "Int8EntropyCalibrator " , (_C .IInt8EntropyCalibrator ,), attribute_mapping
123
129
)()
124
130
elif algo_type == CalibrationAlgo .ENTROPY_CALIBRATION_2 :
125
131
return type (
126
- "DataLoaderCalibrator " , (_C .IInt8MinMaxCalibrator ,), attribute_mapping
132
+ "Int8EntropyCalibrator2 " , (_C .IInt8EntropyCalibrator2 ,), attribute_mapping
127
133
)()
128
134
elif algo_type == CalibrationAlgo .LEGACY_CALIBRATION :
129
135
return type (
130
- "DataLoaderCalibrator " , (_C .IInt8LegacyCalibrator ,), attribute_mapping
136
+ "Int8LegacyCalibrator " , (_C .IInt8LegacyCalibrator ,), attribute_mapping
131
137
)()
132
138
elif algo_type == CalibrationAlgo .MINMAX_CALIBRATION :
133
139
return type (
134
- "DataLoaderCalibrator " , (_C .IInt8MinMaxCalibrator ,), attribute_mapping
140
+ "Int8MinMaxCalibrator " , (_C .IInt8MinMaxCalibrator ,), attribute_mapping
135
141
)()
136
142
else :
137
143
log (
0 commit comments