Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/oet/calculator/uma.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,19 +303,23 @@ def calc(
or not isinstance(cache_dir, str)
):
raise RuntimeError("Problems handling input parameters.")
# Check if we have the respective models stored locally in cache
# If so, switch to offline mode
if self.check_for_model_files(basemodel=basemodel, cache_dir=cache_dir):
print("Model parameters found in cache. Switching to offline mode.")
# Check if the model files are available
model_files_available = self.check_for_model_files(basemodel=basemodel, cache_dir=cache_dir)
# If they are available, switch to offline mode.
if model_files_available:
self.switch_to_offline_mode()
# If set by the user, switch also to offline mode.
# This is a fallback, if online communication must be prevented.
if offline_mode:
print("Model files detected. Switching to offline mode.")
# If they are not available, but the user requested the offline mode to prevent online communication,
# print a warning as this will likely cause subsequent errors.
elif offline_mode:
self.switch_to_offline_mode()
if self.check_for_model_files(basemodel=basemodel, cache_dir=cache_dir):
print(
"WARNING: No model files were detected. This might lead to subsequent errors."
# Check if the model files are locally available. If not, subsequent errors will occur
# as they cannot be downloaded.
print(
"WARNING: Offline mode selected, but no model files were detected. "
"This will likely cause subsequent errors."
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would there be any downside to keeping this warning? If not, I think it would make sense to leave it in place with the corrected logic:

            if not self.check_for_model_files(basemodel=basemodel, cache_dir=cache_dir):
                print(
                    "WARNING: No model files were detected. This might lead to subsequent errors."
                )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really but seems counter intuitive that the check is done no matter what =)
assuming this check is basically free it should be fine either way

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the model file detection a little. I hope this is fine by you.


# setup calculator if not already set
# this is important as usage on a server would otherwise cause
# initialization with every call so that nothing is gained
Expand Down
7 changes: 6 additions & 1 deletion src/oet/server_client/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from collections import OrderedDict
from collections.abc import Mapping, Sequence
from concurrent.futures import BrokenExecutor, ProcessPoolExecutor
import multiprocessing as mp
from contextlib import redirect_stdout
from pathlib import Path
from types import FrameType
Expand Down Expand Up @@ -623,8 +624,12 @@ def main() -> None:

# Create workers
workers = args.nthreads
# Use spawn start method so CUDA can be initialized safely in worker processes
mp_ctx = mp.get_context("spawn")
# Initialize the ProcessPool
executor = ProcessPoolExecutor(max_workers=workers, initializer=worker_initializer)
executor = ProcessPoolExecutor(
max_workers=workers, initializer=worker_initializer, mp_context=mp_ctx
)

# Make a CalculatorClass getting the hooks on calculators argument parsing
# Info on calculator type is store in the object for client requests
Expand Down