In [1]:
import pandas
import json
import matplotlib as mpl
from matplotlib import pyplot as plt
import numpy as np
import os
import sys
%matplotlib inline
plt.style.use('bmh')
plt.style.use('dark_background')
#sys.path.append("./../sysinfo")
#from cute_device import get_cute_device_str
from helpers import read_df_from_dir, filter_by

In [2]:
#path="/work/alex/data/DL_perf/json/"
path="../../logs/2017.11/"

In [3]:
def autolabel(rects,ax):
    """
    Attach a text label above each bar displaying its height
    """
    max_height=200
    for rect in rects:
        height = rect.get_height()
        if height<15:
            ax.text(rect.get_x() + rect.get_width()/2., 1.05*height, '{:.2f}'.format(height), ha='center', va='bottom', fontsize=14)
        if height>max_height:
            ax.text(rect.get_x() + rect.get_width()/2., 1.05*max_height, '{:.2f}'.format(height), ha='center', va='bottom', fontsize=14, color="red")

In [4]:
def read_file(filename):
    with open(filename) as f:
        data = json.load(f)
    return data
#data=read_file("../logs/scaling/conv2d_2_chainer_GeForce GTX 980 Ti_17.06.10_17.33.42.json")

In [5]:
data = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path,f)) and not f.startswith("arch") ]
#df = pandas.DataFrame(data)
#df
data


Out[5]:
['conv2d_2_chainer_GeForce GTX 980 Ti_17.12.01_10.38.00.json',
 'conv2d_2_chainer_GeForce GTX 1080 Ti_17.12.01_11.15.49.json',
 'conv2d_2_chainer_Tesla K40c_17.12.01_10.52.13.json',
 'conv2d_2_chainer_Tesla K20Xm_17.12.01_10.46.24.json',
 'conv2d_2_chainer_Tesla P100-SXM2-16GB_17.12.01_10.40.16.json']

In [6]:
df = read_df_from_dir(path)

In [7]:
df


