Repository navigation
GPU support
bg-be-gone uses your GPU when it safely can, and the CPU when it can't. The footer always names the device a run actually used, so a CPU result never poses as a GPU one.
- What runs on what
- PyTorch or ONNX Runtime: the Engine row
- Half or full precision
- When the GPU runs out of memory
- What install.sh sets up per vendor (Linux, from source)
- AMD: why your GPU is never impersonated
- Getting your AMD card accelerated anyway
Two words used throughout:
- ONNX Runtime runs most of bg-be-gone's models. It reaches a GPU through a provider: CUDA (NVIDIA), ROCm (AMD), or DirectML (any DirectX 12 GPU, on Windows).
- PyTorch is a second engine, added for recent AMD and NVIDIA cards. It runs BiRefNet and Segment's SAM models faster, and in less VRAM.
| You installed | Runs on | Falls back to |
|---|---|---|
Windows, directml
|
DirectML. With PyTorch added: PyTorch for BiRefNet and SAM. | DirectML, then the CPU |
Windows, cuda
|
CUDA | the CPU |
Windows, cpu or seg
|
the CPU | — |
Linux AppImage, cuda
|
CUDA | the CPU |
Linux AppImage, rocm or rocm-gfx1031
|
ROCm, if it has code for your chip | the CPU |
Linux AppImage, cpu or seg
|
the CPU | — |
| Linux, from source | the first provider that works: CUDA, then ROCm. With PyTorch added: PyTorch for BiRefNet and SAM. | ONNX Runtime, then the CPU |
Who gets PyTorch: the Windows directml installs and Linux source installs, on these cards. The AppImages don't carry it.
| GPU | PyTorch build | Windows download | Linux download |
|---|---|---|---|
| AMD Radeon RX 5000 to 9000 | AMD's ROCm build, for your chip's own target | 1.1 to 1.6 GB | 1.5 to 2 GB |
| NVIDIA RTX 20 or newer (GTX 16 too), driver 580 or later | PyTorch's CUDA build | about 2 GB | about 2.8 GB |
Intel GPUs and AMD's integrated graphics don't get PyTorch: they stay on DirectML (Windows) or ONNX Runtime (Linux).
You don't need to touch this. With PyTorch installed, bg-be-gone prefers it, and falls back to ONNX Runtime on its own. This section is here for the knob-twiddlers among us.
The choice lives in Model → Advanced → Engine, in the sidebar. Segment's sidebar shows the same row. Without PyTorch installed, the row stays hidden.
| Engine | Does |
|---|---|
| Automatic (default) | PyTorch whenever it's installed. ONNX Runtime takes over when PyTorch can't start, or a model can't load on it. |
| PyTorch | Always PyTorch. |
| ONNX Runtime | Always ONNX Runtime: DirectML on Windows, CUDA or ROCm on Linux. |
- The row says what runs, and why, for example "Automatic: PyTorch on AMD (ROCm), because it's installed".
- Switching restarts the background process. A run in progress finishes first.
On PyTorch, BiRefNet runs in half precision (fp16), in about half the VRAM. Precision applies to BiRefNet only, and only on PyTorch.
- Model → Advanced → Full precision runs it in full precision (fp32) instead, in about twice the VRAM.
- Some models need a second file for it. The row warns you first: it downloads that copy once, and keeps both.
- If half precision gives a broken result on your GPU, bg-be-gone redoes that image in full precision. It then stays on full precision until bg-be-gone restarts, and the row says so. You never see the broken one.
You still get your image, just a little later. If a run fails on the GPU, typically for lack of VRAM, that image is redone on the CPU instead of failing. The GPU is used again for the next one, once memory frees up.
- The footer names the device a run actually used, so you'll know when the CPU stepped in.
- Leaving a page releases its model. So background removal and segmentation never fight over VRAM.
On Linux, from source, install.sh picks the ONNX Runtime build for your GPU, then offers PyTorch on top.
-
NVIDIA:
onnxruntime-gpuand the CUDA runtime it needs. -
AMD:
onnxruntime-rocm. It checks the provider holds code for your chip, then runs a small model on the GPU before it calls acceleration working. You need your distro's ROCm runtime; if it's missing, the installer names the packages to install and uses the CPU. - Anything else: the CPU build, which asks nothing of your drivers.
The PyTorch builds are the same pairs as on Windows: AMD's ROCm build for your chip's own gfx target (never another chip's), or PyTorch's CUDA build. If PyTorch can't run, it's taken out again, and ONNX Runtime carries on.
Short version: bg-be-gone runs your AMD card only on code built for that exact chip. Anything else would risk wrong results and a frozen desktop.
ONNX Runtime's ROCm provider ships precompiled code for a fixed list of chips. Cards outside it, including every RDNA2 chip except the RX 6800/6900, are commonly made to work by impersonating a sibling with HSA_OVERRIDE_GFX_VERSION.
bg-be-gone never does this, because it isn't safe. An RX 6750 XT (gfx1031, 40 compute units) running gfx1030 code (built for 80 compute units) produces NaN, "not a number", on BiRefNet. Then it hangs the GPU hard enough to force a full reset, taking the desktop with it. That's a lot of drama for one cut-out.
Instead, bg-be-gone reads which chips the provider binary actually has code for. It uses the GPU only if your exact chip is there. Otherwise it uses the CPU: slower, but correct, and it can't wedge your machine.
Note
bg-be-gone also clears HSA_OVERRIDE_GFX_VERSION for its own process, in case your shell sets it for another app. Other programs keep theirs.
Bring a provider built for your card, and re-run the installer. This is for Linux installs from source.
BGBG_ROCM_WHEEL=/path/to/onnxruntime_rocm-*.whl ./install.shRX 6700 XT / 6750 XT: download the prebuilt wheel from onnxruntime-rocm-gfx1031, and pass it as above. A checkout of that repo next to bg-be-gone's is picked up on its own:
git clone https://github.com/cristeigabriela/onnxruntime-rocm-gfx1031 ../onnxruntime-rocm-gfx1031
./install.shMeasured with it on an RX 6750 XT: 0.707 s per image on BiRefNet General, correct output, no GPU faults.
Another AMD card
That repo's ./build.sh builds a provider for any target, for example ARCH=gfx1032 ./build.sh. It carries the five upstream patches needed to compile against a current distro ROCm. Expect it to take 40 minutes or more: a good time for that tea.
First, check whether you need it at all. If this prints your chip, the stock wheel already covers you:
strings -a "$(python -c 'import onnxruntime,os;print(os.path.dirname(onnxruntime.__file__))')/capi/libonnxruntime_providers_rocm.so" \
| grep -oE 'amdgcn-amd-amdhsa--gfx[0-9a-z]+' | sort -uRun it with the Python that has onnxruntime-rocm installed, such as the worker's own, under ~/.local/share/bg-be-gone/venv/bin/python.
Getting started
When you need it