Skip to content

Commit 2282fb5

Browse files
RocM: filter VRAM fetch by HIP_VISIBLE_DEVICES / CUDA_VISIBLE_DEVICES (fixes ggml-org#1104)
Signed-off-by: Jeroen Mostert <[email protected]>
1 parent 1a7ecd5 commit 2282fb5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

koboldcpp.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,16 @@ def fetch_gpu_properties(testCL,testCU,testVK):
766766
getamdvram = subprocess.run(['rocm-smi', '--showmeminfo', 'vram', '--csv'], capture_output=True, text=True, check=True, encoding='utf-8').stdout # fetch VRAM of devices
767767
if getamdvram:
768768
FetchedCUdeviceMem = [line.split(",")[1].strip() for line in getamdvram.splitlines()[1:] if line.strip()]
769+
770+
visible_devices = os.environ.get('HIP_VISIBLE_DEVICES') or os.environ.get('CUDA_VISIBLE_DEVICES')
771+
if visible_devices:
772+
use_devices = [int(n.strip()) for n in visible_devices.split(',')]
773+
774+
# note: can legit be an empty array, which means no GPU should be used
775+
if use_devices is not None:
776+
FetchedCUdevices = [FetchedCUdevices[i] for i in use_devices]
777+
FetchedCUdeviceMem = [FetchedCUdeviceMem[i] for i in use_devices]
778+
769779
except Exception as e:
770780
pass
771781
lowestcumem = 0

0 commit comments

Comments
 (0)