Skip to content

Commit df5ca68

Browse files
committed
fix: handle GPU availability in test_doc_examples
- Add tensorflow import for GPU detection - Update GPU config test to handle case when GPU is not available - In CI with CUDA_VISIBLE_DEVICES=-1, mixed precision is correctly disabled
1 parent ea2b7ae commit df5ca68

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

tests/test_doc_examples.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import numpy as np
1313
import pandas as pd
1414
import pytest
15+
import tensorflow as tf
1516

1617
from locator import EnsembleLocator, Locator
1718
from locator.data import IndexSet, filter_snps, make_tf_dataset, normalize_locs
@@ -619,8 +620,13 @@ def test_gpu_config_examples(self, temp_dir):
619620
),
620621
}
621622
)
622-
# GPU optimizations are enabled by default
623-
assert loc.config.get("use_mixed_precision", True) is True
623+
# GPU optimizations are enabled by default if GPU is available
624+
# In CI without GPU, use_mixed_precision will be False
625+
if tf.config.list_physical_devices("GPU"):
626+
assert loc.config.get("use_mixed_precision", True) is True
627+
else:
628+
# When no GPU is available, mixed precision is disabled
629+
assert loc.config.get("use_mixed_precision", False) is False
624630

625631
# Example 2: Memory-constrained GPU
626632
loc_constrained = Locator(

0 commit comments

Comments
 (0)