From 728e0794e2d6cee7806ab4c1c2c2d1c4bfe96079 Mon Sep 17 00:00:00 2001 From: myhloli Date: Tue, 2 Jun 2026 03:18:18 +0800 Subject: [PATCH] fix: refactor memory cleaning functions to simplify implementation and avoid circular dependencies --- mineru/utils/model_utils.py | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/mineru/utils/model_utils.py b/mineru/utils/model_utils.py index 1c2e4f68..6c1f486a 100644 --- a/mineru/utils/model_utils.py +++ b/mineru/utils/model_utils.py @@ -180,15 +180,7 @@ def get_res_list_from_layout_res(layout_res, overlap_threshold=0.8): return ocr_res_list, table_res_list, single_page_mfdetrec_res -def _pipeline_inference_quiet_zone(): - """懒加载推理静默区,避免 utils 模块导入时和 pipeline backend 形成循环依赖。""" - from mineru.backend.pipeline.model_init import pipeline_inference_quiet_zone - - return pipeline_inference_quiet_zone() - - -def _clean_memory_without_inference(device='cuda'): - """执行实际显存/内存清理动作,调用方负责进入推理静默区。""" +def clean_memory(device='cuda'): if str(device).startswith("cuda"): if torch.cuda.is_available(): torch.cuda.empty_cache() @@ -213,11 +205,6 @@ def _clean_memory_without_inference(device='cuda'): gc.collect() -def clean_memory(device='cuda'): - with _pipeline_inference_quiet_zone(): - _clean_memory_without_inference(device) - - def clean_vram(device, vram_threshold=8): total_memory = get_vram(device) if total_memory and total_memory <= vram_threshold: