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

[MetaSchedule] Logging Interface Unification #11157

Merged
merged 19 commits into from
May 4, 2022

Conversation

zxybazh
Copy link
Member

@zxybazh zxybazh commented Apr 28, 2022

This PR introduces a new interface to unify meta schedule logging from both c++ and python side. It will be easier to control logging level and format content. From now on, only task scheduler level will be printed to screen by default, and task level information will be logged to a file in given folder. We still support any logging configuration from outside, and use tvm.meta_schedule as the main logger.

The interface uses logger on the python side while on the c++ side we created a new macro called TVM_PY_LOG to work int the following style where logging_func is the optional packed function for logging (thanks to #10032 ):

TVM_PY_LOG(DEBUG, logging_func)
TVM_PY_LOG(INFO, logging_func)
TVM_PY_LOG(WARNING, logging_func)
TVM_PY_LOG(ERROR, logging_func)

The logger would fall back to original c++ logger function LOG(Level) if given logging function is not defined.

Recomended setup of logger is as follows:

logging.getLogger("tvm.meta_schedule").setLevel(logging.INFO)
# Use logging.DEBUG if debugging

And further configuration of task level loggers can be set in TuneConfig for features like whether to stream to screen, whether to propagate to main logger, patterns, etc, by passing a Dict to TuneConfig as follows:

TuneConfig(
    ...,
    logger_config = {
        "loggers": ...,
        "handlers": ...,
        "formatters": ...
    }
    # None if use default setting.
    # The strings can be parameterized using any parameter given in create_loggers function
    # for example, `{logger_name}` and `{log_dir}` can be used for parameterization in tune_extracted_tasks function.
)

Default setting is to output to files in log_dir folder and the logging structure looks like the following directory:

tvm.meta_schedule.tune.task_00_fused_nn_conv2d_add.log
tvm.meta_schedule.tune.task_01_fused_nn_conv2d_add_1.log
tvm.meta_schedule.tune.task_02_fused_nn_conv2d_add_2.log
tvm.meta_schedule.tune.task_03_fused_layout_transform.log
tvm.meta_schedule.tune.task_04_fused_nn_conv2d_add_nn_relu.log
tvm.meta_schedule.tune.task_05_fused_nn_max_pool2d.log
tvm.meta_schedule.tune.task_06_fused_nn_conv2d_add_nn_relu_1.log
tvm.meta_schedule.tune.task_07_fused_nn_conv2d_add_add_nn_relu.log
tvm.meta_schedule.tune.task_08_fused_nn_conv2d_add_nn_relu_2.log
tvm.meta_schedule.tune.task_09_fused_nn_contrib_conv2d_winograd_without_weight_transform_add_nn_relu.log
tvm.meta_schedule.tune.task_10_fused_nn_contrib_conv2d_winograd_without_weight_transform_add_add_nn_relu.log
tvm.meta_schedule.tune.task_11_fused_nn_conv2d_add_nn_relu_3.log
tvm.meta_schedule.tune.task_12_fused_nn_contrib_conv2d_winograd_without_weight_transform_add_nn_relu_1.log
tvm.meta_schedule.tune.task_13_fused_nn_contrib_conv2d_winograd_without_weight_transform_add_add_nn_relu_1.log
tvm.meta_schedule.tune.task_14_fused_nn_conv2d_add_nn_relu_4.log
tvm.meta_schedule.tune.task_15_fused_nn_conv2d_add_nn_relu_5.log
tvm.meta_schedule.tune.task_16_fused_nn_conv2d_add_add_nn_relu_1.log
tvm.meta_schedule.tune.task_17_fused_nn_adaptive_avg_pool2d.log
tvm.meta_schedule.tune.task_18_fused_layout_transform_reshape_squeeze.log
tvm.meta_schedule.tune.task_19_fused_nn_dense_add.log
tvm.meta_schedule.tune.task_scheduler.log

Suggestions are welcome!

CC: @junrushao1994 @shingjan @comaniac

@junrushao
Copy link
Member

Thanks for massively enhancing the current logging system!

However, on the implementation, we do need to follow the standard best practice in python, namely, using:

logger = logging.getLogger(__name__)

to get a logger for this file.

@zxybazh
Copy link
Member Author

zxybazh commented Apr 29, 2022

Thanks for the careful review, I've fixed all the logger usage and made sure it follows the current recommended practice. Ready for review.

@@ -17,7 +17,8 @@
"""User-facing Tuning API"""
# pylint: disable=import-outside-toplevel
import logging
import os.path
from pathlib import Path
Copy link
Member

Choose a reason for hiding this comment

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

Pathlib is definitely a good library, but perhaps it's less plausible if we mix os.path and Pathlib. In our particular case, shall we just do:

os.makedirs(path, exist_ok=False)

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it might be acceptable to use exist_ok = True in this case cause the logs folder could be reused.

@zxybazh zxybazh force-pushed the feature/2022-04-20/logging-refactor branch from d49fa1f to feb2bfe Compare April 29, 2022 18:50
@@ -32,12 +32,14 @@ class CrossThreadReductionNode : public ScheduleRuleNode {
Optional<Integer> opt_warp_size = target->GetAttr<Integer>("thread_warp_size");

if (!opt_max_threads_per_block.defined()) {
LOG(WARNING) << "Target does not have attribute \"max_threads_per_block\", therefore the "
"rule CrossThreadReduction will not be applied";
TVM_PY_LOG(WARNING, context->logging_func)
Copy link
Member

Choose a reason for hiding this comment

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

I was thinking if it's better to make it a LOG(FATAL) instead, but it's do that in a separate PR

@zxybazh zxybazh force-pushed the feature/2022-04-20/logging-refactor branch from e9a1d8c to 2863996 Compare April 29, 2022 23:41
@junrushao
Copy link
Member

Any updates?

Copy link
Member

@junrushao junrushao left a comment

Choose a reason for hiding this comment

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

LGTM! Please try it out for the last time and confirm it prints the dates properly, and then feel free to merge it yourself

@zxybazh zxybazh merged commit 01e1606 into apache:main May 4, 2022
@zxybazh
Copy link
Member Author

zxybazh commented May 4, 2022

Thanks @junrushao1994 @Hzfengsy for reviewing!

shtinsa pushed a commit to Deelvin/tvm that referenced this pull request May 17, 2022
* Implement new logging interface.

* Major interface usage update.

* Functionality fix.

* Switch logging conditions.

* Tweak logging interface.

* Minor fix.

* Feature updates.

* Logging usage.

* Linting.

* Fix linting.

* Fix handler type.

* Fix issues.

* Nits.

* Address issues.

* Add DEBUG level fall back.

* Minor fixes.

* Allow parameterized configuration.

* Linting.

* Polish interface.
SebastianBoblest pushed a commit to SebastianBoblest/tvm that referenced this pull request May 27, 2022
* Implement new logging interface.

* Major interface usage update.

* Functionality fix.

* Switch logging conditions.

* Tweak logging interface.

* Minor fix.

* Feature updates.

* Logging usage.

* Linting.

* Fix linting.

* Fix handler type.

* Fix issues.

* Nits.

* Address issues.

* Add DEBUG level fall back.

* Minor fixes.

* Allow parameterized configuration.

* Linting.

* Polish interface.
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.

3 participants