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

Calling score_test_set multiple times leads to Runtime Error #88

Open
DreRnc opened this issue Dec 20, 2024 · 2 comments
Open

Calling score_test_set multiple times leads to Runtime Error #88

DreRnc opened this issue Dec 20, 2024 · 2 comments

Comments

@DreRnc
Copy link
Contributor

DreRnc commented Dec 20, 2024

Hi, because in the code for the scoring function the context is set, multiple calls to this function will lead to a Runtime Error "context has already been set".

multiprocessing.set_start_method("spawn")
with multiprocessing.Pool(num_processes) as p:
p.starmap(
write_scores_as_json,
[
(
row,
row.output_file,
overwrite,
prediction_file.parent,
flexible,
posebusters,
posebusters_full,
)
for _, row in predictions.iterrows()
],
)

I think it isn't best practice to set the context inside a function call that could be theoretically called multiple times. Or at least, it should be checked that the context is not already set before trying to set it.

As an example of the use case problem, I encountered this when scoring inference for multiple models. So because of this, I need to call as many processes as models I have to score.

Fixing this should be extremely quick (an if statement to check that the context is not set), I can open a pull request for it.

@Ninjani
Copy link
Contributor

Ninjani commented Dec 23, 2024

Thanks for the catch, please open a PR! I guess this should also work: multiprocessing.get_context("spawn").Pool(num_processes)?

@DreRnc
Copy link
Contributor Author

DreRnc commented Dec 25, 2024

I agree with your solution, starting a local context is better if you want it always to use "spawn". I will open a PR now and merge it into contrib_dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants