(param_dict, model_path, protocol=2)
| 182 | |
| 183 | @static_only |
| 184 | def _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 | |
| 210 | def _reconstruct_dense_tensor_data(data): |
no test coverage detected