Skip to content

Commit 845f11e

Browse files
committed
add destroy() method to so backend
Signed-off-by: shen-shanshan <467638484@qq.com>
1 parent 6b2427f commit 845f11e

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

vllm/v1/engine/core.py

+4
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ def shutdown(self):
252252
if self.model_executor:
253253
self.model_executor.shutdown()
254254

255+
so_backend = self.structured_output_manager.backend
256+
if so_backend is not None:
257+
so_backend.destroy()
258+
255259
def profile(self, is_start: bool = True):
256260
self.model_executor.profile(is_start)
257261

vllm/v1/structured_output/backend_guidance.py

+3
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ def allocate_token_bitmask(self, max_num_seqs: int):
110110
return llguidance_torch.allocate_token_bitmask(
111111
max_num_seqs, self.ll_tokenizer.vocab_size)
112112

113+
def destroy(self):
114+
pass
115+
113116

114117
@dataclass
115118
class GuidanceGrammar(StructuredOutputGrammar):

vllm/v1/structured_output/backend_types.py

+6
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,9 @@ def allocate_token_bitmask(self, max_num_seqs: int):
8787
max_num_seqs (int): The maximum number of sequences for which
8888
to allocate the bitmask.
8989
"""
90+
91+
@abstractmethod
92+
def destroy(self):
93+
"""
94+
Clear objects in the backend to avoid nanobind leaked.
95+
"""

vllm/v1/structured_output/backend_xgrammar.py

+3
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ def compile_grammar(self, request_type: StructuredOutputOptions,
126126
def allocate_token_bitmask(self, max_num_seqs: int):
127127
return xgr.allocate_token_bitmask(max_num_seqs, self.vocab_size)
128128

129+
def destroy(self):
130+
del self.compiler
131+
129132

130133
@dataclass
131134
class XgrammarGrammar(StructuredOutputGrammar):

0 commit comments

Comments
 (0)