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

Restructure et_relay subpackage #124

Closed
wants to merge 7 commits into from

Conversation

amaslenn
Copy link

Summary

  1. Make et_replay structure easier to refactor: added an entry point to export public symbols, used it in train code.
  2. Enabled tests run as part of GHA CI.

Test Plan

CI

Additional Notes

amaslenn added 3 commits June 17, 2024 16:44
et_replay/
  - several high level modules mainly responsible for parsing
  - tools # previously was on a layer above, moved here to simplify
    imports management
  - comm # comm utils and functionalities, to be expanded
  - __init__.py # to hide files locations yet always export important
    symbols

`train` now doesn't care about actual files' locations.
@facebook-github-bot
Copy link
Contributor

Hi @amaslenn!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@amaslenn
Copy link
Author

cc @TaekyungHeo

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 17, 2024
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@amaslenn amaslenn changed the title Restruct Restructure et_relay subpackage Jun 17, 2024
@sanrise
Copy link

sanrise commented Jun 19, 2024

The change is a good move to make et_replay a package. But let's keep the imports absolute, they are not long enough yet for us to make them relative. Relative imports spoil readability, pep8 friendliness and refactoring capabilities. Within this single PR we are importing the ExecutionTrace class in the following manners:
from .. import ExecutionTrace, from ..execution_trace import ExecutionTrace, from .execution_trace import ExecutionTrace.

@@ -7,8 +7,8 @@ name = "et_replay"
version = "0.5.0"

[tool.setuptools.package-dir]
"et_replay.lib.comm" = "lib/comm"
"et_replay.tools" = "tools"
"et_replay" = "lib"
Copy link

Choose a reason for hiding this comment

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

this makes sense, to call everything under lib as a part of the et_replay package.

@@ -0,0 +1,3 @@
from .execution_trace import ExecutionTrace
Copy link

@sanrise sanrise Jun 19, 2024

Choose a reason for hiding this comment

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

+1 on exposing the ET class from the package init, but no harm in making this import absolute.

from .. import ExecutionTrace
from . import comms_utils
from .comms_utils import commsArgs
from .pytorch_backend_utils import supportedP2pOps
Copy link

Choose a reason for hiding this comment

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

can we keep the imports absolute? our absolute import strings are not really that long for us to justify relative imports. they also make code refactoring tricky. absolute imports are also more readable and pep8 friendly.

@amaslenn
Copy link
Author

amaslenn commented Jun 19, 2024

@sanrise thank you for the feedback! I mainly agree with you on relative imports topic, but there are a reason I made it like this:

  1. Editors are going crazy: et_replay is a directory and at the same time it is a package. But the structures are different, lib doesn't exist in the package, but exists in the file structure. So I need to either keep lib for both, or use relative imports.
  2. While relative imports have bad reputation, they are all over python's code itself. And it kinda makes sense inside packages.

Anyway, I can use absolute imports and also keep lib and yet export some symbols from init. Seems fine to me. What do you think?

@facebook-github-bot
Copy link
Contributor

@sanrise has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@sanrise
Copy link

sanrise commented Jun 20, 2024

  1. Editors are going crazy: et_replay is a directory and at the same time it is a package. But the structures are different, lib doesn't exist in the package, but exists in the file structure. So I need to either keep lib for both, or use relative imports.

Sounds like presence of lib is vestigial at this point, and we can get rid of it. Without it, the content of lib moves up a level. This means

  • you don't need to patch the module path in your toml
  • export what you want in your __init__.py to do from et_replay import X, Y, Z
  • Your editor is happy.
  • your absolute imports stick around.

Do you see a benefit of keeping it around just to have have it remapped in the toml? I don't, and I believe this will make everything more cleaner/easier. Thoughts?

@facebook-github-bot
Copy link
Contributor

@amaslenn has updated the pull request. You must reimport the pull request before landing.

@amaslenn
Copy link
Author

Do you see a benefit of keeping it around just to have have it remapped in the toml? I don't, and I believe this will make everything more cleaner/easier. Thoughts?

Generally I prefer having a top-level folder for a package or even have src-layout. It makes packaging more standard and manageable. But in our case IMO flat structure is fine too. I've updated my PR accordingly.

@sanrise
Copy link

sanrise commented Jun 24, 2024

Do you see a benefit of keeping it around just to have have it remapped in the toml? I don't, and I believe this will make everything more cleaner/easier. Thoughts?

