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

Method CreateKeyValueStore

oneflow/core/embedding/embedding_manager.cpp:502–548  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

500}
501
502void EmbeddingManager::CreateKeyValueStore(const KeyValueStoreOptions& key_value_store_options,
503 int64_t local_rank_id, int64_t rank_id,
504 int64_t world_size) {
505 CudaCurrentDeviceGuard guard(local_rank_id);
506 const std::string& name = key_value_store_options.Name();
507 const uint32_t line_size = key_value_store_options.LineSize();
508 std::pair<std::string, int64_t> map_key = std::make_pair(name, rank_id);
509 std::unique_lock<std::mutex> lock(mutex_);
510
511 std::unique_ptr<KeyValueStore> store;
512 PersistentTableKeyValueStoreOptions options{};
513 const std::vector<std::string>& persistent_table_paths =
514 key_value_store_options.PersistentTablePaths();
515 CHECK_EQ(persistent_table_paths.size(), world_size);
516 options.table_options.path = persistent_table_paths.at(rank_id);
517 options.table_options.value_size = line_size * key_value_store_options.ValueTypeSize();
518 options.table_options.key_size = key_value_store_options.KeyTypeSize();
519 options.table_options.physical_block_size =
520 key_value_store_options.PersistentTablePhysicalBlockSize();
521 options.table_options.target_chunk_size_mb = 4 * 1024;
522 options.table_options.capacity_hint = key_value_store_options.PersistentTableCapacityHint();
523 store = NewPersistentTableKeyValueStore(options);
524 const std::vector<CacheOptions>& cache_options = key_value_store_options.GetCachesOptions();
525 for (int i = cache_options.size() - 1; i >= 0; --i) {
526 std::unique_ptr<Cache> cache = NewCache(cache_options.at(i));
527 store = NewCachedKeyValueStore(std::move(store), std::move(cache));
528 }
529 store->ReserveQueryLength(kDefaultMaxQueryLength);
530 CHECK(key_value_store_map_.emplace(map_key, std::move(store)).second)
531 << "Can't create an embedding with same name of an existing embedding, the name: " << name;
532
533 if (UseDynamicMemoryAllocation()) {
534#if CUDA_VERSION >= 11020
535 CHECK(embedding_state_map_.emplace(map_key, std::make_unique<DynamicAllocationEmbeddingState>())
536 .second)
537 << "Can't create an embedding state with same name of an existing embedding, the name: "
538 << name;
539#else
540 UNIMPLEMENTED();
541#endif
542 } else {
543 CHECK(embedding_state_map_.emplace(map_key, std::make_unique<StaticAllocationEmbeddingState>())
544 .second)
545 << "Can't create an embedding state with same name of an existing embedding, the name: "
546 << name;
547 }
548}
549
550void EmbeddingManager::SaveSnapshot(const std::string& embedding_name, int64_t local_rank_id,
551 int64_t rank_id, const std::string& snapshot_name) {

Callers

nothing calls this directly

Calls 10

NewCacheFunction · 0.85
LineSizeMethod · 0.80
ValueTypeSizeMethod · 0.80
KeyTypeSizeMethod · 0.80
NameMethod · 0.45
sizeMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected