How to use nni - 10 common examples

To help you get started, we’ve selected a few nni examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / nni / test / config_test / multi_phase / multi_phase.py View on Github external
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

import time
import nni

if __name__ == '__main__':
    for i in range(5):
        hyper_params = nni.get_next_parameter()
        print('hyper_params:[{}]'.format(hyper_params))
        if hyper_params is None:
            break
        nni.report_final_result(0.1*i)
        time.sleep(3)
github microsoft / nni / test / config_test / multi_thread / multi_thread_trial.py View on Github external
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

import nni
import time

if __name__ == '__main__':
    nni.get_next_parameter()
    time.sleep(3)
    nni.report_final_result(0.5)
github microsoft / nni / test / naive_test / naive_trial.py View on Github external
# Licensed under the MIT license.

import time

import nni

params = nni.get_next_parameter()
print('params:', params)
x = params['x']

time.sleep(1)
for i in range(1, 10):
    nni.report_intermediate_result(x ** i)
    time.sleep(0.5)

nni.report_final_result(x ** 10)
github microsoft / nni / test / tuner_test / naive_trial.py View on Github external
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

import nni

params = nni.get_next_parameter()
print('params:', params)
x = params['x']

nni.report_final_result(x)
github microsoft / nni / tools / nni_annotation / testcase / annotated / mnist.py View on Github external
with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        batch_num = 200
        for i in range(batch_num):
            batch_size = nni.choice({50: 50, 250: 250, 500: 500}, name=
                'batch_size')
            batch = mnist.train.next_batch(batch_size)
            dropout_rate = nni.choice({1: 1, 5: 5}, name='dropout_rate')
            mnist_network.train_step.run(feed_dict={mnist_network.x: batch[
                0], mnist_network.y: batch[1], mnist_network.keep_prob:
                dropout_rate})
            if i % 100 == 0:
                test_acc = mnist_network.accuracy.eval(feed_dict={
                    mnist_network.x: mnist.test.images, mnist_network.y:
                    mnist.test.labels, mnist_network.keep_prob: 1.0})
                nni.report_intermediate_result(test_acc)
        test_acc = mnist_network.accuracy.eval(feed_dict={mnist_network.x:
            mnist.test.images, mnist_network.y: mnist.test.labels,
            mnist_network.keep_prob: 1.0})
        nni.report_final_result(test_acc)
github microsoft / nni / tools / nni_annotation / testcase / annotated / handwrite.py View on Github external
import nni
def max_pool(k):
    pass

h_conv1 = 1
nni.choice({'foo': foo, 'bar': bar})(1)
conv_size = nni.choice({2: 2, 3: 3, 5: 5, 7: 7}, name='conv_size')
abc = nni.choice({'2': '2', 3: 3, '(5 * 6)': 5 * 6, 7: 7}, name='abc')
h_pool1 = nni.function_choice({'max_pool': lambda : max_pool(h_conv1),
    'h_conv1': lambda : h_conv1,
    'avg_pool': lambda : avg_pool(h_conv2, h_conv3)}
)
h_pool1 = nni.function_choice({'max_pool(h_conv1)': lambda : max_pool(
    h_conv1), 'avg_pool(h_conv2, h_conv3)': lambda : avg_pool(h_conv2,
    h_conv3)}, name='max_pool')
h_pool2 = nni.function_choice({'max_poo(h_conv1)': lambda : max_poo(h_conv1
    ), '(2 * 3 + 4)': lambda : 2 * 3 + 4, '(lambda x: 1 + x)': lambda : lambda
    x: 1 + x}, name='max_poo')
tmp = nni.qlognormal(1.2, 3, 4.5)
test_acc = 1
nni.report_intermediate_result(test_acc)
test_acc = 2
github microsoft / nni / tools / nni_annotation / testcase / annotated / dir / simple.py View on Github external
import nni


def max_pool(k):
    pass


h_conv1 = 1
conv_size = nni.choice({2: 2, 3: 3, 5: 5, 7: 7}, name='conv_size')
abc = nni.choice({'2': '2', 3: 3, '(5 * 6)': 5 * 6, "{(1): 2, '3': 4}": {(1
    ): 2, '3': 4}, '[1, 2, 3]': [1, 2, 3]}, name='abc')
h_pool1 = nni.function_choice({'max_pool(h_conv1)': lambda : max_pool(
    h_conv1), 'avg_pool(h_conv2, h_conv3)': lambda : avg_pool(h_conv2,
    h_conv3)}, name='max_pool')
h_pool2 = nni.function_choice({'max_poo(h_conv1)': lambda : max_poo(h_conv1
    ), '(2 * 3 + 4)': lambda : 2 * 3 + 4, '(lambda x: 1 + x)': lambda : lambda
    x: 1 + x}, name='max_poo')
test_acc = 1
nni.report_intermediate_result(test_acc)
test_acc = 2
nni.report_final_result(test_acc)
github microsoft / nni / tools / nni_annotation / testcase / annotated / mnist.py View on Github external
mnist_network = MnistNetwork()
    mnist_network.build_network()
    logger.debug('Mnist build network done.')
    graph_location = tempfile.mkdtemp()
    logger.debug('Saving graph to: %s' % graph_location)
    train_writer = tf.summary.FileWriter(graph_location)
    train_writer.add_graph(tf.get_default_graph())
    test_acc = 0.0
    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        batch_num = 200
        for i in range(batch_num):
            batch_size = nni.choice({50: 50, 250: 250, 500: 500}, name=
                'batch_size')
            batch = mnist.train.next_batch(batch_size)
            dropout_rate = nni.choice({1: 1, 5: 5}, name='dropout_rate')
            mnist_network.train_step.run(feed_dict={mnist_network.x: batch[
                0], mnist_network.y: batch[1], mnist_network.keep_prob:
                dropout_rate})
            if i % 100 == 0:
                test_acc = mnist_network.accuracy.eval(feed_dict={
                    mnist_network.x: mnist.test.images, mnist_network.y:
                    mnist.test.labels, mnist_network.keep_prob: 1.0})
                nni.report_intermediate_result(test_acc)
        test_acc = mnist_network.accuracy.eval(feed_dict={mnist_network.x:
            mnist.test.images, mnist_network.y: mnist.test.labels,
            mnist_network.keep_prob: 1.0})
        nni.report_final_result(test_acc)
github microsoft / nni / tools / nni_annotation / testcase / annotated / dir / simple.py View on Github external
import nni


def max_pool(k):
    pass


h_conv1 = 1
conv_size = nni.choice({2: 2, 3: 3, 5: 5, 7: 7}, name='conv_size')
abc = nni.choice({'2': '2', 3: 3, '(5 * 6)': 5 * 6, "{(1): 2, '3': 4}": {(1
    ): 2, '3': 4}, '[1, 2, 3]': [1, 2, 3]}, name='abc')
h_pool1 = nni.function_choice({'max_pool(h_conv1)': lambda : max_pool(
    h_conv1), 'avg_pool(h_conv2, h_conv3)': lambda : avg_pool(h_conv2,
    h_conv3)}, name='max_pool')
h_pool2 = nni.function_choice({'max_poo(h_conv1)': lambda : max_poo(h_conv1
    ), '(2 * 3 + 4)': lambda : 2 * 3 + 4, '(lambda x: 1 + x)': lambda : lambda
    x: 1 + x}, name='max_poo')
test_acc = 1
nni.report_intermediate_result(test_acc)
test_acc = 2
nni.report_final_result(test_acc)
github microsoft / nni / src / sdk / pynni / nni / networkmorphism_tuner / test_networkmorphism_tuner.py View on Github external
def test_graph_json_transform(self):
        """ unittest for graph_json_transform function
        """

        graph_init = CnnGenerator(10, (32, 32, 3)).generate()
        graph_init = to_wider_graph(deepcopy(graph_init))
        graph_init = to_deeper_graph(deepcopy(graph_init))
        graph_init = to_skip_connection_graph(deepcopy(graph_init))
        json_out = graph_to_json(graph_init, "temp.json")

        graph_recover = json_to_graph(json_out)

        # compare all data in graph
        self.assertEqual(graph_init.input_shape, graph_recover.input_shape)
        self.assertEqual(graph_init.weighted, graph_recover.weighted)
        self.assertEqual(
            graph_init.layer_id_to_input_node_ids,
            graph_recover.layer_id_to_input_node_ids,
        )
        self.assertEqual(graph_init.adj_list, graph_recover.adj_list)
        self.assertEqual(
            graph_init.reverse_adj_list,
            graph_recover.reverse_adj_list)
        self.assertEqual(
            len(graph_init.operation_history), len(
                graph_recover.operation_history)
        )