MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / _legacy_static_save

Function _legacy_static_save

python/paddle/framework/io_utils.py:184–207  ·  view source on GitHub ↗
(param_dict, model_path, protocol=2)

Source from the content-addressed store, hash-verified

182
183@static_only
184def _legacy_static_save(param_dict, model_path, protocol=2):
185 def get_tensor(var):
186 if isinstance(var, (paddle.Tensor, core.DenseTensor)):
187 return np.array(var)
188 return var
189
190 param_dict = {name: get_tensor(param_dict[name]) for name in param_dict}
191
192 # When value of dict is lager than 4GB ,there is a Bug on 'MAC python3'
193 if (
194 _is_file_path(model_path)
195 and sys.platform == 'darwin'
196 and sys.version_info.major == 3
197 ):
198 pickle_bytes = pickle.dumps(param_dict, protocol=protocol)
199 with open(model_path, 'wb') as f:
200 max_bytes = 2**30
201 f.writelines(
202 pickle_bytes[i : i + max_bytes]
203 for i in range(0, len(pickle_bytes), max_bytes)
204 )
205 else:
206 with _open_file_buffer(model_path, 'wb') as f:
207 pickle.dump(param_dict, f, protocol=protocol)
208
209
210def _reconstruct_dense_tensor_data(data):

Callers 1

saveFunction · 0.85

Calls 5

_is_file_pathFunction · 0.85
rangeFunction · 0.85
_open_file_bufferFunction · 0.85
dumpMethod · 0.80
get_tensorFunction · 0.70

Tested by

no test coverage detected