Esempio n. 1
0
def _track_legacy_run_step(run: Run, metric_name: str, context: dict, val):
    (value, step, epoch, timestamp) = val

    from aim.storage.context import Context, Metric
    if context is None:
        context = {}

    ctx = Context(context)
    metric = Metric(metric_name, ctx)

    if ctx not in run.contexts:
        run.meta_tree['contexts', ctx.idx] = ctx.to_dict()
        run.meta_run_tree['contexts', ctx.idx] = ctx.to_dict()
        run.contexts[ctx] = ctx.idx
        run._idx_to_ctx[ctx.idx] = ctx

    time_view = run.series_run_tree.view(metric.selector).array('time').allocate()
    val_view = run.series_run_tree.view(metric.selector).array('val').allocate()
    epoch_view = run.series_run_tree.view(metric.selector).array('epoch').allocate()

    max_idx = run.series_counters.get((ctx, metric_name), None)
    if max_idx == None:
        max_idx = len(val_view)
    if max_idx == 0:
        run.meta_tree['traces', ctx.idx, metric_name] = 1
    run.meta_run_tree['traces', ctx.idx, metric_name, "last"] = value

    run.series_counters[ctx, metric_name] = max_idx + 1

    time_view[step] = timestamp
    val_view[step] = value
    epoch_view[step] = epoch
Esempio n. 2
0
    def track(
        self,
        value,
        name: str,
        step: int = None,
        epoch: int = None,
        *,
        context: AimObject = None,
    ):
        track_time = time()
        # TODO move to Trace
        if context is None:
            context = {}

        value = convert_to_py_number(value)

        ctx = Context(context)
        metric = Metric(name, ctx)

        if ctx not in self.contexts:
            self.meta_tree['contexts', ctx.idx] = ctx.to_dict()
            self.meta_run_tree['contexts', ctx.idx] = ctx.to_dict()
            self.contexts[ctx] = ctx.idx
            self._idx_to_ctx[ctx.idx] = ctx

        val_view = self.series_run_tree.view(
            metric.selector).array('val').allocate()
        epoch_view = self.series_run_tree.view(
            metric.selector).array('epoch').allocate()
        time_view = self.series_run_tree.view(
            metric.selector).array('time').allocate()

        max_idx = self.series_counters.get((ctx, name), None)
        if max_idx == None:
            max_idx = len(val_view)
        if max_idx == 0:
            self.meta_tree['traces', ctx.idx, name] = 1
        self.meta_run_tree['traces', ctx.idx, name, "last"] = value

        self.series_counters[ctx, name] = max_idx + 1

        # TODO perform assignments in an atomic way

        if step is None:
            step = max_idx
        val_view[step] = value
        epoch_view[step] = epoch
        time_view[step] = track_time