示例#1
0
def _init_test_repo():
    repo = Repo.default_repo(init=True)
    # some unittests check sequence tracking in a separate thread
    # need to make sure task_queue is there
    os.environ[AIM_ENABLE_TRACKING_THREAD] = 'ON'
    Repo.tracking_queue = _get_tracking_queue()
    del os.environ[AIM_ENABLE_TRACKING_THREAD]
示例#2
0
def select_metrics(search_statement: str, repo_path: Optional[str] = None):
    if repo_path is not None:
        repo = Repo.from_path(repo_path)
    else:
        repo = Repo.default_repo()

    if not repo:
        return None

    return repo.query_metrics(search_statement)
示例#3
0
文件: select.py 项目: admariner/aim
def select_runs(expression: Optional[str] = None, repo_path: Optional[str] = None):
    if repo_path is not None:
        repo = Repo.from_path(repo_path)
    else:
        repo = Repo.default_repo()

    if not repo:
        return None

    return repo.query_runs(expression)
示例#4
0
    def __init__(self,
                 hashname: Optional[str] = None,
                 *,
                 repo: Optional[Union[str, 'Repo']] = None,
                 read_only: bool = False,
                 experiment: Optional[str] = None,
                 system_tracking_interval: int = DEFAULT_SYSTEM_TRACKING_INT):
        hashname = hashname or generate_run_hash()

        self._instance_creation_time = time()
        if repo is None:
            from aim.sdk.repo import Repo
            repo = Repo.default_repo()
        elif isinstance(repo, str):
            from aim.sdk.repo import Repo
            repo = Repo.from_path(repo)

        self.repo = repo
        self.read_only = read_only
        if not read_only:
            logger.debug(f'Opening Run {hashname} in write mode')

        self.hashname = hashname
        self._hash = None
        self._props = None

        self.contexts: Dict[Context, int] = dict()

        if experiment:
            self.props.experiment = experiment

        self.meta_tree: TreeView = self.repo.request(
            'meta', hashname, read_only=read_only,
            from_union=True).tree().view('meta')
        self.meta_run_tree: TreeView = self.meta_tree.view('chunks').view(
            hashname)

        self.meta_attrs_tree: TreeView = self.meta_tree.view('attrs')
        self.meta_run_attrs_tree: TreeView = self.meta_run_tree.view('attrs')

        self.series_run_tree: TreeView = self.repo.request(
            'trcs', hashname, read_only=read_only).tree().view('trcs').view(
                'chunks').view(hashname)
        if not read_only:
            # TODO: [AT] check this once Container db open locking is added
            self.series_run_tree.preload()

        self.series_counters: Dict[Tuple[Context, str], int] = Counter()

        self._creation_time = None
        self._system_resource_tracker: ResourceTracker = None
        if not read_only:
            self.props
            self.creation_time
            self._prepare_resource_tracker(system_tracking_interval)
示例#5
0
def remove_test_data():
    repo = Repo.default_repo()
    repo.container_pool.clear()
    repo.container_view_pool.clear()
    repo.persistent_pool.clear()
    truncate_structured_db(repo.structured_db)

    repo_path_base = repo.path
    shutil.rmtree(os.path.join(repo_path_base, 'meta'), ignore_errors=True)
    shutil.rmtree(os.path.join(repo_path_base, 'seqs'), ignore_errors=True)
    shutil.rmtree(os.path.join(repo_path_base, 'locks'), ignore_errors=True)
    shutil.rmtree(os.path.join(repo_path_base, 'progress'), ignore_errors=True)
示例#6
0
def fill_up_test_data():
    remove_test_data()

    # put dummy data into test repo with 10 runs, tracking 2 metrics over 3 contexts
    repo = Repo.default_repo()
    run_hashes = [hex(random.getrandbits(64))[-7:] for _ in range(10)]

    contexts = [{
        'is_training': True,
        'subset': 'train'
    }, {
        'is_training': True,
        'subset': 'val'
    }, {
        'is_training': False
    }]
    metrics = ['loss', 'accuracy']

    with repo.structured_db:
        try:
            for idx, hash_name in enumerate(run_hashes):
                run = Run(hashname=hash_name,
                          repo=repo,
                          system_tracking_interval=None)
                run['hparams'] = create_run_params()
                run['run_index'] = idx
                run['start_time'] = datetime.datetime.utcnow().isoformat()
                run['name'] = f'Run # {idx}'
                run.props.name = run['name']

                metric_contexts = itertools.product(metrics, contexts)
                for metric_context in metric_contexts:
                    metric = metric_context[0]
                    context = metric_context[1]
                    if metric == 'accuracy' and 'subset' in context:
                        continue
                    else:
                        # track 100 values per run
                        for step in range(100):
                            val = 1.0 - 1.0 / (step + 1)
                            run.track(val,
                                      name=metric,
                                      step=step,
                                      epoch=1,
                                      context=context)
        finally:
            del run
示例#7
0
    def __init__(self, repo: Optional[str] = None,
                 experiment: Optional[str] = None,
                 flush_frequency: int = 0,  # unused
                 block_termination: bool = True,  # unused
                 run: Optional[str] = None,
                 system_tracking_interval: Optional[int] = DEFAULT_SYSTEM_TRACKING_INT):

        self._repo = Repo.from_path(repo) if repo else Repo.default_repo()
        self._repo_path = self._repo.path
        self._run = Run(run, repo=self._repo, experiment=experiment,
                        system_tracking_interval=system_tracking_interval)
        self._run_hash = self._run.hashname
        self.active = True

        Session.sessions.setdefault(self._repo_path, [])
        Session.sessions[self._repo_path].append(self)

        # Bind signal listeners
        self._set_exit_handlers()
示例#8
0
 def setUpClass(cls) -> None:
     super().setUpClass()
     cls.repo = Repo.default_repo()
示例#9
0
文件: base.py 项目: admariner/aim
 def setUpClass(cls) -> None:
     fill_up_test_data()
     cls.repo = Repo.default_repo()
示例#10
0
文件: commands.py 项目: admariner/aim
def up(dev, host, port, repo, tf_logs):
    repo_path = clean_repo_path(repo)
    if repo_path:
        repo_inst = Repo.from_path(repo_path)
    else:
        repo_inst = Repo.default_repo()
    repo_inst.structured_db.run_upgrades()

    os.environ[AIM_UI_MOUNTED_REPO_PATH] = repo_inst.path

    if dev:
        os.environ[AIM_WEB_ENV_KEY] = 'dev'
    else:
        os.environ[AIM_WEB_ENV_KEY] = 'prod'

    if tf_logs:
        os.environ[AIM_TF_LOGS_PATH_KEY] = tf_logs

    try:
        db_cmd = build_db_upgrade_command()
        exec_cmd(db_cmd, stream_output=True)
    except ShellCommandException:
        click.echo('Failed to initialize Aim DB. ' +
                   'Please see the logs above for details.')
        return

    if dev or (os.getenv(AIM_UI_TELEMETRY_KEY) is not None
               and os.getenv(AIM_UI_TELEMETRY_KEY) == '0'):
        os.environ[AIM_UI_TELEMETRY_KEY] = '0'
    else:
        os.environ[AIM_UI_TELEMETRY_KEY] = '1'
        alert_msg = 'Aim UI collects anonymous usage analytics.'
        opt_out_msg = 'Read how to opt-out here: '
        opt_out_url = 'https://github.com/aimhubio/aim#anonymized-telemetry'
        line_width = max(len(opt_out_msg), len(alert_msg)) + 16
        click.echo('┌{}┐'.format('-' * (line_width - 2)))
        click.echo('{}{}{}'.format(' ' * ((line_width - len(alert_msg)) // 2),
                                   alert_msg,
                                   ' ' * ((line_width - len(alert_msg)) // 2)))
        click.echo('{}{}{}'.format(
            ' ' * ((line_width - len(opt_out_msg)) // 2), opt_out_msg,
            ' ' * ((line_width - len(opt_out_msg)) // 2)))
        click.echo('{}{}{}'.format(
            ' ' * ((line_width - len(opt_out_url)) // 2), opt_out_url,
            ' ' * ((line_width - len(opt_out_url)) // 2)))
        click.echo('└{}┘'.format('-' * (line_width - 2)))

    click.echo(
        click.style('Running Aim UI on repo `{}`'.format(repo_inst),
                    fg='yellow'))

    click.echo('Open http://{}:{}'.format(host, port))
    click.echo('Press Ctrl+C to exit')

    try:
        server_cmd = build_uvicorn_command(host, port, 1)
        exec_cmd(server_cmd, stream_output=True)
    except ShellCommandException:
        click.echo('Failed to run Aim UI. ' +
                   'Please see the logs above for details.')
        return