Пример #1
0
def benchmark_share_get_plot(b_data_share_get):
    """
        This function plots the graph for various protocols benchmarks for additive
        shared tensors

        Args:
            b_data_share_get (list): the sample data to approximate

        Returns:
            benchmark_share_get.png (png): plotted graph in graph/ast_benchmarks directory
        """
    # initializing workers
    worker = workers(hook())

    # available protocols
    protocols = ["snn", "fss"]

    # initializing graph plot
    fig, ax = plt.subplots()

    for protocol in protocols:

        # list for handling graph data
        x_data = []
        y_data = []

        for data in b_data_share_get:

            # getting value from b_data_share_get
            dtype, n_workers = data

            # temporary list for calculating average execution time and error
            temp_time_taken = []

            for i in range(10):
                start_time = timeit.default_timer()
                benchmark_share_get(worker, protocol, dtype, n_workers)
                time_taken = timeit.default_timer() - start_time
                temp_time_taken.append(time_taken)

            final_time_taken = sum(temp_time_taken) / len(temp_time_taken)
            final_time_taken *= 1000
            x_data.append(dtype + str(" / ") + str(n_workers))
            y_data.append(final_time_taken)

        ax.plot(x_data, y_data, label=protocol, linestyle="-")
        x_data.clear()
        y_data.clear()

    ax.set_xlabel("dtype / n_workers")
    ax.set_ylabel("Execution Time (ms)")
    ax.legend(bbox_to_anchor=(1, 1.22),
              loc="upper right",
              title="Protocols",
              fontsize="small")
    plt.tight_layout()
    plt.savefig("../graphs/ast_benchmarks/benchmark_share_get.png")
Пример #2
0
def benchmark_batch_norm_plot(b_data_batch_norm):
    """
                This function plots the graph for various protocols benchmarks for
                batch_norm.

                Args:
                    b_data_batch_norm (list): list of protocols to approximate

                Returns:
                    benchmark_batch_norm.png (png): plotted graph in graph/ast_benchmarks directory
                """

    # initializing workers
    worker = workers(hook())

    # getting data (protocols)
    protocols = b_data_batch_norm

    # initializing graph plot
    fig, ax = plt.subplots()

    for protocol in protocols:

        # list for handling graph data
        x_data = []
        y_data = []

        for prec_frac in range(1, 5):
            temp_time_taken = []

            for i in range(10):
                start_time = timeit.default_timer()
                benchmark_batch_norm(worker, protocol, True, prec_frac)
                time_taken = timeit.default_timer() - start_time
                temp_time_taken.append(time_taken)

            final_time_taken = sum(temp_time_taken) / len(temp_time_taken)
            final_time_taken *= 1000
            y_data.append(final_time_taken)
            x_data.append(prec_frac)

        ax.plot(x_data, y_data, label=protocol, linestyle="-")
        x_data.clear()
        y_data.clear()

    # plotting of the data
    plt.title("benchmark_batch_norm")
    ax.set_xlabel("Precision Value")
    ax.set_ylabel("Execution Time (ms)")
    ax.legend(bbox_to_anchor=(1, 1.3),
              loc="upper right",
              title="Protocol",
              fontsize="small")
    plt.tight_layout()
    plt.savefig("../graphs/ast_benchmarks/benchmark_batch_norm.png")
Пример #3
0
def sigmoid_approximation_plot(benchmark_data_sigmoid):
    """
    This function plots the graph for various sigmoidal approximation benchmarks namely
    'chebyshev', 'maclaurin', 'exp'.

    Args:
        benchmark_data_sigmoid (list): the sample data to approximate

    Returns:
        sigmoid_function_approximations_benchmark (png): plotted graph in graph directory
    """

    # initializing workers
    worker = workers(hook())

    # initializing graph plot
    fig, ax1 = plt.subplots()
    ax2 = ax1.twinx()

    # list for handling graph data
    x_data = []
    y_data = []
    y2_data = []

    for data in benchmark_data_sigmoid:

        # getting value from benchmark_data_sigmoid
        method, prec_frac = data

        for precision_value in range(1, (prec_frac + 1)):

            # temporary list for calculating average execution time and error
            temp_time_taken = []
            temp_error = []

            for i in range(10):
                start_time = timeit.default_timer()
                error = benchmark_sigmoid(method, precision_value, worker)
                time_taken = timeit.default_timer() - start_time
                temp_time_taken.append(time_taken)
                temp_error.append(error)

            final_time_taken = sum(temp_time_taken) / len(temp_time_taken)
            final_time_taken *= 1000
            final_error = sum(temp_error) / len(temp_error)
            x_data.append(precision_value)
            y_data.append(final_time_taken)
            y2_data.append(final_error)

        ax1.plot(x_data, y_data, label=method, linestyle="-")
        ax2.plot(x_data, y2_data, label=method, linestyle="--")
        x_data.clear()
        y_data.clear()
        y2_data.clear()

    # plotting of the data
    ax1.set_xlabel("Precision Value")
    ax1.set_ylabel("Execution Time (ms)")
    ax2.set_ylabel("Error")
    ax1.legend(bbox_to_anchor=(1, 1.3), loc="upper right", title="Method", fontsize="small")
    ax2.legend(bbox_to_anchor=(0, 1.3), loc="upper left", title="Error", fontsize="small")
    plt.tight_layout()
    plt.savefig("../graphs/sigmoid_function_approximations_benchmark.png")