MinerU not using the GPU? Replace CPU PyTorch with the CUDA build to enable RTX 4060

A troubleshooting guide for MinerU environments where PyTorch reports 2.8.0+cpu and CUDA unavailable, including how to install the CUDA 12.8 PyTorch build in the same .venv and verify that an RTX 4060 is actually used.

If your MinerU environment reports something like this after checking PyTorch:

1
2
3
4
5
PyTorch: 2.8.0+cpu
PyTorch CUDA: None
CUDA available: False
GPU count: 0
GPU: 未检测到

You can basically confirm that the current environment has the CPU-only PyTorch build installed, so MinerU will not use the NVIDIA GPU. Even if the machine has an RTX 4060, MinerU can only run on CPU as long as torch in that Python environment is the CPU build.

The fix is straightforward: in the same .venv, replace torch and torchvision with the CUDA build. For PyTorch 2.8.0, the official CUDA 12.8 wheels are available, so you can install the cu128 build directly.

First check the NVIDIA driver

Run this in PowerShell:

1
nvidia-smi

Normally, you should see something like:

1
2
3
NVIDIA GeForce RTX 4060
Driver Version: ...
CUDA Version: 12.x

The CUDA Version shown here is the highest CUDA version supported by the current graphics driver. As long as nvidia-smi can detect the GPU, you usually do not need to install the full CUDA Toolkit separately.

If nvidia-smi cannot detect the GPU at all, do not start with PyTorch. Update or reinstall the NVIDIA driver first.

Enter the virtual environment used by MinerU

Go to the MinerU project directory. Here C:\Work\test is used as an example:

1
cd C:\Work\test

If the project uses .venv, activate it:

1
.\.venv\Scripts\Activate.ps1

Confirm the current Python path:

1
python -c "import sys; print(sys.executable)"

It should point to a path like:

1
C:\Work\test\.venv\Scripts\python.exe

This step matters. You need to replace PyTorch in the Python environment that MinerU actually uses, not the system Python, another Conda environment, or a random interpreter selected by VS Code.

Uninstall the CPU PyTorch build

After confirming that .venv is active, uninstall the current CPU build:

1
uv pip uninstall torch torchvision

If you do not use uv, regular pip can also work, but it is better not to mix tools inside the same environment. This guide continues with uv pip.

Install the CUDA 12.8 PyTorch build

Install the CUDA 12.8 build matching PyTorch 2.8.0:

1
uv pip install torch==2.8.0 torchvision==0.23.0 --index-url https://download.pytorch.org/whl/cu128

The official version pairing is:

1
2
3
torch 2.8.0
torchvision 0.23.0
CUDA 12.8

The CUDA PyTorch download can be large, often several GB. Be patient if the network is slow.

If uv says the package is already installed but your check still shows the CPU build, force a reinstall:

1
uv pip install --reinstall torch==2.8.0 torchvision==0.23.0 --index-url https://download.pytorch.org/whl/cu128

Verify that CUDA is available

Run:

1
python -c "import torch; print('PyTorch:', torch.__version__); print('CUDA build:', torch.version.cuda); print('CUDA available:', torch.cuda.is_available()); print('GPU count:', torch.cuda.device_count()); print('GPU:', torch.cuda.get_device_name(0) if torch.cuda.is_available() else '未检测到')"

The correct result should look like:

1
2
3
4
5
PyTorch: 2.8.0+cu128
CUDA build: 12.8
CUDA available: True
GPU count: 1
GPU: NVIDIA GeForce RTX 4060

The most important line is:

1
CUDA available: True

If it is still False, PyTorch still cannot use CUDA. Common causes include installing into the wrong environment, still having the CPU build of torch, a broken NVIDIA driver, or using a Python interpreter different from MinerU’s .venv.

Run a real GPU computation

Seeing CUDA available: True is useful, but you can also run a real CUDA tensor operation:

1
python -c "import torch; x=torch.randn(4096,4096,device='cuda'); y=x@x; torch.cuda.synchronize(); print('设备:', y.device); print('显存:', round(torch.cuda.memory_allocated()/1024**2,1), 'MB')"

A normal result looks like:

1
2
设备: cuda:0
显存: 128.0 MB

This means PyTorch not only detects the GPU, but can actually run CUDA computation on the RTX 4060.

Watch the GPU while running MinerU

Open a second PowerShell window and monitor the GPU:

1
nvidia-smi -l 1

Then run MinerU in the first window:

1
mineru -p "C:\Work\test\input.pdf" -o "C:\Work\test\output"

If the virtual environment is not activated, call the executable inside .venv directly:

1
.\.venv\Scripts\mineru.exe -p "C:\Work\test\input.pdf" -o "C:\Work\test\output"

Watch nvidia-smi. If the following signs appear, MinerU is very likely using the RTX 4060:

  1. python.exe appears.
  2. VRAM usage increases.
  3. GPU-Util rises during inference.
  4. VRAM is released after MinerU exits.

How to think about RTX 4060 and MinerU modes

RTX 4060 belongs to NVIDIA’s 40 series, the Ada Lovelace architecture, which is within the hardware range supported by MinerU GPU acceleration. After the correct CUDA PyTorch build is installed, the normal mineru command can use the GPU.

If you explicitly specify:

1
mineru -p "input.pdf" -o "output" -b pipeline

it is more focused on stability and compatibility, and is also suitable for CPU fallback or low-VRAM cases. If you want to use modes such as hybrid-engine or vlm-engine, which depend more on VLM, it is even more important to confirm that CUDA PyTorch is installed correctly.

Common pitfalls

First, installing into the wrong environment. The most common issue is installing CUDA PyTorch into one Python environment while MinerU actually runs in another .venv. Always check:

1
python -c "import sys; print(sys.executable)"

Second, checking only the driver, not PyTorch. A normal nvidia-smi only proves that the driver sees the GPU. It does not prove that PyTorch inside Python supports CUDA. The final check is still:

1
python -c "import torch; print(torch.__version__, torch.version.cuda, torch.cuda.is_available())"

Third, confusing CUDA Toolkit with PyTorch CUDA. For most normal use cases, you do not need to install the full CUDA Toolkit separately. If the NVIDIA driver works, installing the official PyTorch CUDA wheel is enough.

Fourth, VRAM may be occupied by other programs. RTX 4060 8GB can run these workloads, but the margin is not huge. Before running MinerU, close games, browser hardware acceleration, other AI inference programs, and software that occupies VRAM.

One-line summary

If you see:

1
2
PyTorch: 2.8.0+cpu
CUDA available: False

then MinerU cannot use the RTX 4060 in the current environment. The correct approach is to uninstall the CPU builds of torch and torchvision in the same .venv, then install:

1
uv pip install torch==2.8.0 torchvision==0.23.0 --index-url https://download.pytorch.org/whl/cu128

When the verification changes to:

1
2
3
PyTorch: 2.8.0+cu128
CUDA available: True
GPU: NVIDIA GeForce RTX 4060

run MinerU again and use nvidia-smi -l 1 to watch python.exe, VRAM, and GPU utilization. That is how you confirm whether GPU acceleration is really active.

记录并分享
Built with Hugo
Theme Stack designed by Jimmy