@@ -563,6 +563,8 @@ def __init__(
563563 f"share the same block size, got { group_block_sizes } ."
564564 )
565565 assert pcp_world_size == 1 , "PCP not support hybrid attn now."
566+ self .dcp_world_size = dcp_world_size
567+ self .pcp_world_size = pcp_world_size
566568 self .verify_and_split_kv_cache_groups ()
567569
568570 def verify_and_split_kv_cache_groups (self ) -> None :
@@ -658,11 +660,15 @@ def find_longest_cache_hit(
658660 - The number of tokens of the longest cache hit.
659661 """
660662
663+ def _effective_block_size (kv_cache_spec : KVCacheSpec ) -> int :
664+ return kv_cache_spec .block_size * self .dcp_world_size * self .pcp_world_size
665+
661666 def _get_block_hashes (kv_cache_spec : KVCacheSpec ) -> BlockHashList :
662- if kv_cache_spec .block_size == self .hash_block_size :
667+ effective_block_size = _effective_block_size (kv_cache_spec )
668+ if effective_block_size == self .hash_block_size :
663669 return block_hashes
664670 return BlockHashListWithBlockSize (
665- block_hashes , self .hash_block_size , kv_cache_spec . block_size
671+ block_hashes , self .hash_block_size , effective_block_size
666672 )
667673
668674 num_groups = len (self .kv_cache_config .kv_cache_groups )
@@ -687,13 +693,14 @@ def _get_block_hashes(kv_cache_spec: KVCacheSpec) -> BlockHashList:
687693 for idx , (spec , group_ids , manager_cls , use_eagle ) in enumerate (
688694 self .attention_groups
689695 ):
696+ effective_block_size = _effective_block_size (spec )
690697 cached_blocks = hit_blocks_by_group [group_ids [0 ]]
691698 if isinstance (spec , FullAttentionSpec ) and cached_blocks is not None :
692699 # Full attention is downward-closed: we only need to look
693700 # up cached blocks once; on subsequent iterations just trim
694701 # to the (reduced) current hit length.
695702 curr_hit_length = (
696- curr_hit_length // spec . block_size * spec . block_size
703+ curr_hit_length // effective_block_size * effective_block_size
697704 )
698705 continue
699706
@@ -703,7 +710,8 @@ def _get_block_hashes(kv_cache_spec: KVCacheSpec) -> BlockHashList:
703710 if drop_eagle_block :
704711 # Eagle needs to match one more block and then pop the last.
705712 _max_length = min (
706- curr_hit_length + spec .block_size , max_cache_hit_length
713+ curr_hit_length + effective_block_size ,
714+ max_cache_hit_length ,
707715 )
708716 hit_blocks = manager_cls .find_longest_cache_hit (
709717 block_hashes = _get_block_hashes (spec ),
@@ -713,8 +721,10 @@ def _get_block_hashes(kv_cache_spec: KVCacheSpec) -> BlockHashList:
713721 kv_cache_spec = spec ,
714722 drop_eagle_block = drop_eagle_block ,
715723 alignment_tokens = self .scheduler_block_size ,
724+ dcp_world_size = self .dcp_world_size ,
725+ pcp_world_size = self .pcp_world_size ,
716726 )
717- _new_hit_length = len (hit_blocks [0 ]) * spec . block_size
727+ _new_hit_length = len (hit_blocks [0 ]) * effective_block_size
718728 if drop_eagle_block :
719729 eagle_verified .add (idx )
720730 elif _new_hit_length < curr_hit_length :
@@ -735,7 +745,7 @@ def _get_block_hashes(kv_cache_spec: KVCacheSpec) -> BlockHashList:
735745 # Truncate full attention blocks to final hit_length (if present)
736746 first_group = self .attention_groups [0 ]
737747 if isinstance (first_group .spec , FullAttentionSpec ):
738- num_blocks = hit_length // first_group .spec . block_size
748+ num_blocks = hit_length // _effective_block_size ( first_group .spec )
739749 for group_id in first_group .group_ids :
740750 if (blks := hit_blocks_by_group [group_id ]) is not None :
741751 del blks [num_blocks :]
@@ -758,11 +768,15 @@ def find_longest_cache_hit_per_group(
758768 (blocks_per_group, hit_lengths_per_group)
759769 """
760770
771+ def _effective_block_size (kv_cache_spec : KVCacheSpec ) -> int :
772+ return kv_cache_spec .block_size * self .dcp_world_size * self .pcp_world_size
773+
761774 def _get_block_hashes (kv_cache_spec : KVCacheSpec ) -> BlockHashList :
762- if kv_cache_spec .block_size == self .hash_block_size :
775+ effective_block_size = _effective_block_size (kv_cache_spec )
776+ if effective_block_size == self .hash_block_size :
763777 return block_hashes
764778 return BlockHashListWithBlockSize (
765- block_hashes , self .hash_block_size , kv_cache_spec . block_size
779+ block_hashes , self .hash_block_size , effective_block_size
766780 )
767781
768782 num_groups = len (self .kv_cache_config .kv_cache_groups )
@@ -778,8 +792,10 @@ def _get_block_hashes(kv_cache_spec: KVCacheSpec) -> BlockHashList:
778792 kv_cache_spec = spec ,
779793 drop_eagle_block = use_eagle ,
780794 alignment_tokens = self .scheduler_block_size ,
795+ dcp_world_size = self .dcp_world_size ,
796+ pcp_world_size = self .pcp_world_size ,
781797 )
782- group_hit = len (blocks [0 ]) * spec . block_size
798+ group_hit = len (blocks [0 ]) * _effective_block_size ( spec )
783799 for gid , blks in zip (group_ids , blocks ):
784800 hit_blocks [gid ] = blks
785801 hit_lengths [gid ] = group_hit
0 commit comments