| 341 | } |
| 342 | |
| 343 | of::Maybe<void> Graph::GraphImpl::BuildGraph() { |
| 344 | CompileScope build_graph_scope(job_.job_conf(), *device_.device_->shared_from_symbol()); |
| 345 | { |
| 346 | const of::OpGraph op_graph(job_); |
| 347 | op_graph.TopoForEachNode([&](const of::OpNode* node) -> of::Maybe<void> { |
| 348 | const of::OperatorConf& op_conf = node->op().op_conf(); |
| 349 | JUST(AddOp(op_conf)); |
| 350 | if (op_conf.has_variable_conf()) { |
| 351 | const of::LazyMode::Guard lazy_mode_disabled_guard{false}; |
| 352 | const of::VariableOpConf& variable_conf = op_conf.variable_conf(); |
| 353 | variable_op_name_to_tensor_[op_conf.name()] = JUST(of::one::functional::Empty( |
| 354 | of::Shape(variable_conf.shape()), |
| 355 | JUST(of::DType::Get(static_cast<of::DataType>(variable_conf.data_type()))), |
| 356 | *device_.device_, /*requires_grad=*/false, /*pin_memory=*/false)); |
| 357 | } |
| 358 | return of::Maybe<void>::Ok(); |
| 359 | }); |
| 360 | } |
| 361 | JUST(LoadCheckpoint()); |
| 362 | JUST(of::CurJobBuildAndInferCtx_Complete()); |
| 363 | std::shared_ptr<of::Job> complete_job = JUST(of::GetCurrentJob()); |
| 364 | int64_t job_id = JUST(of::JobBuildAndInferCtx_GetCurrentJobId()); |
| 365 | CHECK(of::Singleton<OneFlowEnv>::Get() != nullptr); |
| 366 | |
| 367 | // apply custom job passes |
| 368 | complete_job = JUST(ApplyJobPasses(*complete_job)); |
| 369 | graph_ = std::make_shared<of::NNGraph>(job_.job_conf().job_name(), *complete_job, job_id, |
| 370 | of::Singleton<OneFlowEnv>::Get()->GetSessionCtx()); |
| 371 | { |
| 372 | const of::OpGraph complete_graph(*complete_job); |
| 373 | complete_graph.TopoForEachNode([&](const of::OpNode* node) -> of::Maybe<void> { |
| 374 | const of::LazyMode::Guard lazy_mode_disabled_guard{false}; |
| 375 | const of::OperatorConf& op_conf = node->op().op_conf(); |
| 376 | if (op_conf.has_output_conf()) { |
| 377 | of::InterfaceBlobConf blob_conf = op_conf.output_conf().blob_conf(); |
| 378 | if (batch_size_ > 0) { |
| 379 | const std::string input_lbi_str = op_conf.output_conf().in(); |
| 380 | const of::LogicalBlobId input_lbi = of::GenLogicalBlobId(input_lbi_str); |
| 381 | int64_t batch_size = node->LogicalBlobDesc4Lbi(input_lbi).shape().At(0); |
| 382 | blob_conf.mutable_shape()->set_dim(0, batch_size); |
| 383 | } |
| 384 | output_name_to_tensor_[op_conf.name()] = JUST(of::one::functional::Empty( |
| 385 | of::Shape(blob_conf.shape()), |
| 386 | JUST(of::DType::Get(static_cast<of::DataType>(blob_conf.data_type()))), |
| 387 | *device_.device_, /*requires_grad=*/false, /*pin_memory=*/false)); |
| 388 | } |
| 389 | return of::Maybe<void>::Ok(); |
| 390 | }); |
| 391 | } |
| 392 | return of::Maybe<void>::Ok(); |
| 393 | } |
| 394 | |
| 395 | of::Maybe<void> Graph::GraphImpl::LoadCheckpoint() { |
| 396 | for (const auto& variable_op_name_and_tensor : variable_op_name_to_tensor_) { |
nothing calls this directly
no test coverage detected