File tree Expand file tree Collapse file tree 1 file changed +14
-7
lines changed
lightllm/server/router/dynamic_prompt Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -82,13 +82,20 @@ def is_leaf(self):
8282 return len (self .children ) == 0
8383
8484
85- def match (key , seq ):
86- i = 0
87- for k , w in zip (key , seq ):
88- if k != w :
89- break
90- i += 1
91- return i
85+ def match (t1 : torch .Tensor , t2 : torch .Tensor ) -> int :
86+ # Ensure same shape for comparison: flatten and get min length
87+ t1_flat = t1 .flatten ()
88+ t2_flat = t2 .flatten ()
89+ min_len = min (t1_flat .size (0 ), t2_flat .size (0 ))
90+
91+ # Compare elements and find first mismatch
92+ diff = t1_flat [:min_len ] != t2_flat [:min_len ]
93+ mismatch_indices = torch .nonzero (diff )
94+
95+ if mismatch_indices .numel () == 0 :
96+ return min_len # All matched up to min_len
97+ else :
98+ return mismatch_indices [0 ].item ()
9299
93100
94101class RadixCache :
You can’t perform that action at this time.
0 commit comments