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

first onnx neural compressor commit #3

Merged
merged 18 commits into from
May 10, 2024
Merged

first onnx neural compressor commit #3

merged 18 commits into from
May 10, 2024

Conversation

chensuyue
Copy link
Collaborator

@chensuyue chensuyue commented Apr 30, 2024

First onnx neural compressor commit

Copy link
Contributor

Choose a reason for hiding this comment

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

For CI, I would prefer github actions when possible.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, we can have a migrate plan. May I know the reason to choose GHA instead of Azure pipeline?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure - ONNX has moved to use github actions because they are easier to manage (doesn't need to belong to an ado organization which would require additional permissions) and they run faster. So that's two wins. I use chatgpt to translate the yaml files and it was pretty straightforward: onnx/onnx#6075

Copy link
Contributor

Choose a reason for hiding this comment

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

I saw there are several comments on CI tools, those are good suggestions. In our plan, this PR intends to land a MVP scope code migration to community first and enhance the CI/CD continuously during maintenance. I suggest to get this PR merged first and address these items progressively. does it make sense? @freddychiu @justinchuby

Copy link
Contributor

@thuang6 thuang6 May 9, 2024

Choose a reason for hiding this comment

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

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
Collaborator Author

Choose a reason for hiding this comment

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

The pre-commit.ci [Bot] is able to auto fix the format issue in the PR, do you want us to replace with lintrunner?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, please consider lintrunner since it is a standard check in the ONNX repository. It will provide a uniform linting experience in CI and in local environments, even though there is no autofix-in-CI features yet (can be implemented if needed). In practice, the local autofix experience has been good.

Copy link
Contributor

Choose a reason for hiding this comment

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

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
SECURITY.md Outdated Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F"]
Copy link
Contributor

@justinchuby justinchuby Apr 30, 2024

Choose a reason for hiding this comment

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

Comment on lines +63 to +72
"E402", # Module level import not at top of file
"E501", # Line too long (121 > 120 characters)
"E721", # Do not compare types, use isinstance()
"E722", # Do not use bare except
"E731", # Do not assign a lambda expression, use a def
"E741", # Do not use variables named ‘l’, ‘O’, or ‘I’
"F401", # {name} imported but unused
"F403", # from {name} import * used; unable to detect undefined names
"F405", # {name} may be undefined, or defined from star imports
"F841", # Local variable is assigned to but never used{name}
Copy link
Contributor

@justinchuby justinchuby Apr 30, 2024

Choose a reason for hiding this comment

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

Suggested change
"E402", # Module level import not at top of file
"E501", # Line too long (121 > 120 characters)
"E721", # Do not compare types, use isinstance()
"E722", # Do not use bare except
"E731", # Do not assign a lambda expression, use a def
"E741", # Do not use variables named ‘l’, ‘O’, or ‘I’
"F401", # {name} imported but unused
"F403", # from {name} import * used; unable to detect undefined names
"F405", # {name} may be undefined, or defined from star imports
"F841", # Local variable is assigned to but never used{name}
"E501", # Line too long (121 > 120 characters)
"E731", # Do not assign a lambda expression, use a def
"E741", # Do not use variables named ‘l’, ‘O’, or ‘I’

nit: I would refer to https://github.com/onnx/onnx/blob/d6f87121ba256ac6cc4d1da0463c300c278339d2/pyproject.toml#L154. For violating files, consider running auto-fix and create inline ignores using ruff check /path/to/file.py --add-noqa https://docs.astral.sh/ruff/linter/#inserting-necessary-suppression-comments so that the rules are not disabled for the rest of the codebase.

requirements.txt Show resolved Hide resolved
@justinchuby
Copy link
Contributor

I suggest using the ruff formatter over black, because it is much faster: https://docs.astral.sh/ruff/formatter/

setup.py Outdated Show resolved Hide resolved
chensuyue and others added 10 commits May 6, 2024 10:32
Signed-off-by: chensuyue <[email protected]>
Signed-off-by: chensuyue <[email protected]>
Signed-off-by: chensuyue <[email protected]>
Co-authored-by: Justin Chu <[email protected]>
Signed-off-by: chen, suyue <[email protected]>
Co-authored-by: Justin Chu <[email protected]>
Signed-off-by: chen, suyue <[email protected]>
Co-authored-by: Justin Chu <[email protected]>
Signed-off-by: chen, suyue <[email protected]>
Signed-off-by: chensuyue <[email protected]>
Comment on lines +21 to +48
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]

ruff already excludes directories in gitignore by default https://docs.astral.sh/ruff/settings/#respect-gitignore

I suggest adding https://github.com/github/gitignore/blob/main/Python.gitignore to the current gitignore



[tool.ruff]
# Exclude a variety of commonly ignored directories.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Exclude a variety of commonly ignored directories.

profile = "black"
line_length = 120
known_first_party = ["neural_compressor", "neural_insights", "neural_solution"]
extend_skip_glob = ["**/__init__.py"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
extend_skip_glob = ["**/__init__.py"]

Wondering why init files should be excluded?

@justinchuby
Copy link
Contributor

justinchuby commented May 8, 2024

On style: ONNX doesn't declare explicitly that it follows the Google Python style, so there's some wiggle room here. In practice, we enforce the Google style in code reviews (you may find some inconsistencies from old code). If there is a choice between "adopting the Google style guide and creating some exceptions" and "removing it altogether", I recommend the former. If the Google style guide doesn't fit the need, I would find a style guide that is comprehensive and easy to enforce enough that the code will look consistent across. (As an example, pep8 is not comprehensive enough such that many variations are complied with the guide)

Import: We are moving the ONNX project to be more compliant to the Google style, for good reasons: https://gist.github.com/justinchuby/9085242a53158f2fd7ae7aa650e55ee3#3-import-only-modules Feel free to share your rationale and create exceptions if needed though!

My recommendations:

  1. Pick and adhere to a strong style guide, preferably Google style.
  2. Create exceptions to the style guide if needed; justify them.
  3. Use tools to automatically enforce them in CI. In practice ruff has been very good at doing so; we need to enable more ruff rules.

Sorry for being pedantic about style. Since this is the start of the project, it is a perfect time that we nail this down.

@thuang6
Copy link
Contributor

thuang6 commented May 9, 2024

On style: ONNX doesn't declare explicitly that it follows the Google Python style, so there's some wiggle room here. In practice, we enforce the Google style in code reviews (you may find some inconsistencies from old code). If there is a choice between "adopting the Google style guide and creating some exceptions" and "removing it altogether", I recommend the former. If the Google style guide doesn't fit the need, I would find a style guide that is comprehensive and easy to enforce enough that the code will look consistent across. (As an example, pep8 is not comprehensive enough such that many variations are complied with the guide)

Import: We are moving the ONNX project to be more compliant to the Google style, for good reasons: https://gist.github.com/justinchuby/9085242a53158f2fd7ae7aa650e55ee3#3-import-only-modules Feel free to share your rationale and create exceptions if needed though!

My recommendations:

  1. Pick and adhere to a strong style guide, preferably Google style.
  2. Create exceptions to the style guide if needed; justify them.
  3. Use tools to automatically enforce them in CI. In practice ruff has been very good at doing so; we need to enable more ruff rules.

Sorry for being pedantic about style. Since this is the start of the project, it is a perfect time that we nail this down.

Thanks for recommendation. we understood your points on style part, specifically for import style, also understood the pros (avoid potential name conflict) and cons (a little bit tedious for long package/module name). In fact, There are all existing code migrated from original repo though it is the first PR in current repo. Anyway, we will take some time to check each import and revise or raise exception if there is issue found.

Copy link
Contributor

@justinchuby justinchuby left a comment

Choose a reason for hiding this comment

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

LGTM thanks for addressing the comments! Happy to see the unresolved items tracked by issues if the intention is to merge the migrated code first.

Signed-off-by: chensuyue <[email protected]>
Signed-off-by: chensuyue <[email protected]>
Signed-off-by: chensuyue <[email protected]>
Signed-off-by: chensuyue <[email protected]>
@thuang6
Copy link
Contributor

thuang6 commented May 9, 2024

I suggest using the ruff formatter over black, because it is much faster: https://docs.astral.sh/ruff/formatter/

tracked issue Suggest using the ruff formatter over black for this comment

@thuang6 thuang6 merged commit aa60571 into main May 10, 2024
1 check passed
@hshen14
Copy link
Contributor

hshen14 commented May 11, 2024

Thanks @justinchuby @freddychiu for your review!

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

Successfully merging this pull request may close these issues.

6 participants