Skip to content

PyTorch启用苹果gpu #572

@SWHL

Description

@SWHL

Discussed in #509

Originally posted by xian-zh July 23, 2025

     ##torch.py
        self.use_gpu = False
        if cfg.engine_cfg.use_cuda:
            self.device = torch.device(f"cuda:{cfg.engine_cfg.gpu_id}")
            self.predictor.to(self.device)
            self.use_gpu = True
        # Mac 上启用 PyTorch GPU 加速需通过 Metal Performance Shaders (MPS) 后端实现
        if cfg.engine_cfg.use_mps:
            self.device = torch.device("mps" if torch.backends.mps.is_available() else "cpu")
            self.predictor.to(self.device)
            self.use_gpu = True    
     ##use
     engine = RapidOCR(
          params={
              "Det.engine_type": EngineType.TORCH,
              "Cls.engine_type": EngineType.TORCH,
              "Rec.engine_type": EngineType.TORCH,
              "EngineConfig.torch.use_mps": True,  # 使用torch GPU版推理
          }
    
    )
```</div>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions