return (net, image_shape) def cnn_setup(network, dev, batch_size): net, image_shape = instantiate_network(network, batch_size, dev) device = torch.device( 'cuda' if dev == 'gpu' and torch.cuda.is_available() else 'cpu') target = net.to(device) input_tensor = np.random.randn(*image_shape).astype(np.float32) input = torch.autograd.Variable(torch.from_numpy(input_tensor)) input = input.to(device) return [target, input] def cnn_trial(target, input): return target(input) def cnn_teardown(target, input): pass if __name__ == '__main__': run_template(validate_config=validate, check_early_exit=common_early_exit({'frameworks': 'pt'}), gen_trial_params=common_trial_params( 'pt', 'cnn_comp', cnn_trial, cnn_setup, cnn_teardown, ['network', 'device', 'batch_size'], ['networks', 'devices', 'batch_sizes']))
graph, lib, params = nnvm.compiler.build( net, target='llvm' if dev == 'cpu' else 'cuda', shape={'data': image_shape}, params=params, dtype='float32') mod = tvm.contrib.graph_runtime.create(graph, lib, ctx=device) mod.set_input(**params) mod.set_input( 'data', tvm.nd.array((np.random.uniform(size=image_shape)).astype('float32'))) return [mod] def cnn_trial(mod): return mod.run() def cnn_teardown(mod): pass if __name__ == '__main__': run_template(validate_config=validate, check_early_exit=common_early_exit({'frameworks': 'nnvm'}), gen_trial_params=common_trial_params( 'nnvm', 'cnn_comp', cnn_trial, cnn_setup, cnn_teardown, ['network', 'device', 'batch_size', 'opt_level'], ['networks', 'devices', 'batch_sizes', 'nnvm_opt']))
from validate_config import validate from exp_templates import common_trial_params, run_template from relay_util import cnn_setup, cnn_trial, cnn_teardown if __name__ == '__main__': run_template(validate_config=validate, gen_trial_params=common_trial_params( 'relay', 'opt_comparison', cnn_trial, cnn_setup, cnn_teardown, ['network', 'device', 'batch_size', 'opt_level'], ['networks', 'devices', 'batch_sizes', 'opt_levels']))
net, num_states, shapes = import_gluon_rnn(network) net.initialize(ctx=context) net.hybridize() shape_list = [shapes['data'] ] + [shapes['state%s' % i] for i in range(num_states)] mx_inputs = [ mx.nd.array(np.random.rand(*shape).astype('float32'), ctx=context) for shape in shape_list ] return [lambda: net(*mx_inputs)[0].asnumpy()] def rnn_trial(thunk): thunk() def rnn_teardown(thunk): pass if __name__ == '__main__': run_template(validate_config=validate, check_early_exit=common_early_exit({'frameworks': 'mxnet'}), gen_trial_params=common_trial_params('mxnet', 'gluon_rnns', rnn_trial, rnn_setup, rnn_teardown, ['device', 'network'], ['devices', 'networks']))
from validate_config import validate from exp_templates import (common_trial_params, common_early_exit, run_template) from language_data import N_LETTERS from pt_rnn import RNN, samples def rnn_setup(device, hidden_size, lang, letters): rnn = RNN(N_LETTERS, hidden_size, N_LETTERS) return [lambda: samples(rnn, lang, letters)] def rnn_trial(thunk): return thunk() def rnn_teardown(thunk): pass if __name__ == '__main__': run_template(validate_config=validate, check_early_exit=common_early_exit({'frameworks': 'pt'}), gen_trial_params=common_trial_params( 'pt', 'char_rnn', rnn_trial, rnn_setup, rnn_teardown, ['device', 'hidden_size', 'language', 'input'], ['devices', 'hidden_sizes', 'languages', 'inputs']))
cell_only = (configuration == 'cell') aot = (method == 'aot') net = RNNCellOnly if cell_only else RNNLoop init_net = net(aot, gpu, N_LETTERS, hidden_size, N_LETTERS) if cell_only: return [lambda: samples(init_net, lang, letters)] return [lambda: init_net.samples(lang, letters)] def rnn_trial(thunk): return thunk() def rnn_teardown(thunk): pass if __name__ == '__main__': run_template(validate_config=validate, check_early_exit=common_early_exit({'frameworks': 'relay'}), gen_trial_params=common_trial_params( 'relay', 'char_rnn', rnn_trial, rnn_setup, rnn_teardown, [ 'device', 'configuration', 'method', 'hidden_size', 'language', 'input' ], [ 'devices', 'relay_configs', 'relay_methods', 'hidden_sizes', 'languages', 'inputs' ]))