Out[7]:
batch_size batch_size_per_device bytes_x_train channels_first device framework framework_full gpus misc nb_gpus path_out platform problem shape_x_train time
0 32 32 671088640 True GTX 980 Ti chainer Chainer-3.1.0 [0] None 1 /work/alex/data/DL_perf/2017.11 {'cpu': {'brand': 'Intel(R) Xeon(R) CPU E5-265... conv2d_2 [10240, 1, 128, 128] 11.639489
1 32 32 671088640 True GTX 1080 Ti chainer Chainer-3.1.0 [0] None 1 ./logs//2017.11 {'cpu': {'brand': 'Intel(R) Core(TM) i7-3820 C... conv2d_2 [10240, 1, 128, 128] 13.154673
2 32 32 671088640 True K40c chainer Chainer-3.1.0 [0] None 1 /work/alex/data/DL_perf/2017.11 {'cpu': {'brand': 'Intel(R) Xeon(R) CPU E5-269... conv2d_2 [10240, 1, 128, 128] 39.623070
3 32 32 671088640 True K20Xm chainer Chainer-3.1.0 [0] None 1 /work/alex/data/DL_perf/2017.11 {'cpu': {'brand': 'Intel(R) Xeon(R) CPU E5-265... conv2d_2 [10240, 1, 128, 128] 42.494191
4 32 32 671088640 True P100-SXM2 chainer Chainer-3.1.0 [0] None 1 /work/alex/data/DL_perf/2017.11 {'cpu': {'brand': 'Intel(R) Xeon(R) CPU E5-263... conv2d_2 [10240, 1, 128, 128] 10.224831

In [ ]:


In [8]:
#df.sort_values(by=["device","framework"],inplace=True)
#df.sort_values(by=["time"],inplace=True)

In [9]:
#filter what to plot
devices=df["device"].unique()
print(devices)
#df


['GTX 980 Ti' 'GTX 1080 Ti' 'K40c' 'K20Xm' 'P100-SXM2']

In [ ]:


In [10]:
#df_filtered = filter_by(df,filters={"device":"P100-PCIE"})

In [11]:
def render(key,filters,color):
    id_dev=0
    df_filtered = filter_by(df,filters)
    df_plot=df_filtered.groupby([key],as_index=False).mean()
    if df_plot.shape[0]<1:
        return "nothing to plot"
    df_plot.reset_index()
    df_plot.sort_values(by=["time"],inplace=True, ascending=False)

    mpl.rcParams['figure.figsize'] = 12, 5
    ax = plt.subplot('111')#, facecolor='white')
    width=0.5
    #ax.set_ylim(0,200)
    err = df_filtered.groupby([key])["time"].std()
    #print (err)
    error_config = {'ecolor': 'r'}
    bars = plt.bar(np.arange(len(df_plot))+width/2,df_plot["time"],width=width,color=color, yerr=err, error_kw=error_config)
    autolabel(bars,ax)
    plt.ylabel("epoch time, s",size=18)
    plt.xticks(np.arange(len(df_plot))+0.25)
    plt.yticks(size=18)
    
    #ax.set_xticks(np.arange(len(labels))+(width*cnt_models)/2, minor=False)
    #ax.set_xticklabels(df["device"], minor=False,size=18,rotation=0)
    ax.set_xticklabels(df_plot[key], minor=False,size=18,rotation=0)
    plt.grid(b=False, which='major', axis='x', )

    plt.tick_params(axis='x', which='both', bottom='off', top='off',  labelbottom='on')
    plt.tick_params(axis='y', which='both', left='off', right='off')
    name_out=""
    title = ""
    for key in filters:
        name_out+=str(filters[key])+"_"
        title+=str(filters[key])+"  "
    name_out = name_out[:-1]
    plt.title(title[:-1])
    print(name_out)
    plt.savefig(os.path.join("./plots",name_out+".svg"),bbox_inches="tight",transparent=True)
    plt.show()
#todo: time per byte

In [12]:
#render(key="framework",filters={"device":"P100-PCIE","problem":"conv2d_1"},color="yellowgreen")
filters={"framework":"chainer","problem":"conv2d_2","nb_gpus":1}

render(key="device",filters=filters,color="yellowgreen")


chainer_conv2d_2_1
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-12-f80e9cca1fe9> in <module>()
      2 filters={"framework":"chainer","problem":"conv2d_2","nb_gpus":1}
      3 
----> 4 render(key="device",filters=filters,color="yellowgreen")

<ipython-input-11-df2a2c6a7ce5> in render(key, filters, color)
     36     plt.title(title[:-1])
     37     print(name_out)
---> 38     plt.savefig(os.path.join("./plots",name_out+".svg"),bbox_inches="tight",transparent=True)
     39     plt.show()
     40 #todo: time per byte

~/.local/lib/python3.6/site-packages/matplotlib/pyplot.py in savefig(*args, **kwargs)
    695 def savefig(*args, **kwargs):
    696     fig = gcf()
--> 697     res = fig.savefig(*args, **kwargs)
    698     fig.canvas.draw_idle()   # need this if 'transparent=True' to reset colors
    699     return res

~/.local/lib/python3.6/site-packages/matplotlib/figure.py in savefig(self, fname, **kwargs)
   1812             self.set_frameon(frameon)
   1813 
-> 1814         self.canvas.print_figure(fname, **kwargs)
   1815 
   1816         if frameon:

~/.local/lib/python3.6/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2257                 orientation=orientation,
   2258                 bbox_inches_restore=_bbox_inches_restore,
-> 2259                 **kwargs)
   2260         finally:
   2261             if bbox_inches and restore_bbox:

~/.local/lib/python3.6/site-packages/matplotlib/backends/backend_svg.py in print_svg(self, filename, *args, **kwargs)
   1190     def print_svg(self, filename, *args, **kwargs):
   1191         if isinstance(filename, six.string_types):
-> 1192             with io.open(filename, 'w', encoding='utf-8') as svgwriter:
   1193                 return self._print_svg(filename, svgwriter, **kwargs)
   1194 

FileNotFoundError: [Errno 2] No such file or directory: './plots/chainer_conv2d_2_1.svg'

In [15]:
#    color=["dodgerblue","yellowgreen"][id_dev]
for problem in df["problem"].unique():
    #render(key="framework",filters={"device":"E5-2699","problem":problem},color="dodgerblue")
    render(key="framework",filters={"nb_gpus":1, "device":"P100-SXM2","problem":problem}, color="yellowgreen")


1_P100-SXM2_conv2d_2
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-15-0fc5404c0d87> in <module>()
      2 for problem in df["problem"].unique():
      3     #render(key="framework",filters={"device":"E5-2699","problem":problem},color="dodgerblue")
----> 4     render(key="framework",filters={"nb_gpus":1, "device":"P100-SXM2","problem":problem},color="yellowgreen")
      5 

<ipython-input-11-df2a2c6a7ce5> in render(key, filters, color)
     36     plt.title(title[:-1])
     37     print(name_out)
---> 38     plt.savefig(os.path.join("./plots",name_out+".svg"),bbox_inches="tight",transparent=True)
     39     plt.show()
     40 #todo: time per byte

~/.local/lib/python3.6/site-packages/matplotlib/pyplot.py in savefig(*args, **kwargs)
    695 def savefig(*args, **kwargs):
    696     fig = gcf()
--> 697     res = fig.savefig(*args, **kwargs)
    698     fig.canvas.draw_idle()   # need this if 'transparent=True' to reset colors
    699     return res

~/.local/lib/python3.6/site-packages/matplotlib/figure.py in savefig(self, fname, **kwargs)
   1812             self.set_frameon(frameon)
   1813 
-> 1814         self.canvas.print_figure(fname, **kwargs)
   1815 
   1816         if frameon:

~/.local/lib/python3.6/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2257                 orientation=orientation,
   2258                 bbox_inches_restore=_bbox_inches_restore,
-> 2259                 **kwargs)
   2260         finally:
   2261             if bbox_inches and restore_bbox:

~/.local/lib/python3.6/site-packages/matplotlib/backends/backend_svg.py in print_svg(self, filename, *args, **kwargs)
   1190     def print_svg(self, filename, *args, **kwargs):
   1191         if isinstance(filename, six.string_types):
-> 1192             with io.open(filename, 'w', encoding='utf-8') as svgwriter:
   1193                 return self._print_svg(filename, svgwriter, **kwargs)
   1194 

FileNotFoundError: [Errno 2] No such file or directory: './plots/1_P100-SXM2_conv2d_2.svg'

In [14]:
for problem in df["problem"].unique():
    render(key="device",filters={"problem":problem,"framework":"chainer"},color="yellowgreen")


conv2d_2_chainer
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-14-6f8cf2555056> in <module>()
      1 for problem in df["problem"].unique():
----> 2     render(key="device",filters={"problem":problem,"framework":"chainer"},color="yellowgreen")

<ipython-input-11-df2a2c6a7ce5> in render(key, filters, color)
     36     plt.title(title[:-1])
     37     print(name_out)
---> 38     plt.savefig(os.path.join("./plots",name_out+".svg"),bbox_inches="tight",transparent=True)
     39     plt.show()
     40 #todo: time per byte

~/.local/lib/python3.6/site-packages/matplotlib/pyplot.py in savefig(*args, **kwargs)
    695 def savefig(*args, **kwargs):
    696     fig = gcf()
--> 697     res = fig.savefig(*args, **kwargs)
    698     fig.canvas.draw_idle()   # need this if 'transparent=True' to reset colors
    699     return res

~/.local/lib/python3.6/site-packages/matplotlib/figure.py in savefig(self, fname, **kwargs)
   1812             self.set_frameon(frameon)
   1813 
-> 1814         self.canvas.print_figure(fname, **kwargs)
   1815 
   1816         if frameon:

~/.local/lib/python3.6/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2257                 orientation=orientation,
   2258                 bbox_inches_restore=_bbox_inches_restore,
-> 2259                 **kwargs)
   2260         finally:
   2261             if bbox_inches and restore_bbox:

~/.local/lib/python3.6/site-packages/matplotlib/backends/backend_svg.py in print_svg(self, filename, *args, **kwargs)
   1190     def print_svg(self, filename, *args, **kwargs):
   1191         if isinstance(filename, six.string_types):
-> 1192             with io.open(filename, 'w', encoding='utf-8') as svgwriter:
   1193                 return self._print_svg(filename, svgwriter, **kwargs)
   1194 

FileNotFoundError: [Errno 2] No such file or directory: './plots/conv2d_2_chainer.svg'

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: