Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

部分函数内增加了设备类型的转换,防止某些只接受"cuda"的函数拿到"gpu"后报错。 #1631

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions magic_pdf/model/sub_modules/mfr/unimernet/Unimernet.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def latex_rm_whitespace(s: str):

class UnimernetModel(object):
def __init__(self, weight_dir, cfg_path, _device_="cpu"):
device_map = {'cpu': 'cpu', 'gpu': 'cuda'}
_device_ = device_map[_device_]

args = argparse.Namespace(cfg_path=cfg_path, options=None)
cfg = Config(args)
cfg.config.model.pretrained = os.path.join(weight_dir, "pytorch_model.pth")
Expand Down
6 changes: 4 additions & 2 deletions magic_pdf/model/sub_modules/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ def clean_vram(device, vram_threshold=8):


def get_vram(device):
device_map = {'cpu': 'cpu', 'gpu': 'cuda'}

if torch.cuda.is_available() and device != 'cpu':
total_memory = torch.cuda.get_device_properties(device).total_memory / (1024 ** 3) # 将字节转换为 GB
total_memory = torch.cuda.get_device_properties(device_map[device]).total_memory / (1024 ** 3) # 将字节转换为 GB
return total_memory
elif str(device).startswith("npu"):
import torch_npu
if torch_npu.npu.is_available():
total_memory = torch_npu.npu.get_device_properties(device).total_memory / (1024 ** 3) # 转为 GB
return total_memory
else:
return None
return None
Loading