Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions magic_pdf/model/custom_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@ def __init__(self, model_path):
self.gen_config = SamplingParams(max_tokens=4096,temperature=0,repetition_penalty=1.05)

def _auto_gpu_mem_ratio(self, ratio):
mem_free, mem_total = torch.cuda.mem_get_info()
if torch.cuda.is_available():
mem_free, mem_total = torch.cuda.mem_get_info()
else:
import torch_npu
mem_free, mem_total = torch_npu.npu.mem_get_info()
ratio = ratio * mem_free / mem_total
return ratio

Expand Down Expand Up @@ -905,7 +909,12 @@ def __init__(self, model_path, max_batch_size=64, queue_timeout=0.1, max_queue_s
logger.info(f"Max batch size: {max_batch_size}, Queue timeout: {queue_timeout}s")

def _auto_gpu_mem_ratio(self, ratio):
mem_free, mem_total = torch.cuda.mem_get_info()
if torch.cuda.is_available():
mem_free, mem_total = torch.cuda.mem_get_info()
else:
import torch_npu
# npu上ratio设置0.6比较合适
mem_free, mem_total = torch_npu.npu.mem_get_info()
ratio = ratio * mem_free / mem_total
return ratio

Expand Down