kvcache framework restructure#1139
Draft
Adrenaline-S wants to merge 2 commits into
Draft
Conversation
Move implementation files into subdirectories to align with refactor branch: - allocator/: KVCacheAllocator, HybridTypeKVCacheAllocator, SingleTypeKVCacheAllocator - config_creator/: CacheConfigCreator, HybridConfigCreator, SingleConfigCreator, MemoryEvaluationHelper - group/: KVCacheGroup, FullKVCacheGroup, LinearKVCacheGroup - spec/: CacheGroupType, KVCacheSpec, KVCacheSpecBase, MHAKVCacheSpec, MLAKVCacheSpec, LinearKVCacheSpec Content is unchanged; include paths and BUILD files will be fixed in the next commit.
8750d41 to
713c00c
Compare
…v_refactor Phase 1 (a88a7da): restructure kvcache directory layout (rename only) - Move files into allocator/, config_creator/, group/, spec/ subdirs - Content unchanged; ensures git log --follow can trace history Phase 2: sync kvcache content from refactor-kvcache branch (3e04315) - Add spec/ subdirectory: KVCacheSpec hierarchy (MHA/MLA/Linear/Opaque), KVCacheSpecDesc/KVCacheSpecDescTypes for Python-C++ config bridge - Add allocator/: KVCacheAllocator, HybridKVCacheAllocator, HybridPoolKVCacheAllocator, HybridTypeKVCacheAllocator, SingleTypeKVCacheAllocator - Add config_creator/: CacheConfigCreator, HybridConfigCreator, HybridPoolConfigCreator, SingleConfigCreator, MemoryEvaluationHelper - Add group/: KVCacheGroup, FullKVCacheGroup, LinearKVCacheGroup, SWAKVCacheGroup - Replace CacheConfig with GroupBase/LayerBase design - Update BlockPool, SharedBlockCache, KVCacheResource/BatchKVCacheResource - Add CPSlotMapper, KVCacheTransferPlanner, SharedBlockCache - Update metrics, model_rpc, normal_engine, pybind, Python models Excludes DSV4/deepseek_v4-specific content per scope constraint. Phase 3: sync kvcache framework optimizations from feat/dsv4_on_dev_refactor (df5290b -> 92dcc53), excluding all DeepSeek V4 model-specific content. - GroupBase/LayerBase changed from class to plain struct; CacheConfig stores vector<GroupBase>/vector<LayerBase> + tag_to_gid map - KVCacheSpecDesc: local_head_num_kv->num_kv_heads, local_num_k/v_heads->num_k/v_heads; SpecBuilder refactored with per-type factories and TP-aware head count derivation - SpecBuildContext gains attn_tp_size/kernel_tokens_per_block/cp fields - LayerKVCacheSpecDescs: map<int64_t,...> -> vector<vector<...>> - CacheGroupPolicy: group_type field removed (derived from spec lifecycle) - primaryLayerGroupIdsSnapshot() removed; initGroups() signature simplified - kv_cache_layer_to_group param chain removed from NormalEngine, NormalExecutor, MtpExecutor, PyWrappedModel, CudaGraphRunner - group_order fields removed; mergeMTPModule rewritten with tag-based group alignment preserving target group-index namespace - BlockPoolConfigHelper: simplify MTP spec lookup to specForGroup(0) Excludes: deepseek_v4.py, DSV4CacheTest.cc, DSV4-specific helpers
713c00c to
8e3adcd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
The existing KVCache framework had all implementations flat in
rtp_llm/cpp/cache/, withCacheConfigusing rawstd::vectorfields (layer_to_group_id,group_types,cache_specs) to manage cache group information. This lacked type-safe group/layer mapping abstractions and made it impossible to declare per-layer cache layouts from the Python side.Key Changes
1. Directory Modularization (with git mv to preserve history)
Split root-level files into four subdirectories by responsibility:
spec/— KVCacheSpec type hierarchy (MHA/MLA/Linear/Opaque) +KVCacheSpecDescPython bridge descriptorsallocator/— Allocator hierarchy; addedHybridKVCacheAllocatorbase class andHybridPoolKVCacheAllocator(independent per-group block pools)group/— Cache group implementations; addedSWAKVCacheGroup(sliding-window attention group)config_creator/— Config factory; addedHybridPoolConfigCreator2. CacheConfig: GroupBase/LayerBase Compositional Design
Introduced
GroupBase(managing spec/policy/tag/layer_ids per group) andLayerBase(managing multi-dimensional layer-to-group mapping) to replace the flat field model. AddedfromGroupedSpecs()/fromLayerDescs()construction paths, enabling declarative per-layer cache type configuration (MHA/MLA/Linear/SWA) viaKVCacheSpecDescfrom the Python side.3. KVCacheAllocator Enhancements
Integrated
SharedBlockCache(standalone prefix-tree cache, replacing the BlockPool-embedded BlockCache) andCPSlotMapper(context-parallel sharding support). Addedtag- andgroup_id-dimensioned address conversion interfaces and independent block pool support (use_independent_block_pools).4. Config Layer Extensions
ConfigModules.h:PrefillCPConfiggainskv_cache_sharded/prefill_cp_size;KVCacheConfiggainsenable_gpu_prefix_tree/enable_independent_group_eviction;HybridAttentionConfiggainsenable_independent_kv_cache_poolsModelConfig.h: addedkv_cache_spec_descs(LayerKVCacheSpecDescs) for models to populate per-layer cache specs5. Python-Side Changes
BaseModel._post_build_model_config()auto-populateskv_cache_spec_descsfor standard MHA/MLA modelsKVCacheSpecDesc/KVCacheSpecDescExtratypes exposedOpDefs.h:layer_attn_typesrenamed tolayer_group_typesto reflect multi-group semantics