Skip to content

Fix mypy error about PyTorch Distributed#4413

Merged
toshihikoyanase merged 2 commits intooptuna:masterfrom
Alnusjaponica:fix-checks-integration-pytorch-distributed
Feb 10, 2023
Merged

Fix mypy error about PyTorch Distributed#4413
toshihikoyanase merged 2 commits intooptuna:masterfrom
Alnusjaponica:fix-checks-integration-pytorch-distributed

Conversation

@Alnusjaponica
Copy link
Copy Markdown
Contributor

Motivation

Resolve #4116

Description of the changes

This PR fixes mypy error in integration/pytorch_distributed.py, by making it explicit that __init__() of TorchDistributedTrial changes a global variable. Note that mypy error of the line was used to be ignored before PR #4281 but I removed type: ignore to reduce unused warnings. Mypy recognize this as error again from 1.0.0.

@Alnusjaponica
Copy link
Copy Markdown
Contributor Author

I confirmed that this PR fixes mypy error in Checks (integration) together with #4410.
See here to confirm.

@github-actions github-actions bot added the optuna.integration Related to the `optuna.integration` submodule. This is automatically labeled by github-actions. label Feb 9, 2023
@Alnusjaponica Alnusjaponica marked this pull request as ready for review February 9, 2023 09:31
@toshihikoyanase
Copy link
Copy Markdown
Member

@cross32768 Could you review this PR since it follows up #4281.

It will fix the error in https://github.com/optuna/optuna/actions/runs/4139175958/jobs/7156458918.

optuna/integration/pytorch_distributed.py:137: error: Incompatible types in assignment (expression has type "Optional[ProcessGroup]", variable has type "ProcessGroup") [assignment]

)

_g_pg: List[Optional["ProcessGroup"]] = [None]
_g_pg: Optional["ProcessGroup"] = None
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change seems reasonable to me since only the first element is used in the master code.
I'd like to use a local variable to manage the process group for Optuna in #4268, but I don't think we should work on it in this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your follow-up.

Copy link
Copy Markdown
Contributor

@cross32768 cross32768 left a comment

Choose a reason for hiding this comment

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

I checked this change in my local environment and confirmed that this change fix the mypy error. It looks reasonable fix. LGTM!

Copy link
Copy Markdown
Member

@toshihikoyanase toshihikoyanase left a comment

Choose a reason for hiding this comment

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

I also confirmed that the change worked with the pytorch distributed example in oputna/optuna-examples. LGTM!

@toshihikoyanase toshihikoyanase added the code-fix Change that does not change the behavior, such as code refactoring. label Feb 10, 2023
@toshihikoyanase toshihikoyanase added this to the v3.2.0 milestone Feb 10, 2023
@toshihikoyanase toshihikoyanase merged commit 1d473ed into optuna:master Feb 10, 2023
@Alnusjaponica Alnusjaponica deleted the fix-checks-integration-pytorch-distributed branch February 16, 2023 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-fix Change that does not change the behavior, such as code refactoring. optuna.integration Related to the `optuna.integration` submodule. This is automatically labeled by github-actions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve mypy error on master branch

3 participants