<jupyter_start><jupyter_text>Summary of ImageNet/ResNet50 Training using Multiple Node<jupyter_code>%matplotlib inline
import glob
import json
import os
from pathlib import Path
import re

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns

SAVE_FIGURE = False
FIGURE_FONT_SIZE = 12

plt.rcParams["figure.dpi"] = 120
plt.rcParams['font.family'] = 'monospace'
plt.rcParams['font.size'] = FIGURE_FONT_SIZE
pd.set_option('precision', 3)
pd.set_option('display.max_columns', 30)

project_dir = os.getcwd()
dir_anode_multi = f'{project_dir}/anode_multi'
dir_vnode_multi = f'{project_dir}/vnode_multi'
# function definitions

def read_data_from_files(dirpath, name, index_gpus=False):
    nnodes = [1, 2, 4, 8, 16, 32]
    index = []
    data = []
    for nnode in nnodes:
        file_pattern = f'{dirpath}/job{nnode:02d}.sh.o*'
        files = glob.glob(file_pattern)
        if not files:
            continue
        index.append(nnode)
        with open(files[0]) as inf:
            lines = inf.readlines()
            last_line = lines[-1].strip()
            record_str = last_line.split(' ')[-1]
            data.append(float(record_str))
    if index_gpus:
        if name == 'anode':
            ngpus = 8
        elif name == 'vnode':
            ngpus = 4
        index = [n * ngpus for n in index]
    return pd.Series(data=data, index=index, name=name)

def load_data(index_gpus=False):
    node_types = {
        'anode': dir_anode_multi,
        'vnode': dir_vnode_multi
    }

    series = []
    for node, dirpath in node_types.items():
        column_key = node
        data = read_data_from_files(dirpath, column_key, index_gpus)
        series.append(data)
    return pd.concat(series, axis=1)

def plot(data, column_labels, title, legend_fontsize=None, xaxis_gpus=False):
    data0 = data[column_labels.keys()]
    data0 = data0.rename(columns=column_labels)
    data0 = data0 / 3600
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)

    if xaxis_gpus:
        ax.set_xlabel('# of GPUs')
    else:
        ax.set_xlabel('# of Nodes')
    ax.set_ylabel('Time (hours)')

    data0.dropna(how='all').plot.bar(ax=ax, rot=0)
    for p in ax.patches:
        if p.get_height() == 0:
            continue
        ax.annotate(f'{p.get_height():.2f}', (p.get_x() * 1.005, p.get_height() * 1.005), size=10)

    ax.legend(fontsize=legend_fontsize)
    if SAVE_FIGURE:
        fig.savefig(f'{title}.pdf')
    ax.set_title(title)<jupyter_output><empty_output><jupyter_text>Performance by Changing Number of Nodes<jupyter_code>data = load_data()
print('Training Time')
data
print('Relative Performance against #Node=1')
data.loc[1] / data
print('Speedup of Node(A) against Node(V)')
data.loc[:, ['vnode']].apply(lambda x: x/data['anode']).rename(columns={'vnode': 'speedup'})
title = 'Node(A) vs. Node(V) in #Nodes'
column_labels = {
    'anode': 'Node(A)',
    'vnode': 'Node(V)',
}
plot(data, column_labels, title)<jupyter_output><empty_output><jupyter_text>Performance by Changing Number of GPUs<jupyter_code>data_gpus = load_data(index_gpus=True)
print('Training Time')
data_gpus
print('Relative Performance against #GPUs=8')
data_gpus.loc[8] / data_gpus
print('Speedup of Node(A) against Node(V)')
data_gpus.loc[:, ['vnode']].apply(lambda x: x/data_gpus['anode']).rename(columns={'vnode': 'speedup'})
title = 'Node(A) vs. Node(V) in #GPUs'
column_labels = {
    'anode': 'Node(A)',
    'vnode': 'Node(V)',
}
plot(data_gpus, column_labels, title, xaxis_gpus=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1441109852774632, 'fraction_numerical': 0.015855039637599093, 'mean_word_length': 3.7043941411451398, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '329410', 'license': 'MIT', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1301, 'n_words': 268, 'path': 'imagenet/summary_multi.ipynb', 'repo_name': 'aistairc/abci2.0benchmark', 'size': '3532'}