[Bugfix][Build] Patch stable string memleak fix from 2.14 for 2.13 (#51185)

Signed-off-by: Jane Xu <janeyx@meta.com>
Signed-off-by: Shengqi Chen <harry-chen@outlook.com>
Co-authored-by: Shengqi Chen <harry-chen@outlook.com>
This commit is contained in:
Jane (Yuan) Xu
2026-08-08 21:12:39 -07:00
committed by GitHub
co-authored by Shengqi Chen
parent 073c510c91
commit f8d03e7741
2 changed files with 43 additions and 0 deletions
+28
View File
@@ -395,6 +395,34 @@ if(VLLM_GPU_LANG STREQUAL "CUDA" OR VLLM_GPU_LANG STREQUAL "HIP")
#
# _C_stable_libtorch extension (ops registered via STABLE_TORCH_LIBRARY)
#
if(Torch_VERSION VERSION_GREATER_EQUAL "2.13" AND
Torch_VERSION VERSION_LESS "2.14")
# hotfix for https://github.com/pytorch/pytorch/pull/190493
# delete after we bump to 2.14
list(GET TORCH_INCLUDE_DIRS 0 TORCH_INCLUDE_DIR)
set(_stable_hdr_rel "torch/csrc/stable/stableivalue_conversions.h")
file(READ "${TORCH_INCLUDE_DIR}/${_stable_hdr_rel}"
TORCH_STABLE_STRING_CONTENTS)
if(TORCH_STABLE_STRING_CONTENTS MATCHES "auto strptr = new std::string")
set(TORCH_SHADOW_INCLUDE_DIR
"${CMAKE_CURRENT_BINARY_DIR}/torch_patched_headers")
file(MAKE_DIRECTORY "${TORCH_SHADOW_INCLUDE_DIR}/torch/csrc/stable")
file(COPY_FILE
"${TORCH_INCLUDE_DIR}/${_stable_hdr_rel}"
"${TORCH_SHADOW_INCLUDE_DIR}/${_stable_hdr_rel}")
execute_process(
COMMAND patch --batch --forward -p1
"--input=${CMAKE_CURRENT_LIST_DIR}/cmake/patches/pytorch_stable_string.patch"
WORKING_DIRECTORY "${TORCH_SHADOW_INCLUDE_DIR}"
COMMAND_ERROR_IS_FATAL ANY)
include_directories(BEFORE "${TORCH_SHADOW_INCLUDE_DIR}")
endif()
endif()
set(VLLM_STABLE_EXT_SRC
"csrc/libtorch_stable/torch_bindings.cpp"
"csrc/libtorch_stable/cuda_view.cu"
+15
View File
@@ -0,0 +1,15 @@
diff --git a/torch/csrc/stable/stableivalue_conversions.h b/torch/csrc/stable/stableivalue_conversions.h
--- a/torch/csrc/stable/stableivalue_conversions.h
+++ b/torch/csrc/stable/stableivalue_conversions.h
@@ -807 +807 @@
-// Returns a new std::string; the string in val is deleted.
+// Returns a std::string which owns its memory; the string in val is deleted.
@@ -819 +819 @@
- auto strptr = new std::string(data, length);
+ const auto str = std::string(data, length);
@@ -821 +821 @@
- // delete the old string before returning new string
+ // delete the old string
@@ -823 +823 @@
- return *strptr;
+ return str;