Skip to content

Commit 269b95d

Browse files
authored
[Serving] Support user defined storage size of multi-tier Embedding in serving. (#417)
1 parent b32e05f commit 269b95d

File tree

7 files changed

+28
-4
lines changed

7 files changed

+28
-4
lines changed

docs/Processor.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,10 @@ void* initialize(const char* model_entry, const char* model_config, int* state);
375375
"ev_storage_type": 12,
376376

377377
# 多级存储路径, 如果设置了多级存储
378-
"ev_storage_path": "/ssd/1/"
378+
"ev_storage_path": "/ssd/1/",
379+
380+
# 多级存储中每级存储的大小
381+
"ev_storage_size": [1024, 1024]
379382
}
380383
```
381384
#### 模型路径配置

serving/processor/framework/graph_optimizer.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,8 @@ Status SavedModelOptimizer::RunNativeTFGraphPass() {
607607
}
608608

609609
if (option_.st) {
610-
TF_RETURN_IF_ERROR(RewriteEmbeddingVariableAttr(option_.st, option_.path));
610+
TF_RETURN_IF_ERROR(RewriteEmbeddingVariableAttr(option_.st,
611+
option_.path, option_.size));
611612
}
612613

613614
// Add other passes here
@@ -2360,12 +2361,14 @@ Node* SavedModelOptimizer::UpdateRestoreShardNodeInputs(
23602361
}
23612362

23622363
Status SavedModelOptimizer::RewriteEmbeddingVariableAttr(
2363-
embedding::StorageType st, std::string path) {
2364+
embedding::StorageType st, const std::string& path,
2365+
const std::vector<int64>& storage_size) {
23642366
for (Node* node : graph_.nodes()) {
23652367
if (node->op_def().name() == "KvResourceImportV2" ||
23662368
node->op_def().name() == "InitializeKvVariableOp") {
23672369
node->AddAttr("storage_type", st);
23682370
node->AddAttr("storage_path", path);
2371+
node->AddAttr("storage_size", storage_size);
23692372

23702373
LOG(INFO) << "debug op: " << node->DebugString();
23712374
}

serving/processor/framework/graph_optimizer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ struct GraphOptimizerOption {
149149
// multi tiered embedding
150150
embedding::StorageType st = embedding::StorageType::INVALID;
151151
std::string path;
152+
std::vector<int64> size;
152153
};
153154

154155
struct SrcInfo {
@@ -263,7 +264,8 @@ class SavedModelOptimizer : public GraphOptimizer {
263264
std::unordered_map<std::string, std::vector<Node*>>& origin_import_nodes,
264265
std::vector<Node*>& new_kv_import_nodes);
265266

266-
Status RewriteEmbeddingVariableAttr(embedding::StorageType st, std::string path);
267+
Status RewriteEmbeddingVariableAttr(embedding::StorageType st, const std::string& path,
268+
const std::vector<int64>& size);
267269

268270
Node* storage_pointer_node_ = nullptr;// storage placeholder node
269271
Node* version_node_ = nullptr; // version placeholder node

serving/processor/serving/model_config.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,12 @@ Status ModelConfigFactory::Create(const char* model_config, ModelConfig** config
385385
case embedding::StorageType::DRAM_SSDHASH:
386386
(*config)->storage_type = embedding::StorageType::DRAM_SSDHASH;
387387
(*config)->storage_path = json_config["ev_storage_path"].asString();
388+
for (int i = 0; i < json_config["ev_storage_size"].size(); i++)
389+
(*config)->storage_size.emplace_back(json_config["ev_storage_size"][i].asInt64());
390+
if (json_config["ev_storage_size"].size() < 4) {
391+
for (int i = json_config["ev_storage_size"].size(); i < 4; i++)
392+
(*config)->storage_size.emplace_back(1024*1024*1024);
393+
}
388394
break;
389395
default:
390396
return Status(error::Code::INVALID_ARGUMENT,

serving/processor/serving/model_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct ModelConfig {
6060
// EmbeddingVariable Config
6161
embedding::StorageType storage_type = embedding::StorageType::INVALID;
6262
std::string storage_path;
63+
std::vector<int64> storage_size;
6364
};
6465

6566
class ModelConfigFactory {

serving/processor/serving/model_config_test.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ const std::string oss_config = " \
236236
\"oss_access_id\" : \"test_id\", \
237237
\"ev_storage_type\" : 12, \
238238
\"ev_storage_path\" : \"123\", \
239+
\"ev_storage_size\" : [1024, 1024], \
239240
\"oss_access_key\" : \"test_key\" \
240241
}";
241242

@@ -244,6 +245,12 @@ const std::string oss_config = " \
244245
ModelConfigFactory::Create(oss_config.c_str(), &config).ok());
245246
EXPECT_EQ(12, config->storage_type);
246247
EXPECT_EQ("123", config->storage_path);
248+
for (int i = 0; i < 2; i++) {
249+
EXPECT_EQ(1024, config->storage_size[i]);
250+
}
251+
for (int i = 2; i < 4; i++) {
252+
EXPECT_EQ(1024*1024*1024, config->storage_size[i]);
253+
}
247254
}
248255

249256
TEST_F(ModelConfigTest, ShouldFailureWhenConfigEmbeddingConfig) {
@@ -266,6 +273,7 @@ const std::string oss_config = " \
266273
\"oss_access_id\" : \"test_id\", \
267274
\"ev_storage_type\" : 14, \
268275
\"ev_storage_path\" : \"123\", \
276+
\"ev_storage_size\" : [1024, 1024, 1024, 1024], \
269277
\"oss_access_key\" : \"test_key\" \
270278
}";
271279

serving/processor/serving/model_instance.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ Status LocalSessionInstance::Init(ModelConfig* config,
277277

278278
option.st = config->storage_type;
279279
option.path = config->storage_path;
280+
option.size = config->storage_size;
280281

281282
optimizer_ = new SavedModelOptimizer(config->signature_name,
282283
&meta_graph_def_, option);

0 commit comments

Comments
 (0)