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

MART typing #29

Merged
merged 19 commits into from
Feb 2, 2023
Merged

MART typing #29

merged 19 commits into from
Feb 2, 2023

Conversation

lumurillo
Copy link
Contributor

What does this PR do?

Add typing annotation to the MART implementation to make the code more readable and robust.

Type of change

Please check all relevant options.

  • Improvement (non-breaking)
  • Bug fix (non-breaking)
  • New feature (non-breaking)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Testing

Please describe the tests that you ran to verify your changes. Consider listing any relevant details of your test configuration.

  • pytest --cov=mart

Before submitting

  • The title is self-explanatory and the description concisely explains the PR
  • My PR does only one thing, instead of bundling different changes together
  • I list all the breaking changes introduced by this pull request
  • I have commented my code
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have run pre-commit hooks with pre-commit run -a command without errors

Did you have fun?

Make sure you had fun coding 🙃

@lumurillo lumurillo added the enhancement New feature or request label Dec 15, 2022
@lumurillo lumurillo self-assigned this Dec 15, 2022
@lumurillo lumurillo changed the title Lumurillo/mart typing MART typing Dec 15, 2022
Copy link
Contributor

@dxoigmn dxoigmn left a comment

Choose a reason for hiding this comment

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

See comments.

def on_run_start(self, adversary, input, target, model, **kwargs):
def on_run_start(
self,
adversary: Callback,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we would want to type this as Adversary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Adversary class is defined below in this file, so I decided to use its parent class. Other option is to type it as torch.nn.Module which is the other parent class.

Copy link
Contributor

Choose a reason for hiding this comment

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

I still think it should be Adversary rather than nn.Module. It definitely should not be Callback. What is the problem with using Adversary? Is it because circular imports? Then we should restructure things. (Or make this nn.Module and create a new PR that fixes the circular import issue.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created issue #38 to tackle this. This circular issue can be a sign of a possible design problem between the adversaries and callbacks.

Comment on lines 24 to 27
def __init__(self, target_model, mart_exp_config_yaml, **kwargs):
def __init__(self, target_model: torch.nn.Module, mart_exp_config_yaml: str, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we use the ART's ObjectDetector type in the target_model argument?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think that is correct. @mzweilin?

Copy link
Contributor

Choose a reason for hiding this comment

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

Currently, we expect it to be ObjectDetector. But later we may want to use BaseEstimator as we generalize the wrapper for non-object detection models in ART.

@lumurillo lumurillo requested a review from dxoigmn January 3, 2023 17:43
Copy link
Contributor

@dxoigmn dxoigmn left a comment

Choose a reason for hiding this comment

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

See comments.

def on_run_start(self, adversary, input, target, model, **kwargs):
def on_run_start(
self,
adversary: Callback,
Copy link
Contributor

Choose a reason for hiding this comment

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

I still think it should be Adversary rather than nn.Module. It definitely should not be Callback. What is the problem with using Adversary? Is it because circular imports? Then we should restructure things. (Or make this nn.Module and create a new PR that fixes the circular import issue.)

Comment on lines 24 to 27
def __init__(self, target_model, mart_exp_config_yaml, **kwargs):
def __init__(self, target_model: torch.nn.Module, mart_exp_config_yaml: str, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think that is correct. @mzweilin?

def on_run_start(self, adversary, input, target, model, **kwargs):
def on_run_start(
self,
adversary: torch.nn.Module,
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay.

@lumurillo lumurillo force-pushed the lumurillo/mart-typing branch from afad315 to 2a9c668 Compare January 10, 2023 16:49
Copy link
Contributor

@dxoigmn dxoigmn left a comment

Choose a reason for hiding this comment

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

One comment about using typing.TYPE_CHECKING to guard new imports.

@dxoigmn dxoigmn self-requested a review February 2, 2023 17:37
Copy link
Contributor

@dxoigmn dxoigmn left a comment

Choose a reason for hiding this comment

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

LGTM!

@lumurillo lumurillo merged commit c1064d8 into main Feb 2, 2023
@lumurillo lumurillo deleted the lumurillo/mart-typing branch February 2, 2023 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants