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

@dataclass-style structured configs to @attrs-style #1172

Closed
wants to merge 2 commits into from
Closed

@dataclass-style structured configs to @attrs-style #1172

wants to merge 2 commits into from

Conversation

rpartsey
Copy link
Collaborator

@rpartsey rpartsey commented Mar 1, 2023

Motivation and Context

  • Finish @dataclass-style structured configs to @attr.s-style @attr.s(auto_attribs=True, slots=True).
  • Migrated code to modern attrs API

How Has This Been Tested

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@rpartsey rpartsey added the WIP label Mar 1, 2023
@rpartsey rpartsey self-assigned this Mar 1, 2023
@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Mar 1, 2023
@rpartsey rpartsey removed the WIP label Mar 1, 2023
@rpartsey rpartsey requested a review from vincentpierre March 1, 2023 18:41
Copy link
Contributor

@vincentpierre vincentpierre left a comment

Choose a reason for hiding this comment

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

LGTM, did you do some testings to make sure we do not have issues with overwriting configs?

class SceneSamplerParamsConfig:
scene: str = "v3_sc1_staging_00"
scene_sets: List[Any] = field(default_factory=list)
scene_sets: List[Any] = []
Copy link
Contributor

Choose a reason for hiding this comment

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

I am against doing this as this technically bad behavior. I would rather we stick to dataclasses and wrap it with this: https://pypi.org/project/dataslots/

Copy link
Contributor

Choose a reason for hiding this comment

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

The main issue here is that the list can be edited and it will affect the DEFAULT parameters of the config which is unexpected behavior and bugprone.

Copy link
Contributor

@Skylion007 Skylion007 left a comment

Choose a reason for hiding this comment

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

We should consider sticking with dataclasses. They are better supported and I don't see any performance gains from doing it here. The are some nice features like validators, but we aren't using them currently. One of the nice things about having these files as dataclasses is that we can define them without Hydra. Not having a attrs.Factory of fields initializer creates bugprone behavior since our default args are mutable.

@rpartsey
Copy link
Collaborator Author

rpartsey commented Mar 1, 2023

We should consider sticking with dataclasses. They are better supported and I don't see any performance gains from doing it here. The are some nice features like validators, but we aren't using them currently. One of the nice things about having these files as dataclasses is that we can define them without Hydra. Not having a attrs.Factory of fields initializer creates bugprone behavior since our default args are mutable.

This was planned to be a follow-up PR to #1120, where you actually asked and approved structured configs to be attrs-style.

We should agree how do we define structured configs and either rollback structured config definition changes in #1120 or in this PR to make our code consistent.

@rpartsey
Copy link
Collaborator Author

rpartsey commented Mar 1, 2023

This PR can actually be decomposed into two:

  1. structured config @dataclass-style definition to @attr.s-style definition (update code that wasn't updated in Performance improvement on lab #1120)
  2. migrating our code to modern attrs API (should still be valid)

@rpartsey
Copy link
Collaborator Author

rpartsey commented Mar 1, 2023

LGTM, did you do some testings to make sure we do not have issues with overwriting configs?

I didn't observe any issues during development if structured configs (parent and child) are defined the same style. Though, I didn't test extensively.

@rpartsey rpartsey mentioned this pull request Mar 3, 2023
7 tasks
@rpartsey
Copy link
Collaborator Author

rpartsey commented Mar 3, 2023

Closing in favour of #1182.

@rpartsey rpartsey closed this Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants