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

[ONNX] Migrate to PT2 logging #106592

Closed
wants to merge 8 commits into from
Closed

Conversation

BowenBao
Copy link
Collaborator

@BowenBao BowenBao commented Aug 4, 2023

Stack from ghstack (oldest at bottom):

Summary

  • The 'dynamo_export' diagnostics leverages the PT2 artifact logger to handle the verbosity
    level of logs that are recorded in each SARIF log diagnostic. In addition to SARIF log,
    terminal logging is by default disabled. Terminal logging can be activated by setting
    the environment variable TORCH_LOGS="onnx_diagnostics". When the environment variable
    is set, it also fixes logging level to logging.DEBUG, overriding the verbosity level
    specified in the diagnostic options.
    See torch/_logging/__init__.py for more on PT2 logging.
  • Replaces 'with_additional_message' with 'Logger.log' like apis.
  • Introduce 'LazyString', adopted from 'torch._dynamo.utils', to skip
    evaluation if the message will not be logged into diagnostic.
  • Introduce 'log_source_exception' for easier exception logging.
  • Introduce 'log_section' for easier markdown title logging.
  • Updated all existing code to use new api.
  • Removed 'arg_format_too_verbose' diagnostic.
  • Rename legacy diagnostic classes for TorchScript Onnx Exporter to avoid
    confusion.

Follow ups

  • The 'dynamo_export' diagnostic now will not capture python stack
    information at point of diagnostic creation. This will be added back in
    follow up PRs for debug level logging.
  • There is type mismatch due to subclassing 'Diagnostic' and 'DiagnosticContext'
    for 'dynamo_export' to incorporate with PT2 logging. Follow up PR will
    attempt to fix it.
  • More docstrings with examples.

Summary
- 'dynamo_export' diagnostics now utilize PT2 artifact logger to manage
the verbosity level of logs recorded into each diagnostic in SARIF log.
The terminal logging is by default turned off. Setting environment variable
'TORCH_LOGS="+onnx_diagnostics"' turns on terminal logging, as well as
adjusts the verbosity level which overrides that in diagnostic options.
Replaces 'with_additional_message' with 'Logger.log' like apis.
- Introduce 'LazyString', adopted from 'torch._dynamo.utils', to skip
evaluation if the message will not be logged into diagnostic.
- Introduce 'log_source_exception' for easier exception logging.
- Introduce 'log_section' for easier markdown title logging.
- Updated all existing code to use new api.
- Removed 'arg_format_too_verbose' diagnostic.
- Rename legacy diagnostic classes for TorchScript Onnx Exporter to avoid
confusion.

Follow ups
- The 'dynamo_export' diagnostic now will not capture python stack
information at point of diagnostic creation. This will be added back in
follow up PRs for debug level logging.
- There is type mismatch due to subclassing 'Diagnostic' and 'DiagnosticContext'
for 'dynamo_export' to incorporate with PT2 logging. Follow up PR will
attempt to fix it.
- More docstrings with examples.

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Aug 4, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/106592

Note: Links to docs will display an error until the docs builds have been completed.

✅ 3 Unrelated Failures

As of commit 0e223a3:

UNSTABLE - The following jobs failed but were likely due to flakiness present on trunk and has been marked as unstable:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot bot added the release notes: onnx torch.onnx related changes that should show up in the release notes label Aug 4, 2023
BowenBao added a commit that referenced this pull request Aug 4, 2023
Summary
- 'dynamo_export' diagnostics now utilize PT2 artifact logger to manage
the verbosity level of logs recorded into each diagnostic in SARIF log.
The terminal logging is by default turned off. Setting environment variable
'TORCH_LOGS="+onnx_diagnostics"' turns on terminal logging, as well as
adjusts the verbosity level which overrides that in diagnostic options.
Replaces 'with_additional_message' with 'Logger.log' like apis.
- Introduce 'LazyString', adopted from 'torch._dynamo.utils', to skip
evaluation if the message will not be logged into diagnostic.
- Introduce 'log_source_exception' for easier exception logging.
- Introduce 'log_section' for easier markdown title logging.
- Updated all existing code to use new api.
- Removed 'arg_format_too_verbose' diagnostic.
- Rename legacy diagnostic classes for TorchScript Onnx Exporter to avoid
confusion.

Follow ups
- The 'dynamo_export' diagnostic now will not capture python stack
information at point of diagnostic creation. This will be added back in
follow up PRs for debug level logging.
- There is type mismatch due to subclassing 'Diagnostic' and 'DiagnosticContext'
for 'dynamo_export' to incorporate with PT2 logging. Follow up PR will
attempt to fix it.
- More docstrings with examples.

ghstack-source-id: cb731ec7ee3957ff26367ff52419766de6fa9b65
Pull Request resolved: #106592
Summary
- 'dynamo_export' diagnostics now utilize PT2 artifact logger to manage
the verbosity level of logs recorded into each diagnostic in SARIF log.
The terminal logging is by default turned off. Setting environment variable
'TORCH_LOGS="+onnx_diagnostics"' turns on terminal logging, as well as
adjusts the verbosity level which overrides that in diagnostic options.
- Replaces 'with_additional_message' with 'Logger.log' like apis.
- Introduce 'LazyString', adopted from 'torch._dynamo.utils', to skip
evaluation if the message will not be logged into diagnostic.
- Introduce 'log_source_exception' for easier exception logging.
- Introduce 'log_section' for easier markdown title logging.
- Updated all existing code to use new api.
- Removed 'arg_format_too_verbose' diagnostic.
- Rename legacy diagnostic classes for TorchScript Onnx Exporter to avoid
confusion.

Follow ups
- The 'dynamo_export' diagnostic now will not capture python stack
information at point of diagnostic creation. This will be added back in
follow up PRs for debug level logging.
- There is type mismatch due to subclassing 'Diagnostic' and 'DiagnosticContext'
for 'dynamo_export' to incorporate with PT2 logging. Follow up PR will
attempt to fix it.
- More docstrings with examples.

[ghstack-poisoned]
BowenBao added a commit that referenced this pull request Aug 4, 2023
Summary
- 'dynamo_export' diagnostics now utilize PT2 artifact logger to manage
the verbosity level of logs recorded into each diagnostic in SARIF log.
The terminal logging is by default turned off. Setting environment variable
'TORCH_LOGS="+onnx_diagnostics"' turns on terminal logging, as well as
adjusts the verbosity level which overrides that in diagnostic options.
Replaces 'with_additional_message' with 'Logger.log' like apis.
- Introduce 'LazyString', adopted from 'torch._dynamo.utils', to skip
evaluation if the message will not be logged into diagnostic.
- Introduce 'log_source_exception' for easier exception logging.
- Introduce 'log_section' for easier markdown title logging.
- Updated all existing code to use new api.
- Removed 'arg_format_too_verbose' diagnostic.
- Rename legacy diagnostic classes for TorchScript Onnx Exporter to avoid
confusion.

Follow ups
- The 'dynamo_export' diagnostic now will not capture python stack
information at point of diagnostic creation. This will be added back in
follow up PRs for debug level logging.
- There is type mismatch due to subclassing 'Diagnostic' and 'DiagnosticContext'
for 'dynamo_export' to incorporate with PT2 logging. Follow up PR will
attempt to fix it.
- More docstrings with examples.

ghstack-source-id: 4cc785e10fb4a9eccf9b62e7f9540cb5aa2bc0e8
Pull Request resolved: #106592
@BowenBao BowenBao added the topic: improvements topic category label Aug 4, 2023
Summary
- 'dynamo_export' diagnostics now utilize PT2 artifact logger to manage
the verbosity level of logs recorded into each diagnostic in SARIF log.
The terminal logging is by default turned off. Setting environment variable
'TORCH_LOGS="+onnx_diagnostics"' turns on terminal logging, as well as
adjusts the verbosity level which overrides that in diagnostic options.
- Replaces 'with_additional_message' with 'Logger.log' like apis.
- Introduce 'LazyString', adopted from 'torch._dynamo.utils', to skip
evaluation if the message will not be logged into diagnostic.
- Introduce 'log_source_exception' for easier exception logging.
- Introduce 'log_section' for easier markdown title logging.
- Updated all existing code to use new api.
- Removed 'arg_format_too_verbose' diagnostic.
- Rename legacy diagnostic classes for TorchScript Onnx Exporter to avoid
confusion.

Follow ups
- The 'dynamo_export' diagnostic now will not capture python stack
information at point of diagnostic creation. This will be added back in
follow up PRs for debug level logging.
- There is type mismatch due to subclassing 'Diagnostic' and 'DiagnosticContext'
for 'dynamo_export' to incorporate with PT2 logging. Follow up PR will
attempt to fix it.
- More docstrings with examples.

[ghstack-poisoned]
BowenBao added a commit that referenced this pull request Aug 4, 2023
Summary
- 'dynamo_export' diagnostics now utilize PT2 artifact logger to manage
the verbosity level of logs recorded into each diagnostic in SARIF log.
The terminal logging is by default turned off. Setting environment variable
'TORCH_LOGS="+onnx_diagnostics"' turns on terminal logging, as well as
adjusts the verbosity level which overrides that in diagnostic options.
Replaces 'with_additional_message' with 'Logger.log' like apis.
- Introduce 'LazyString', adopted from 'torch._dynamo.utils', to skip
evaluation if the message will not be logged into diagnostic.
- Introduce 'log_source_exception' for easier exception logging.
- Introduce 'log_section' for easier markdown title logging.
- Updated all existing code to use new api.
- Removed 'arg_format_too_verbose' diagnostic.
- Rename legacy diagnostic classes for TorchScript Onnx Exporter to avoid
confusion.

Follow ups
- The 'dynamo_export' diagnostic now will not capture python stack
information at point of diagnostic creation. This will be added back in
follow up PRs for debug level logging.
- There is type mismatch due to subclassing 'Diagnostic' and 'DiagnosticContext'
for 'dynamo_export' to incorporate with PT2 logging. Follow up PR will
attempt to fix it.
- More docstrings with examples.

ghstack-source-id: 088f441b5f2f20c4a983194b7fb35c389a29582d
Pull Request resolved: #106592
Summary
- The 'dynamo_export' diagnostics leverages the PT2 artifact logger to handle the verbosity
level of logs that are recorded in each SARIF log diagnostic. In addition to SARIF log,
terminal logging is by default disabled. Terminal logging can be activated by setting
the environment variable `TORCH_LOGS="onnx_diagnostics"`. When the environment variable
is set, it also fixes logging level to `logging.DEBUG`, overriding the verbosity level
specified in the diagnostic options.
See `torch/_logging/__init__.py` for more on PT2 logging.
- Replaces 'with_additional_message' with 'Logger.log' like apis.
- Introduce 'LazyString', adopted from 'torch._dynamo.utils', to skip
evaluation if the message will not be logged into diagnostic.
- Introduce 'log_source_exception' for easier exception logging.
- Introduce 'log_section' for easier markdown title logging.
- Updated all existing code to use new api.
- Removed 'arg_format_too_verbose' diagnostic.
- Rename legacy diagnostic classes for TorchScript Onnx Exporter to avoid
confusion.

Follow ups
- The 'dynamo_export' diagnostic now will not capture python stack
information at point of diagnostic creation. This will be added back in
follow up PRs for debug level logging.
- There is type mismatch due to subclassing 'Diagnostic' and 'DiagnosticContext'
for 'dynamo_export' to incorporate with PT2 logging. Follow up PR will
attempt to fix it.
- More docstrings with examples.

[ghstack-poisoned]
BowenBao added a commit that referenced this pull request Aug 4, 2023
Summary
- 'dynamo_export' diagnostics now utilize PT2 artifact logger to manage
the verbosity level of logs recorded into each diagnostic in SARIF log.
The terminal logging is by default turned off. Setting environment variable
'TORCH_LOGS="+onnx_diagnostics"' turns on terminal logging, as well as
adjusts the verbosity level which overrides that in diagnostic options.
Replaces 'with_additional_message' with 'Logger.log' like apis.
- Introduce 'LazyString', adopted from 'torch._dynamo.utils', to skip
evaluation if the message will not be logged into diagnostic.
- Introduce 'log_source_exception' for easier exception logging.
- Introduce 'log_section' for easier markdown title logging.
- Updated all existing code to use new api.
- Removed 'arg_format_too_verbose' diagnostic.
- Rename legacy diagnostic classes for TorchScript Onnx Exporter to avoid
confusion.

Follow ups
- The 'dynamo_export' diagnostic now will not capture python stack
information at point of diagnostic creation. This will be added back in
follow up PRs for debug level logging.
- There is type mismatch due to subclassing 'Diagnostic' and 'DiagnosticContext'
for 'dynamo_export' to incorporate with PT2 logging. Follow up PR will
attempt to fix it.
- More docstrings with examples.

ghstack-source-id: b979765ade83f6372095cfc81708a31dc8984dca
Pull Request resolved: #106592
Summary
- The 'dynamo_export' diagnostics leverages the PT2 artifact logger to handle the verbosity
level of logs that are recorded in each SARIF log diagnostic. In addition to SARIF log,
terminal logging is by default disabled. Terminal logging can be activated by setting
the environment variable `TORCH_LOGS="onnx_diagnostics"`. When the environment variable
is set, it also fixes logging level to `logging.DEBUG`, overriding the verbosity level
specified in the diagnostic options.
See `torch/_logging/__init__.py` for more on PT2 logging.
- Replaces 'with_additional_message' with 'Logger.log' like apis.
- Introduce 'LazyString', adopted from 'torch._dynamo.utils', to skip
evaluation if the message will not be logged into diagnostic.
- Introduce 'log_source_exception' for easier exception logging.
- Introduce 'log_section' for easier markdown title logging.
- Updated all existing code to use new api.
- Removed 'arg_format_too_verbose' diagnostic.
- Rename legacy diagnostic classes for TorchScript Onnx Exporter to avoid
confusion.

Follow ups
- The 'dynamo_export' diagnostic now will not capture python stack
information at point of diagnostic creation. This will be added back in
follow up PRs for debug level logging.
- There is type mismatch due to subclassing 'Diagnostic' and 'DiagnosticContext'
for 'dynamo_export' to incorporate with PT2 logging. Follow up PR will
attempt to fix it.
- More docstrings with examples.

[ghstack-poisoned]
BowenBao added a commit that referenced this pull request Aug 5, 2023
Summary
- 'dynamo_export' diagnostics now utilize PT2 artifact logger to manage
the verbosity level of logs recorded into each diagnostic in SARIF log.
The terminal logging is by default turned off. Setting environment variable
'TORCH_LOGS="+onnx_diagnostics"' turns on terminal logging, as well as
adjusts the verbosity level which overrides that in diagnostic options.
Replaces 'with_additional_message' with 'Logger.log' like apis.
- Introduce 'LazyString', adopted from 'torch._dynamo.utils', to skip
evaluation if the message will not be logged into diagnostic.
- Introduce 'log_source_exception' for easier exception logging.
- Introduce 'log_section' for easier markdown title logging.
- Updated all existing code to use new api.
- Removed 'arg_format_too_verbose' diagnostic.
- Rename legacy diagnostic classes for TorchScript Onnx Exporter to avoid
confusion.

Follow ups
- The 'dynamo_export' diagnostic now will not capture python stack
information at point of diagnostic creation. This will be added back in
follow up PRs for debug level logging.
- There is type mismatch due to subclassing 'Diagnostic' and 'DiagnosticContext'
for 'dynamo_export' to incorporate with PT2 logging. Follow up PR will
attempt to fix it.
- More docstrings with examples.

ghstack-source-id: 9cac69b43b356d66852c8511a966203db9ea0bd1
Pull Request resolved: #106592
@BowenBao BowenBao marked this pull request as ready for review August 5, 2023 00:08
Summary
- The 'dynamo_export' diagnostics leverages the PT2 artifact logger to handle the verbosity
level of logs that are recorded in each SARIF log diagnostic. In addition to SARIF log,
terminal logging is by default disabled. Terminal logging can be activated by setting
the environment variable `TORCH_LOGS="onnx_diagnostics"`. When the environment variable
is set, it also fixes logging level to `logging.DEBUG`, overriding the verbosity level
specified in the diagnostic options.
See `torch/_logging/__init__.py` for more on PT2 logging.
- Replaces 'with_additional_message' with 'Logger.log' like apis.
- Introduce 'LazyString', adopted from 'torch._dynamo.utils', to skip
evaluation if the message will not be logged into diagnostic.
- Introduce 'log_source_exception' for easier exception logging.
- Introduce 'log_section' for easier markdown title logging.
- Updated all existing code to use new api.
- Removed 'arg_format_too_verbose' diagnostic.
- Rename legacy diagnostic classes for TorchScript Onnx Exporter to avoid
confusion.

Follow ups
- The 'dynamo_export' diagnostic now will not capture python stack
information at point of diagnostic creation. This will be added back in
follow up PRs for debug level logging.
- There is type mismatch due to subclassing 'Diagnostic' and 'DiagnosticContext'
for 'dynamo_export' to incorporate with PT2 logging. Follow up PR will
attempt to fix it.
- More docstrings with examples.

[ghstack-poisoned]
@titaiwangms
Copy link
Collaborator

Can #106478 be merged before this PR lol

@BowenBao
Copy link
Collaborator Author

BowenBao commented Aug 8, 2023

Can #106478 be merged before this PR lol

Sure, yours is earlier :)

@titaiwangms titaiwangms added the module: onnx Related to torch.onnx label Aug 8, 2023
Copy link
Collaborator

@titaiwangms titaiwangms left a comment

Choose a reason for hiding this comment

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

Is diagnostics.levels.ERROR affected?

docs/source/onnx_diagnostics.rst Show resolved Hide resolved
test/onnx/internal/test_diagnostics.py Show resolved Hide resolved
torch/onnx/_internal/fx/op_validation.py Show resolved Hide resolved
torch/onnx/_internal/fx/op_validation.py Show resolved Hide resolved
Summary
- The 'dynamo_export' diagnostics leverages the PT2 artifact logger to handle the verbosity
level of logs that are recorded in each SARIF log diagnostic. In addition to SARIF log,
terminal logging is by default disabled. Terminal logging can be activated by setting
the environment variable `TORCH_LOGS="onnx_diagnostics"`. When the environment variable
is set, it also fixes logging level to `logging.DEBUG`, overriding the verbosity level
specified in the diagnostic options.
See `torch/_logging/__init__.py` for more on PT2 logging.
- Replaces 'with_additional_message' with 'Logger.log' like apis.
- Introduce 'LazyString', adopted from 'torch._dynamo.utils', to skip
evaluation if the message will not be logged into diagnostic.
- Introduce 'log_source_exception' for easier exception logging.
- Introduce 'log_section' for easier markdown title logging.
- Updated all existing code to use new api.
- Removed 'arg_format_too_verbose' diagnostic.
- Rename legacy diagnostic classes for TorchScript Onnx Exporter to avoid
confusion.

Follow ups
- The 'dynamo_export' diagnostic now will not capture python stack
information at point of diagnostic creation. This will be added back in
follow up PRs for debug level logging.
- There is type mismatch due to subclassing 'Diagnostic' and 'DiagnosticContext'
for 'dynamo_export' to incorporate with PT2 logging. Follow up PR will
attempt to fix it.
- More docstrings with examples.

[ghstack-poisoned]
Summary
- The 'dynamo_export' diagnostics leverages the PT2 artifact logger to handle the verbosity
level of logs that are recorded in each SARIF log diagnostic. In addition to SARIF log,
terminal logging is by default disabled. Terminal logging can be activated by setting
the environment variable `TORCH_LOGS="onnx_diagnostics"`. When the environment variable
is set, it also fixes logging level to `logging.DEBUG`, overriding the verbosity level
specified in the diagnostic options.
See `torch/_logging/__init__.py` for more on PT2 logging.
- Replaces 'with_additional_message' with 'Logger.log' like apis.
- Introduce 'LazyString', adopted from 'torch._dynamo.utils', to skip
evaluation if the message will not be logged into diagnostic.
- Introduce 'log_source_exception' for easier exception logging.
- Introduce 'log_section' for easier markdown title logging.
- Updated all existing code to use new api.
- Removed 'arg_format_too_verbose' diagnostic.
- Rename legacy diagnostic classes for TorchScript Onnx Exporter to avoid
confusion.

Follow ups
- The 'dynamo_export' diagnostic now will not capture python stack
information at point of diagnostic creation. This will be added back in
follow up PRs for debug level logging.
- There is type mismatch due to subclassing 'Diagnostic' and 'DiagnosticContext'
for 'dynamo_export' to incorporate with PT2 logging. Follow up PR will
attempt to fix it.
- More docstrings with examples.

[ghstack-poisoned]
Copy link
Collaborator

@thiagocrepaldi thiagocrepaldi left a comment

Choose a reason for hiding this comment

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

Going OOF, so I will defer this to our colleagues. :)

The only thing I spotted is having a global logger instead of part of Diagnostic classes

@@ -16,6 +18,7 @@

# This is a workaround for mypy not supporting Self from typing_extensions.
_Diagnostic = TypeVar("_Diagnostic", bound="Diagnostic")
diagnostic_logger: logging.Logger = logging.getLogger(__name__)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to move to the diagnostic ctor? It is nicer to not depend on globals as much as 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.

Similar discussion here #106741 (comment) on idiomatic global logger.

It is a bit anti-pattern that Diagnostic needs to keep track of logger, but I feel it is better to keep track of the global logger instead of a global var of __name__ value here to retrieve that same logger.

@BowenBao
Copy link
Collaborator Author

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Aug 11, 2023
@BowenBao
Copy link
Collaborator Author

Merging but will address any more comments in follow ups.

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@facebook-github-bot facebook-github-bot deleted the gh/BowenBao/283/head branch August 15, 2023 14:17
nshankar118 pushed a commit to nshankar118/Pytorch that referenced this pull request Aug 15, 2023
Summary
- 'dynamo_export' diagnostics now utilize PT2 artifact logger to manage
the verbosity level of logs recorded into each diagnostic in SARIF log.
The terminal logging is by default turned off. Setting environment variable
'TORCH_LOGS="+onnx_diagnostics"' turns on terminal logging, as well as
adjusts the verbosity level which overrides that in diagnostic options.
Replaces 'with_additional_message' with 'Logger.log' like apis.
- Introduce 'LazyString', adopted from 'torch._dynamo.utils', to skip
evaluation if the message will not be logged into diagnostic.
- Introduce 'log_source_exception' for easier exception logging.
- Introduce 'log_section' for easier markdown title logging.
- Updated all existing code to use new api.
- Removed 'arg_format_too_verbose' diagnostic.
- Rename legacy diagnostic classes for TorchScript Onnx Exporter to avoid
confusion.

Follow ups
- The 'dynamo_export' diagnostic now will not capture python stack
information at point of diagnostic creation. This will be added back in
follow up PRs for debug level logging.
- There is type mismatch due to subclassing 'Diagnostic' and 'DiagnosticContext'
for 'dynamo_export' to incorporate with PT2 logging. Follow up PR will
attempt to fix it.
- More docstrings with examples.

ghstack-source-id: fd5ad1132f3a71c56a3d16c6c693ee088cdcc185
Pull Request resolved: pytorch/pytorch#106592
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk Trigger trunk jobs on your pull request Merged module: onnx Related to torch.onnx open source release notes: onnx torch.onnx related changes that should show up in the release notes topic: improvements topic category
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants