@@ -30,6 +30,7 @@ namespace sd {
3030 std::unordered_set<const ggml_tensor*> params_tensor_set_;
3131 ggml_status last_compute_status_ = GGML_STATUS_FAILED ;
3232 Tensor<float > output_;
33+ std::string device_memory_error_;
3334
3435 using GraphCutPlan = ggml_graph_cut::Plan;
3536 ggml_tensor* canonical_param_tensor (ggml_tensor* tensor);
@@ -73,9 +74,9 @@ namespace sd {
7374
7475 ComputeResult run () {
7576 if (!execute_graph (task_.graph , task_.n_threads , task_.no_return , task_.read_outputs )) {
76- return {last_compute_status_, {}};
77+ return {last_compute_status_, {}, std::move (device_memory_error_) };
7778 }
78- return {GGML_STATUS_SUCCESS , std::move (output_)};
79+ return {GGML_STATUS_SUCCESS , std::move (output_), {} };
7980 }
8081 };
8182
@@ -602,8 +603,12 @@ namespace sd {
602603 const auto & segment = plan.segments [index];
603604 const bool last = index + 1 == plan.segments .size ();
604605 auto fail_segment = [&](const char * phase) {
605- LOG_ERROR (" %s segment %zu/%zu (%s) failed during %s" , task_.description .c_str (),
606- index + 1 , plan.segments .size (), segment.group_name .c_str (), phase);
606+ auto message = sd_format (" %s segment %zu/%zu (%s) failed during %s" , task_.description .c_str (),
607+ index + 1 , plan.segments .size (), segment.group_name .c_str (), phase);
608+ LOG_ERROR (" %s" , message.c_str ());
609+ if (!device_memory_error_.empty ()) {
610+ device_memory_error_ = message + " : " + device_memory_error_;
611+ }
607612 return false ;
608613 };
609614 session_.cut_cache_ .prune (segment.live_cut_names );
@@ -658,7 +663,7 @@ namespace sd {
658663 sync_runtime_residency ();
659664 requests = memory_requests (measurement.buffers , new_cache_bytes);
660665 }
661- const bool ready = weights.ensure_segment_capacity (index, requests);
666+ const bool ready = weights.ensure_segment_capacity (index, requests, &device_memory_error_ );
662667 if (!ready && manager != nullptr ) {
663668 last_compute_status_ = GGML_STATUS_ALLOC_FAILED ;
664669 }
@@ -880,7 +885,8 @@ namespace sd {
880885 const DeviceMemoryRequest& request,
881886 const std::vector<ggml_tensor*>& required_params,
882887 const std::vector<std::vector<ggml_tensor*>>& preferred_eviction_order,
883- const std::vector<ggml_tensor*>& protected_params) {
888+ const std::vector<ggml_tensor*>& protected_params,
889+ std::string* device_memory_error) {
884890 GGML_ASSERT (&manager == manager_);
885891 auto capacity = [&]() { return manager.inspect_compute_backend_capacity (request, required_params); };
886892 const auto initial = capacity ();
@@ -972,10 +978,14 @@ namespace sd {
972978 const auto budget_bytes = available.available_budget_bytes == SIZE_MAX
973979 ? std::string (" unlimited" )
974980 : sd_format (" %.2f MB" , available.available_budget_bytes / (1024.0 * 1024.0 ));
975- LOG_WARN (" execution engine cannot make enough memory available on %s: need %.2f MB device / %.2f MB budget, available %s device / %s budget" ,
976- ggml_backend_name (request.compute_backend ),
977- available.required_device_bytes / (1024.0 * 1024.0 ),
978- available.required_budget_bytes / (1024.0 * 1024.0 ), device_bytes.c_str (), budget_bytes.c_str ());
981+ auto message = sd_format (" execution engine cannot make enough memory available on %s: need %.2f MB device / %.2f MB budget, available %s device / %s budget" ,
982+ ggml_backend_name (request.compute_backend ),
983+ available.required_device_bytes / (1024.0 * 1024.0 ),
984+ available.required_budget_bytes / (1024.0 * 1024.0 ), device_bytes.c_str (), budget_bytes.c_str ());
985+ LOG_WARN (" %s" , message.c_str ());
986+ if (device_memory_error != nullptr && available.valid ) {
987+ *device_memory_error = std::move (message);
988+ }
979989 return false ;
980990 }
981991
0 commit comments