Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make multi-processing in baseline models more consistent #909

Merged
12 changes: 10 additions & 2 deletions src/safeds/ml/classical/classification/_baseline_classifier.py
sibre28 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from concurrent.futures import ALL_COMPLETED, wait
from typing import Self

from joblib._multiprocessing_helpers import mp
sibre28 marked this conversation as resolved.
Show resolved Hide resolved

from safeds._validation._check_columns_are_numeric import _check_columns_are_numeric
from safeds.data.labeled.containers import TabularDataset
from safeds.exceptions import (
Expand Down Expand Up @@ -86,7 +88,10 @@ def fit(self, train_data: TabularDataset) -> Self:

copied_model = copy.deepcopy(self)

with ProcessPoolExecutor(max_workers=len(self._list_of_model_types)) as executor:
with ProcessPoolExecutor(
max_workers=len(self._list_of_model_types),
mp_context=mp.get_context("spawn"),
) as executor:
futures = []
for model in self._list_of_model_types:
futures.append(executor.submit(_fit_single_model, model, train_data))
Expand Down Expand Up @@ -149,7 +154,10 @@ def predict(self, test_data: TabularDataset) -> dict[str, float]:
raise DatasetMissesDataError
_check_columns_are_numeric(test_data_as_table, test_data.features.add_columns(test_data.target).column_names)

with ProcessPoolExecutor(max_workers=len(self._list_of_model_types)) as executor:
with ProcessPoolExecutor(
max_workers=len(self._list_of_model_types),
mp_context=mp.get_context("spawn"),
) as executor:
results = []
futures = []
for model in self._fitted_models:
Expand Down
12 changes: 10 additions & 2 deletions src/safeds/ml/classical/regression/_baseline_regressor.py
sibre28 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from concurrent.futures import ALL_COMPLETED, wait
from typing import Self

from joblib._multiprocessing_helpers import mp
sibre28 marked this conversation as resolved.
Show resolved Hide resolved

from safeds._validation._check_columns_are_numeric import _check_columns_are_numeric
from safeds.data.labeled.containers import TabularDataset
from safeds.exceptions import (
Expand Down Expand Up @@ -95,7 +97,10 @@ def fit(self, train_data: TabularDataset) -> Self:

copied_model = copy.deepcopy(self)

with ProcessPoolExecutor(max_workers=len(self._list_of_model_types)) as executor:
with ProcessPoolExecutor(
max_workers=len(self._list_of_model_types),
mp_context=mp.get_context("spawn"),
) as executor:
futures = []
for model in self._list_of_model_types:
futures.append(executor.submit(_fit_single_model, model, train_data))
Expand Down Expand Up @@ -159,7 +164,10 @@ def predict(self, test_data: TabularDataset) -> dict[str, float]:
_check_columns_are_numeric(test_data_as_table, test_data.features.add_columns(test_data.target).column_names)

# Start Processes
with ProcessPoolExecutor(max_workers=len(self._list_of_model_types)) as executor:
with ProcessPoolExecutor(
max_workers=len(self._list_of_model_types),
mp_context=mp.get_context("spawn"),
) as executor:
results = []
futures = []
for model in self._fitted_models:
Expand Down