From 4765f0f189fd0cd032a79da37ba427c3ba60ec33 Mon Sep 17 00:00:00 2001 From: Vadim Gimpelson <156319763+vadiklyutiy@users.noreply.github.com> Date: Sat, 6 Jun 2026 03:56:36 +0400 Subject: [PATCH] [Bugfix] Fix `sequence_parallel_chunk_impl` custom op aliasing its input (#44130) Signed-off-by: Vadim Gimpelson Co-authored-by: Cursor --- vllm/model_executor/models/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vllm/model_executor/models/utils.py b/vllm/model_executor/models/utils.py index 83d113415dc..02b1352ca9d 100644 --- a/vllm/model_executor/models/utils.py +++ b/vllm/model_executor/models/utils.py @@ -838,7 +838,10 @@ def sequence_parallel_chunk_impl(x: torch.Tensor) -> torch.Tensor: chunk = y.shape[0] // tp_size start = tp_rank * chunk - return torch.narrow(y, 0, start, chunk) + out = torch.narrow(y, 0, start, chunk) + # narrow() returns a view; clone when it aliases the input (no-pad case), + # since a functional custom op must not return a view of an input. + return out.clone() if y is x else out def sequence_parallel_chunk_impl_fake(x: torch.Tensor) -> torch.Tensor: