-
Notifications
You must be signed in to change notification settings - Fork 498
[KUNLUNXIN][BUF-FIX]fix that transformer engine disable benchmark logger #1241
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,8 @@ | |
|
|
||
| device = flag_gems.device | ||
| vendor_name = flag_gems.vendor_name | ||
| recordLogger = logging.getLogger("flag_gems.benchmark.record") | ||
| recordLogger.propagate = False | ||
|
|
||
|
|
||
| class BenchConfig: | ||
|
|
@@ -165,12 +167,23 @@ def pytest_configure(config): | |
| for arg in config.invocation_params.args | ||
| ] | ||
|
|
||
| logging.basicConfig( | ||
| filename="result_{}.log".format("_".join(cmd_args)).replace("_-", "-"), | ||
| filemode="w", | ||
| level=logging.INFO, | ||
| format="[%(levelname)s] %(message)s", | ||
| ) | ||
| log_file = "result_{}.log".format("_".join(cmd_args)).replace("_-", "-") | ||
|
|
||
| for h in list(recordLogger.handlers): | ||
| recordLogger.removeHandler(h) | ||
| try: | ||
| h.close() | ||
| except Exception as e: | ||
| import warnings | ||
|
|
||
| warnings.warn(f"Failed to close handler: {e}") | ||
|
|
||
| handler = logging.FileHandler(log_file, mode="w", encoding="utf-8") | ||
| handler.setLevel(logging.INFO) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wait a min, the default logger in global level is debug, should we keep the same log level?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logger is dedicated to recording benchmark results (metrics & JSON summaries) rather than debug traces. Using logging.INFO is intentional here because we only want to capture the final performance data. Setting it to DEBUG isn't necessary for this purpose and might introduce unwanted noise if we ever add debug logs to this specific logger in the future. We are strictly maintaining the original behavior, as the previous code also used level=logging.INFO. |
||
| handler.setFormatter(logging.Formatter("[%(levelname)s] %(message)s")) | ||
| recordLogger.addHandler(handler) | ||
| recordLogger.setLevel(logging.INFO) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may I know why setLevel twice?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is necessary because we are configuring a named non-root logger to isolate our benchmark results, which follows the standard Python logging behavior (as seen in the Logging Cookbook ). Why set level twice?
So, setting both ensures our log isolation works correctly and robustly." |
||
| recordLogger.info("Benchmark record logger enabled") | ||
|
|
||
|
|
||
| BUILTIN_MARKS = { | ||
|
|
@@ -239,4 +252,4 @@ def extract_and_log_op_attributes(request): | |
| yield | ||
|
|
||
| if Config.record_log and op_attributes: | ||
| logging.info(json.dumps(op_attributes, indent=2)) | ||
| recordLogger.info(json.dumps(op_attributes, indent=2)) | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,5 @@ | ||||||
| import gc | ||||||
| import importlib | ||||||
| import logging | ||||||
| import os | ||||||
| import time | ||||||
| from typing import Any, Generator, List, Optional, Tuple | ||||||
|
|
@@ -26,7 +25,7 @@ | |||||
| OperationAttribute, | ||||||
| check_metric_dependencies, | ||||||
| ) | ||||||
| from .conftest import Config | ||||||
| from .conftest import Config, recordLogger | ||||||
|
|
||||||
| torch_backend_device = flag_gems.runtime.torch_backend_device | ||||||
| torch_device_fn = flag_gems.runtime.torch_device_fn | ||||||
|
|
@@ -372,7 +371,7 @@ def run(self): | |||||
| shape_desc=self.shape_desc, | ||||||
| ) | ||||||
| print(attri) | ||||||
|
kiddyjinjin marked this conversation as resolved.
|
||||||
| logging.info(attri.to_dict()) | ||||||
| recordLogger.info(attri.to_dict()) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I don't get time to go through all 374 lines above. My question: as default logger( Back to
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me clarify the relationship between enable_gems and this fix, and provide evidence for the issue.
Conclusion: We have tested that without this fix, pytest ... --record log fails to generate the result file in this environment. This PR fixes it by using a dedicated logger that bypasses the polluted Root Logger.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tengqm , I will skip review this PR for now. FlagGems/benchmark/performance_utils.py Lines 427 to 428 in 4eda19f
I am confusing....it seems we are not using standard pytest or pytest-benchmark plugin.... @kiddyjinjin , @dongjibin1996 please move/go ahead. |
||||||
| return | ||||||
| self.init_user_config() | ||||||
| for dtype in self.to_bench_dtypes: | ||||||
|
|
@@ -425,7 +424,7 @@ def run(self): | |||||
| result=metrics, | ||||||
| ) | ||||||
| print(result) | ||||||
|
kiddyjinjin marked this conversation as resolved.
|
||||||
| logging.info(result.to_json()) | ||||||
| recordLogger.info(result.to_json()) | ||||||
|
|
||||||
|
|
||||||
| class GenericBenchmark(Benchmark): | ||||||
|
|
||||||

Uh oh!
There was an error while loading. Please reload this page.