Beispiel #1
0
def test_deformatting():
    internal_space = format_search_space(user_space)
    assert deformat_parameters(internal_params_1,
                               internal_space) == user_params_1
    assert deformat_parameters(internal_params_2,
                               internal_space) == user_params_2
    assert deformat_parameters(internal_params_3,
                               internal_space) == user_params_3
Beispiel #2
0
def test_dedup_nested():
    space = format_search_space(nested_space)
    dedup = Deduplicator(space)
    params = set()
    for i in range(10):
        p = dedup(suggest(rng, space))
        s = nni.dump(deformat_parameters(p, space), sort_keys=True)
        assert s not in params
        params.add(s)
Beispiel #3
0
def test_dedup_finite():
    space = format_search_space(finite_space)
    dedup = Deduplicator(space)
    params = []
    exhausted = False
    try:
        for i in range(7):
            p = dedup(suggest(rng, space))
            params.append(deformat_parameters(p, space))
    except nni.NoMoreTrialError:
        exhausted = True
    params = sorted(params, key=(lambda p: (p['x'], p['y'], p['z'])))
    assert exhausted
    assert params == [
        {
            'x': 'a',
            'y': 0.0,
            'z': 1.0
        },
        {
            'x': 'a',
            'y': 0.6,
            'z': 1.0
        },
        {
            'x': 'a',
            'y': 1.0,
            'z': 1.0
        },
        {
            'x': 'b',
            'y': 0.0,
            'z': 1.0
        },
        {
            'x': 'b',
            'y': 0.6,
            'z': 1.0
        },
        {
            'x': 'b',
            'y': 1.0,
            'z': 1.0
        },
    ]
Beispiel #4
0
def test_activate():
    internal_space = format_search_space(user_space)

    assert internal_space[('pool', )].is_activated_in({})

    partial = {('pool', ): 1, ('kernel', ): 1, ('D', ): 0}
    assert internal_space[('D', 0, 'dropout')].is_activated_in(partial)
    assert internal_space[('D', 0, 'U_lr')].is_activated_in(partial)
    assert not internal_space[('D', 1, 'dropout')].is_activated_in(partial)
    assert not internal_space[('D', 1, 'N_lr')].is_activated_in(partial)

    partial = {('pool', ): 1, ('kernel', ): 1, ('D', ): 2}
    assert not internal_space[('D', 0, 'dropout')].is_activated_in(partial)
    assert not internal_space[('D', 0, 'U_lr')].is_activated_in(partial)
    assert not internal_space[('D', 1, 'dropout')].is_activated_in(partial)
    assert not internal_space[('D', 1, 'N_lr')].is_activated_in(partial)

    assert internal_space[('not_nested', )].is_activated_in(partial)
Beispiel #5
0
def test_formatting():
    internal_space = format_search_space(user_space)
    assert all(key == value.key for key, value in internal_space.items())
    specs = list(internal_space.values())
    assert spec_names == [spec.name for spec in specs]
    assert spec_types == [spec.type for spec in specs]
    assert spec_values == [spec.values for spec in specs]
    assert spec_keys == [spec.key for spec in specs]
    assert spec_categoricals == [spec.categorical for spec in specs]
    assert spec_sizes == [spec.size for spec in specs]
    assert spec_lows == [spec.low for spec in specs]
    assert spec_highs == [spec.high for spec in specs]
    assert spec_normals == [spec.normal_distributed for spec in specs]
    assert spec_mus == [spec.mu for spec in specs]
    assert spec_sigmas == [spec.sigma for spec in specs]
    assert spec_qs == [spec.q for spec in specs]
    assert spec_clips == [spec.clip for spec in specs]
    assert spec_logs == [spec.log_distributed for spec in specs]
Beispiel #6
0
 def update_search_space(self, space):
     self.space = format_search_space(space)
Beispiel #7
0
 def update_search_space(self, space):
     self.space = format_search_space(space)
     self.dedup = Deduplicator(self.space)
Beispiel #8
0
 def update_search_space(self, space):
     self.space = format_search_space(space)
     if not self.space:  # the tuner will crash in this case, report it explicitly
         raise ValueError('Search space is empty')
     self._init_grid()
Beispiel #9
0
def test_resuming():
    internal_space = format_search_space(user_space)
    assert format_parameters(user_params_1, internal_space) == resume_params_1
    assert format_parameters(user_params_2, internal_space) == resume_params_2
    assert format_parameters(user_params_3, internal_space) == resume_params_3
Beispiel #10
0
def test_dedup_infinite():
    space = format_search_space(infinite_space)
    dedup = Deduplicator(space)
    for i in range(10):
        p = suggest(rng, space)
        assert dedup(p) is p