(tensor, file_name)
| 690 | |
| 691 | |
| 692 | def _save_dense_tensor(tensor, file_name): |
| 693 | if not tensor._is_initialized(): |
| 694 | raise ValueError( |
| 695 | "The saved tensor is not initialized. If you used group sharded, please use save_group_sharded_model firstly." |
| 696 | ) |
| 697 | if _is_file_path(file_name): |
| 698 | _seek = core.save_dense_tensor(tensor, file_name) |
| 699 | # '_seek' is the end position of this tensor in the file. |
| 700 | |
| 701 | elif _is_memory_buffer(file_name): |
| 702 | tensor_bytes = core.save_dense_tensor_to_memory(tensor) |
| 703 | |
| 704 | with _open_file_buffer(file_name, 'wb') as f: |
| 705 | f.write(tensor_bytes) |
| 706 | _seek = f.tell() |
| 707 | |
| 708 | else: |
| 709 | raise NotImplementedError( |
| 710 | f'Only supports saving objects to file or BytesIO, but received {type(file_name)}' |
| 711 | ) |
| 712 | return _seek |
| 713 | |
| 714 | |
| 715 | def _load_dense_tensor(file_name): |
no test coverage detected