コード例 #1
0
def setup_logger(config):
    log_path = config.get("log_path", os.getcwd())
    if is_main_process():
        backends = [
            TensorBoardBackend(verbosity=dllogger.Verbosity.VERBOSE,
                               log_dir=log_path),
            JSONStreamBackend(verbosity=dllogger.Verbosity.VERBOSE,
                              filename=os.path.join(log_path, "log.json")),
            AggregatorBackend(verbosity=dllogger.Verbosity.VERBOSE,
                              agg_dict={"loss": AverageMeter}),
            StdOutBackend(
                verbosity=dllogger.Verbosity.DEFAULT,
                step_format=empty_step_format,
                metric_format=no_string_metric_format,
                prefix_format=empty_prefix_format,
            ),
        ]

        logger = Logger(backends=backends)
    else:
        logger = Logger(backends=[])
    container_setup_info = get_framework_env_vars()
    logger.log(step="PARAMETER",
               data=container_setup_info,
               verbosity=dllogger.Verbosity.DEFAULT)

    logger.metadata("loss", {
        "unit": "nat",
        "GOAL": "MINIMIZE",
        "STAGE": "TRAIN"
    })
    logger.metadata("val_loss", {
        "unit": "nat",
        "GOAL": "MINIMIZE",
        "STAGE": "VAL"
    })
    return logger
コード例 #2
0
class dllogger_class():
    def format_step(self, step):
        if isinstance(step, str):
            return step
        elif isinstance(step, int):
            return "Iteration: {} ".format(step)
        elif len(step) > 0:
            return "Iteration: {} ".format(step[0])
        else:
            return ""

    def __init__(self, log_path="bert_dllog.json"):
        self.logger = Logger([
            StdOutBackend(Verbosity.DEFAULT, step_format=self.format_step),
            JSONStreamBackend(Verbosity.VERBOSE, log_path),
        ])
        self.logger.metadata("mlm_loss", {
            "format": ":.4f",
            "GOAL": "MINIMIZE",
            "STAGE": "TRAIN"
        })
        self.logger.metadata("nsp_loss", {
            "format": ":.4f",
            "GOAL": "MINIMIZE",
            "STAGE": "TRAIN"
        })
        self.logger.metadata("avg_loss_step", {
            "format": ":.4f",
            "GOAL": "MINIMIZE",
            "STAGE": "TRAIN"
        })
        self.logger.metadata("total_loss", {
            "format": ":.4f",
            "GOAL": "MINIMIZE",
            "STAGE": "TRAIN"
        })
        self.logger.metadata("loss", {
            "format": ":.4f",
            "GOAL": "MINIMIZE",
            "STAGE": "TRAIN"
        })
        self.logger.metadata("f1", {
            "format": ":.4f",
            "GOAL": "MINIMIZE",
            "STAGE": "VAL"
        })
        self.logger.metadata("precision", {
            "format": ":.4f",
            "GOAL": "MINIMIZE",
            "STAGE": "VAL"
        })
        self.logger.metadata("recall", {
            "format": ":.4f",
            "GOAL": "MINIMIZE",
            "STAGE": "VAL"
        })
        self.logger.metadata("mcc", {
            "format": ":.4f",
            "GOAL": "MINIMIZE",
            "STAGE": "VAL"
        })
        self.logger.metadata("exact_match", {
            "format": ":.4f",
            "GOAL": "MINIMIZE",
            "STAGE": "VAL"
        })
        self.logger.metadata(
            "throughput_train",
            {
                "unit": "seq/s",
                "format": ":.3f",
                "GOAL": "MAXIMIZE",
                "STAGE": "TRAIN"
            },
        )
        self.logger.metadata(
            "throughput_inf",
            {
                "unit": "seq/s",
                "format": ":.3f",
                "GOAL": "MAXIMIZE",
                "STAGE": "VAL"
            },
        )
コード例 #3
0

l = Logger(
    [
        StdOutBackend(Verbosity.DEFAULT, step_format=format_step),
        JSONStreamBackend(Verbosity.VERBOSE, "tmp.json"),
    ]
)

# You can log metrics in separate calls
l.log(step="PARAMETER", data={"HP1": 17}, verbosity=Verbosity.DEFAULT)
l.log(step="PARAMETER", data={"HP2": 23}, verbosity=Verbosity.DEFAULT)
# or together
l.log(step="PARAMETER", data={"HP3": 1, "HP4": 2}, verbosity=Verbosity.DEFAULT)

l.metadata("loss", {"unit": "nat", "GOAL": "MINIMIZE", "STAGE": "TRAIN"})
l.metadata("val.loss", {"unit": "nat", "GOAL": "MINIMIZE", "STAGE": "VAL"})
l.metadata(
    "speed",
    {"unit": "speeds/s", "format": ":.3f", "GOAL": "MAXIMIZE", "STAGE": "TRAIN"},
)

for epoch in range(0, 2):

    for it in range(0, 10):
        l.log(
            step=(epoch, it),
            data={"loss": 130 / (1 + epoch * 10 + it)},
            verbosity=Verbosity.DEFAULT,
        )
        if it % 3 == 0: