Exemplo n.º 1
0
def getGraphs(K, verbose=1):
    """ Returns a dictionary of graphs with relevant topologies """
    graphs = {}
    for topo in ['ring']:
        try:
            graphs[topo] = define_graph_topology(K, topo, verbose=verbose)
        except:
            graphs[topo] = None
    return graphs
Exemplo n.º 2
0
def main(dataset, dataset_path, dataset_size, use_split_dataset, split_by,
         random_state, algoritmname, max_global_steps, local_iters, solvername,
         output_dir, exit_time, lambda_, l1_ratio, theta, graph_topology, c,
         logmode, ckpt_freq, n_connectivity):

    # Fix gamma = 1.0 according to:
    #   Adding vs. Averaging in Distributed Primal-Dual Optimization
    gamma = 1.0

    # Initialize process group
    comm.init_process_group('mpi')

    # Get rank of current process
    rank = comm.get_rank()
    world_size = comm.get_world_size()

    # Create graph with specified topology
    graph = define_graph_topology(world_size,
                                  graph_topology,
                                  n_connectivity=n_connectivity)

    if use_split_dataset:
        X, y = load_dataset_by_rank(dataset,
                                    rank,
                                    world_size,
                                    dataset_size,
                                    split_by,
                                    dataset_path=dataset_path,
                                    random_state=random_state)
    else:
        X, y = load_dataset(dataset,
                            rank,
                            world_size,
                            dataset_size,
                            split_by,
                            dataset_path=dataset_path,
                            random_state=random_state)

    # Define subproblem
    solver = configure_solver(name=solvername,
                              split_by=split_by,
                              l1_ratio=l1_ratio,
                              lambda_=lambda_,
                              C=c,
                              random_state=random_state)

    # Add hooks to log and save metrics.
    monitor = Monitor(solver, output_dir, ckpt_freq, exit_time, split_by,
                      logmode)

    # Always use this value throughout this project
    Akxk, xk = run_algorithm(algoritmname, X, y, solver, gamma, theta,
                             max_global_steps, local_iters, world_size, graph,
                             monitor)

    monitor.save(Akxk, xk, weightname='weight.npy', logname='result.csv')
Exemplo n.º 3
0
def main(dataset, dataset_path, dataset_size, datapoints, use_split_dataset,
         split_by, random_state, algoritmname, max_global_steps, local_iters,
         solvername, output_dir, exit_time, lambda_, l1_ratio, theta,
         graph_topology, c, logmode, ckpt_freq, n_connectivity, fit_intercept,
         normalize, verbose):

    # Fix gamma = 1.0 according to:
    #   Adding vs. Averaging in Distributed Primal-Dual Optimization
    gamma = 1.0

    # Initialize process group
    comm.init_process_group('mpi')

    # Get rank of current process
    rank = comm.get_rank()
    world_size = comm.get_world_size()

    # Create graph with specified topology
    graph = define_graph_topology(world_size,
                                  graph_topology,
                                  n_connectivity=n_connectivity,
                                  verbose=verbose)

    if use_split_dataset:
        if not dataset_path:
            dataset_path = os.path.join('data', dataset, split_by,
                                        f'{world_size}')
        X, y, X_test, y_test = load_dataset_by_rank(dataset,
                                                    rank,
                                                    world_size,
                                                    dataset_size,
                                                    datapoints,
                                                    split_by,
                                                    dataset_path=dataset_path,
                                                    random_state=random_state,
                                                    verbose=verbose)
    else:
        X, y = load_dataset(dataset,
                            rank,
                            world_size,
                            dataset_size,
                            datapoints,
                            split_by,
                            dataset_path=dataset_path,
                            random_state=random_state,
                            verbose=verbose)

    # Define subproblem
    solver = configure_solver(name=solvername,
                              split_by=split_by,
                              l1_ratio=l1_ratio,
                              lambda_=lambda_,
                              C=c,
                              random_state=random_state)

    # Add hooks to log and save metrics.
    if algoritmname != 'cola':
        output_dir = os.path.join(output_dir, algoritmname)
    if dataset:
        output_dir = os.path.join(output_dir, dataset, f'{world_size:0>2}',
                                  graph_topology)
    monitor = Monitor(output_dir,
                      ckpt_freq=ckpt_freq,
                      exit_time=exit_time,
                      split_by=split_by,
                      mode=logmode,
                      verbose=verbose,
                      Ak=X,
                      Ak_test=X_test,
                      y_test=y_test)

    # Run CoLA
    comm.barrier()
    if algoritmname == 'cola':
        model = Cola(gamma, solver, theta, fit_intercept, normalize)
        monitor.init(model, graph)
        model = model.fit(X, y, graph, monitor, max_global_steps, local_iters)
    else:
        raise NotImplementedError()

    # Show test stats
    if X_test is not None:
        monitor.show_test_statistics()

    # Save final model
    monitor.save(modelname='model.pickle', logname=f'result.csv')