MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / LoadCheckpoint

Method LoadCheckpoint

oneflow/api/cpp/framework/graph.cpp:395–419  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

393}
394
395of::Maybe<void> Graph::GraphImpl::LoadCheckpoint() {
396 for (const auto& variable_op_name_and_tensor : variable_op_name_to_tensor_) {
397 const auto& variable_op_name = variable_op_name_and_tensor.first;
398 const auto& variable_tensor = variable_op_name_and_tensor.second;
399 const std::string variable_filename = model_path_ + "/" + variable_op_name + "/out";
400 const std::string buffer = [&]() {
401 std::ifstream variable_file(variable_filename, std::ios::binary);
402 CHECK(variable_file.is_open());
403 std::stringstream ss;
404 ss << variable_file.rdbuf();
405 return ss.str();
406 }();
407 const auto& callback = [&](of::ep::Stream* stream,
408 const std::shared_ptr<of::vm::EagerBlobObject>& eager_blob_object) {
409 of::AutoMemcpy(stream, eager_blob_object->mut_dptr(), buffer.data(),
410 variable_tensor->shape()->elem_cnt()
411 * of::GetSizeOfDataType(variable_tensor->dtype()->data_type()),
412 eager_blob_object->mem_case(), of::memory::MakeHostMemCase());
413 };
414 JUST(of::one::SyncAccessTensorWithTimeOut(variable_tensor, callback, "mut"));
415 }
416 const auto& pair = Unzip(variable_op_name_to_tensor_);
417 JUST(of::FillVariableTensorMgr(pair.first, pair.second));
418 return of::Maybe<void>::Ok();
419}
420
421of::Maybe<void> Graph::GraphImpl::RegisterTensors(const std::vector<Tensor>& inputs) {
422 {

Callers

nothing calls this directly

Calls 13

AutoMemcpyFunction · 0.85
GetSizeOfDataTypeFunction · 0.85
MakeHostMemCaseFunction · 0.85
UnzipFunction · 0.85
FillVariableTensorMgrFunction · 0.85
is_openMethod · 0.80
mut_dptrMethod · 0.45
dataMethod · 0.45
elem_cntMethod · 0.45
shapeMethod · 0.45
data_typeMethod · 0.45

Tested by

no test coverage detected