Generally I prefer having a top-level folder for a package or even have src-layout. It makes packaging more standard and manageable. But in our case IMO flat structure is fine too. I've updated my PR accordingly.

thanks a lot! will import and run the linters / static checks shortly.

@facebook-github-bot
Copy link
Contributor

@sanrise has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@TaekyungHeo
Copy link
Contributor

@sanrise, please don't merge this PR until we inform you.

@@ -6,7 +6,7 @@
import uuid
from typing import Any, Dict

from et_replay.lib.execution_trace import ExecutionTrace
from et_replay.execution_trace import ExecutionTrace
Copy link

Choose a reason for hiding this comment

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

nit: for the record, this can also be from et_replay import ExecutionTrace. But this works too. (y)

Copy link
Author

Choose a reason for hiding this comment

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

Thank you! This makes sense, updated.

@facebook-github-bot
Copy link
Contributor

@amaslenn has updated the pull request. You must reimport the pull request before landing.

@TaekyungHeo
Copy link
Contributor

@sanrise , you can continue code review at #129

@amaslenn amaslenn closed this Jun 27, 2024
@briancoutinho
Copy link
Contributor

@TaekyungHeo after import we are seeing some Black formatting error. Did you guys run black formatter already?
If yes then we might need to disable the linter either outside or in meta, if you haven't i can share the format suggestions

@briancoutinho briancoutinho reopened this Jul 12, 2024
@briancoutinho
Copy link
Contributor

@TaekyungHeo also can you rebase to latest param main commit?

sanrise pushed a commit to sanrise/param that referenced this pull request Jul 15, 2024
Summary:
1. Make `et_replay` structure easier to refactor: added an entry point to export public symbols, used it in train code.
2. Enabled tests run as part of GHA CI.

Reviewed at facebookresearch#124

Pull Request resolved: facebookresearch#129

Test Plan:
CI

## Additional Notes
--

Differential Revision: D59178710

Pulled By: sanrise
sanrise pushed a commit to sanrise/param that referenced this pull request Jul 15, 2024
Summary:
Pull Request resolved: facebookresearch#133

1. Make `et_replay` structure easier to refactor: added an entry point to export public symbols, used it in train code.
2. Enabled tests run as part of GHA CI.

Reviewed at facebookresearch#124

Pull Request resolved: facebookresearch#129

Test Plan:
CI

## Additional Notes
--

Differential Revision: D59178710

Pulled By: sanrise
sanrise pushed a commit to sanrise/param that referenced this pull request Jul 15, 2024
Summary:
Pull Request resolved: facebookresearch#133

1. Make `et_replay` structure easier to refactor: added an entry point to export public symbols, used it in train code.
2. Enabled tests run as part of GHA CI.

Reviewed at facebookresearch#124

Pull Request resolved: facebookresearch#129

Test Plan:
CI

## Additional Notes
--

Differential Revision: D59178710

Pulled By: sanrise
sanrise pushed a commit to sanrise/param that referenced this pull request Jul 16, 2024
Summary:
Pull Request resolved: facebookresearch#133

1. Make `et_replay` structure easier to refactor: added an entry point to export public symbols, used it in train code.
2. Enabled tests run as part of GHA CI.

Reviewed at facebookresearch#124

Pull Request resolved: facebookresearch#129

Test Plan:
CI

## Additional Notes
--

Reviewed By: shengfukevin

Differential Revision: D59178710

Pulled By: sanrise
facebook-github-bot pushed a commit that referenced this pull request Jul 16, 2024
Summary:
Pull Request resolved: #133

1. Make `et_replay` structure easier to refactor: added an entry point to export public symbols, used it in train code.
2. Enabled tests run as part of GHA CI.

Reviewed at #124

Pull Request resolved: #129

Test Plan:
CI

## Additional Notes
--

Reviewed By: shengfukevin

Differential Revision: D59178710

Pulled By: sanrise

fbshipit-source-id: 81762730953136d3a3560b17aac2c8b1de7e8343
@amaslenn
Copy link
Author

@sanrise shall we close this PR now?

@amaslenn
Copy link
Author

Let's reopen if needed.

@amaslenn amaslenn closed this Jul 19, 2024
@TaekyungHeo
Copy link
Contributor

@amaslenn, I believe we can close this PR as it has been merged by @sanrise. #133

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants