Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit 5b988d6

Browse files
authored
ensure only rank 0 worker writes to terminal (#4445)
* ensure only rank 0 worker writes to terminal * update CHANGELOG
1 parent 8482f02 commit 5b988d6

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
- Log the grad norm properly even when we're not clipping it.
2323
- Fixed a bug where `PretrainedModelInitializer` fails to initialize a model with a 0-dim tensor
2424
- Fixed a bug with the layer unfreezing schedule of the `SlantedTriangular` learning rate scheduler.
25+
- Fixed a regression with logging in the distributed setting. Only the main worker should write log output to the terminal.
2526

2627
### Added
2728

allennlp/common/logging.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ def prepare_global_logging(serialization_dir: str, rank: int = 0, world_size: in
9292
root_logger.setLevel(LEVEL)
9393

9494
# put all the handlers on the root logger
95-
for handler in [file_handler, stdout_handler, stderr_handler]:
96-
root_logger.addHandler(handler)
95+
root_logger.addHandler(file_handler)
96+
if rank == 0:
97+
root_logger.addHandler(stdout_handler)
98+
root_logger.addHandler(stderr_handler)
9799

98100
# write uncaught exceptions to the logs
99101
def excepthook(exctype, value, traceback):

0 commit comments

Comments
 (0)