| 299 | } |
| 300 | |
| 301 | bool ModelServer::BatchGraphDeepFMPredict( |
| 302 | const std::vector<features_t>& batch_features, |
| 303 | const std::vector<features_t>& batch_users, |
| 304 | std::vector<float>* batch_prob) const { |
| 305 | DXCHECK(target_type_ == 1); |
| 306 | if (batch_features.empty()) { |
| 307 | return false; |
| 308 | } |
| 309 | |
| 310 | if (!graph_ || !model_) { |
| 311 | return false; |
| 312 | } |
| 313 | |
| 314 | OpContext op_context; |
| 315 | op_context.Init(graph_.get(), model_->mutable_param()); |
| 316 | if (!op_context.InitOp({target_name_}, -1)) { |
| 317 | return false; |
| 318 | } |
| 319 | |
| 320 | Instance* inst = op_context.mutable_inst(); |
| 321 | auto& X = inst->insert<csr_t>(deepx_core::X_NAME); |
| 322 | for (const auto& features : batch_features) { |
| 323 | EmplaceRow(features, &X); |
| 324 | } |
| 325 | |
| 326 | auto& User = inst->insert<csr_t>(instance_name::X_USER_NODE_NAME); |
| 327 | for (const auto& users : batch_users) { |
| 328 | EmplaceRow(users, &User); |
| 329 | } |
| 330 | DXASSERT(X.row() == User.row()); |
| 331 | |
| 332 | inst->set_batch(X.row()); |
| 333 | |
| 334 | op_context.InitPredict(); |
| 335 | op_context.Predict(); |
| 336 | const auto& P = op_context.hidden().get<tsr_t>(target_name_); |
| 337 | DXASSERT(P.is_rank(2)); |
| 338 | DXASSERT(P.same_shape(X.row(), 1)); |
| 339 | batch_prob->resize(X.row()); |
| 340 | const float_t* _P = P.data(); |
| 341 | for (int i = 0; i < X.row(); ++i) { |
| 342 | (*batch_prob)[i] = (float)*_P; |
| 343 | ++_P; |
| 344 | } |
| 345 | return true; |
| 346 | } |
| 347 | |
| 348 | static void DeleteOpContext(OpContext* op_context) noexcept { |
| 349 | delete op_context; |
nothing calls this directly
no test coverage detected