[Perf] Optimize clamp to clamp_ (#48143)

Signed-off-by: yewentao256 <zhyanwentao@126.com>
Signed-off-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Wentao Ye
2026-07-16 18:41:07 -04:00
committed by GitHub
co-authored by mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 2cab53ddee
commit f17be06fbe
7 changed files with 48 additions and 32 deletions
+3 -1
View File
@@ -107,7 +107,9 @@ class Step3p5MTPProposer(EagleProposer):
if block_table is None:
continue
n_blocks = block_table.shape[1]
bn = (new_positions_1d // block_size).clamp(max=n_blocks - 1).to(torch.long)
bn = new_positions_1d // block_size
bn.clamp_(max=n_blocks - 1)
bn = bn.to(torch.long)
block_ids = block_table[:batch_size].gather(1, bn.unsqueeze(1)).squeeze(1)
sm = block_ids * block_size + (new_positions_1d % block_size)
sm.masked_fill_(exceeds, PADDING_SLOT_ID)