fix(core): free GPU memory when stopping pytorch rerank models - #5173
Merged
qinxuye merged 1 commit intoJul 14, 2026
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces GPU memory cleanup for PyTorch-backed rerank models during actor teardown in __pre_destroy__ and adds corresponding unit tests to verify this behavior. The reviewer suggests extending the model_format == "pytorch" guard to EmbeddingModel as well, which prevents torch-free GGUF embedding models from triggering torch-dependent cleanup blocks.
OliverBryant
force-pushed
the
fix/rerank-vram-leak-on-stop
branch
2 times, most recently
from
July 13, 2026 07:10
4e871e2 to
73742aa
Compare
RerankModel had no stop()/close(), and __pre_destroy__'s GPU-cleanup branch only covered LLM pytorch/vllm/sglang and EmbeddingModel, so stopping a sentence_transformers rerank model left its CUDA tensors and VRAM allocated. The leaked memory then crashed the next model's subpool during CUDA init on relaunch. Also guard the EmbeddingModel branch with model_format == "pytorch" (per review feedback) so the torch-free llama.cpp (ggufv2) embedding path isn't pulled into the torch-dependent cleanup block.
OliverBryant
force-pushed
the
fix/rerank-vram-leak-on-stop
branch
from
July 13, 2026 07:14
73742aa to
5bf977b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RerankModelhas nostop()/close(), andModelActor.__pre_destroy__'s GPU-cleanup branch only covered LLM pytorch/vllm/sglang andEmbeddingModel, so stopping a pytorch-format rerank model (e.g. sentence_transformers) never released its CUDA tensors/VRAM.xoscar.errors.ServerClosed: ... 0 bytes readatcreate_actor— reproducing the second-launch failure of Qwen3-Reranker-0.6B.__pre_destroy__to also run the existingdel self._model; gc.collect(); empty_cache()cleanup for pytorch-formatRerankModelinstances, guarded bymodel_format == "pytorch"so the torch-free llama.cpp (ggufv2) rerank path is unaffected.Test plan
test_pre_destroy_frees_rerank_gpu_memoryinxinference/core/tests/test_model.py, parametrized over pytorch (expects cleanup) and ggufv2 (expects skip).pytest xinference/core/tests/test_model.py— 3 passedpre-commit run --files xinference/core/model.py xinference/core/tests/test_model.py— black/isort/mypy/codespell pass (one pre-existing flake8 E231 false positive on an unrelated line is unchanged)