def top_level_task(): ffconfig = FFConfig() print("Python API batchSize(%d) workersPerNodes(%d) numNodes(%d)" % (ffconfig.batch_size, ffconfig.workers_per_node, ffconfig.num_nodes)) ffmodel = FFModel(ffconfig) dims = [ffconfig.batch_size, 784] input_tensor = ffmodel.create_tensor(dims, DataType.DT_FLOAT) num_samples = 60000 output_tensors = PyTorchModel.file_to_ff("mlp.ff", ffmodel, [input_tensor]) ffoptimizer = SGDOptimizer(ffmodel, 0.01) ffmodel.optimizer = ffoptimizer ffmodel.compile(loss_type=LossType.LOSS_SPARSE_CATEGORICAL_CROSSENTROPY, metrics=[ MetricsType.METRICS_ACCURACY, MetricsType.METRICS_SPARSE_CATEGORICAL_CROSSENTROPY ]) label_tensor = ffmodel.label_tensor (x_train, y_train), (x_test, y_test) = mnist.load_data() print(x_train.shape) x_train = x_train.reshape(60000, 784) x_train = x_train.astype('float32') x_train /= 255 y_train = y_train.astype('int32') y_train = np.reshape(y_train, (len(y_train), 1)) dataloader_input = ffmodel.create_data_loader(input_tensor, x_train) dataloader_label = ffmodel.create_data_loader(label_tensor, y_train) ffmodel.init_layers() epochs = ffconfig.epochs ts_start = ffconfig.get_current_time() ffmodel.fit(x=dataloader_input, y=dataloader_label, epochs=epochs) ts_end = ffconfig.get_current_time() run_time = 1e-6 * (ts_end - ts_start) print("epochs %d, ELAPSED TIME = %.4fs, THROUGHPUT = %.2f samples/s\n" % (epochs, run_time, num_samples * epochs / run_time))
def top_level_task(): ffconfig = FFConfig() alexnetconfig = NetConfig() print(alexnetconfig.dataset_path) print("Python API batchSize(%d) workersPerNodes(%d) numNodes(%d)" % (ffconfig.batch_size, ffconfig.workers_per_node, ffconfig.num_nodes)) ffmodel = FFModel(ffconfig) dims_input = [ffconfig.batch_size, 3, 224, 224] input = ffmodel.create_tensor(dims_input, DataType.DT_FLOAT) output_tensors = PyTorchModel.file_to_ff("resnet18.ff", ffmodel, [input]) t = ffmodel.softmax(output_tensors[0]) ffoptimizer = SGDOptimizer(ffmodel, 0.01) ffmodel.optimizer = ffoptimizer ffmodel.compile(loss_type=LossType.LOSS_SPARSE_CATEGORICAL_CROSSENTROPY, metrics=[ MetricsType.METRICS_ACCURACY, MetricsType.METRICS_SPARSE_CATEGORICAL_CROSSENTROPY ]) label = ffmodel.label_tensor num_samples = 10000 (x_train, y_train), (x_test, y_test) = cifar10.load_data(num_samples) full_input_np = np.zeros((num_samples, 3, 224, 224), dtype=np.float32) for i in range(0, num_samples): image = x_train[i, :, :, :] image = image.transpose(1, 2, 0) pil_image = Image.fromarray(image) pil_image = pil_image.resize((224, 224), Image.NEAREST) image = np.array(pil_image, dtype=np.float32) image = image.transpose(2, 0, 1) full_input_np[i, :, :, :] = image full_input_np /= 255 y_train = y_train.astype('int32') full_label_np = y_train dataloader_input = ffmodel.create_data_loader(input, full_input_np) dataloader_label = ffmodel.create_data_loader(label, full_label_np) num_samples = dataloader_input.num_samples assert dataloader_input.num_samples == dataloader_label.num_samples ffmodel.init_layers() epochs = ffconfig.epochs ts_start = ffconfig.get_current_time() #ffmodel.fit(x=dataloader_input, y=dataloader_label, epochs=epochs) ffmodel.eval(x=dataloader_input, y=dataloader_label) ts_end = ffconfig.get_current_time() run_time = 1e-6 * (ts_end - ts_start) print("epochs %d, ELAPSED TIME = %.4fs, THROUGHPUT = %.2f samples/s\n" % (epochs, run_time, num_samples * epochs / run_time))