Skip to content

Commit c47c39b

Browse files
yiliu30zehao-intel
authored andcommitted
[Strategy] Adjust the hints for import hyperopt and sigopt (#213)
Signed-off-by: yiliu30 <[email protected]> Signed-off-by: zehao-intel <[email protected]>
1 parent 870bc7f commit c47c39b

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

neural_compressor/contrib/strategy/sigopt.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,13 @@ def __init__(self, model, conf, q_dataloader, q_func=None,
8888
try:
8989
import sigopt
9090
except ImportError:
91-
ImportError(f"Please install sigopt for using {strategy_name} strategy.")
91+
try:
92+
import subprocess
93+
import sys
94+
subprocess.check_call([sys.executable, "-m", "pip", "install", "sigopt"])
95+
import sigopt # pylint: disable=import-error
96+
except:
97+
assert False, "Unable to import sigopt from the local environment."
9298
else:
9399
pass
94100
# SigOpt init

neural_compressor/contrib/strategy/tpe.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ def __init__(self, model, conf, q_dataloader, q_func=None,
9191
try:
9292
import hyperopt
9393
except ImportError:
94-
raise ImportError(f"Please install hyperopt for using {strategy_name} strategy.")
94+
try:
95+
import subprocess
96+
import sys
97+
subprocess.check_call([sys.executable, "-m", "pip", "install", "hyperopt"])
98+
import hyperopt # pylint: disable=import-error
99+
except:
100+
assert False, "Unable to import hyperopt from the local environment."
95101
else:
96102
pass
97103
self.hpopt_search_space = None

test/requirements.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ pillow>=8.2.0
1313
transformers<=4.12.3; python_version < '3.10'
1414
transformers==4.16.0; python_version == '3.10'
1515
tensorflow_model_optimization
16-
sigopt
17-
hyperopt
1816
horovod
1917
tensorflow-addons
2018
onnxruntime-extensions; python_version < '3.10'

0 commit comments

Comments
 (0)