I have a module that defines some functions, and I want this module to import different package based on arguments.
For example, I now have a file called my_module.py:
if CUDA is True:
import numpy as pkg
else:
import cupy as pkg
print(pkg.__name__)
When I import my_module from another file, I expect to somehow add an argument CUDA such than when it's True, then my_module imports cupy and then prints out "cupy", otherwise import numpy and prints "numpy"
For example, this is my main.py:
import my_module # somehow add an argument CUDA=False, should print "numpy"
>>> numpy
if os.environ.get("CUDA") is not None: ...my_module.pycompute things in CPU or GPU. Is there a way?USE_GPU=true) rather than tied to the implementation (CUDA=true).