def paper_card234(path): path = Path(path) times = cm.load_generic(path/'card234'/'salus'/'preempt'/'perf.output', event_filters=['sess_add_time']) plt.style.use(['seaborn-paper', 'mypaper']) ax = plot_remaining(times, linewidth=1) pu.axhlines(0.0, ax=ax, color='r', linestyle='--', linewidth=.5) #ax.set_ylim(0.9, 1.25) #ax.set_xlabel('Workloads') #ax.set_ylabel('Normalized Per Iteration\nTraining Time') #ax.tick_params(axis='x', labelsize=7) ax.figure.set_size_inches(3.25, 2.35, forward=True) ax.figure.tight_layout() ax.figure.savefig('/tmp/workspace/card234.pdf', dpi=300)
def memory_usage(logs, iter_times=None, beginning=None, starts=None, ends=None, mem_type=None, unified_ylabel=False, smoother=None, xformatter=None, per_sess=False, show_avg=None, ax=None): if beginning is None: beginning = get_beginning(logs) if show_avg is None: show_avg = not per_sess # Prepare ticket -> session map ticket2sess = {} for l in logs: if l.type != 'mem_pre': continue if l.ticket not in ticket2sess: ticket2sess[l.ticket] = l.sess elif l.sess != ticket2sess[l.ticket]: print('WARNING: ticket {} reused: previous {}, now: {}'.format( l.ticket, ticket2sess[l.ticket], l.sess)) mem_usages = [ l for l in logs if l.type == 'mem_alloc' or l.type == 'mem_dealloc' ] mem_activities = [] for m in mem_usages: if m.addr == '0x0' or m.addr == '0': continue if m.type == 'mem_alloc': mem_activities.append({ 'timestamp': m.timestamp, 'size': m.size, 'mem_type': m.block['mem_type'], 'alloc_inst': m.block['alloc_inst'], 'session': ticket2sess[m.block['ticket']] }) elif m.type == 'mem_dealloc': mem_activities.append({ 'timestamp': m.timestamp, 'size': -m.size, 'mem_type': m.block['mem_type'], 'alloc_inst': m.block['alloc_inst'], 'session': ticket2sess[m.block['ticket']] }) else: raise ValueError("Unexpected value: ", m) df = pd.DataFrame(mem_activities) if len(df) == 0: return df, None if mem_type is not None: df = df[df['mem_type'] == mem_type] df = df.set_index('timestamp').sort_index() # Save beginning if beginning is None: beginning = df.index[0] nrows = len(df['mem_type'].unique()) if ax is None: fig, axs = plt.subplots(nrows=nrows, ncols=1, sharex=True, squeeze=False) # Make axes into a 1D array axs = axs.reshape(-1) else: axs = [ax] series = [] pending_avg = [] for (name, group), ax in zip(df.groupby('mem_type'), axs): if per_sess: sessionUsages = {} for k, gg in group.groupby('session'): sessionUsages[k] = gg['size'].cumsum() ss = pd.DataFrame(sessionUsages).fillna(method='ffill').fillna(0) else: ss = group['size'].cumsum() # Do range restriction rstarts = None rends = None # Restrict x axis to iteration timaxes, must be done after cumsum, otherwise there # will be negative number if iter_times is not None: rstarts = iter_times[0][0] rends = iter_times[-1][1] rstarts = starts if starts is not None else rstarts rends = ends if ends is not None else rends if rstarts is not None and rends is not None: ss = ss.loc[rstarts:rends] elif rstarts is not None: ss = ss.loc[rstarts:] elif rends is not None: ss = ss.loc[:rends] ss.index = ss.index - beginning if show_avg: ss2 = ss.resample('100us').interpolate(method='time') pending_avg.append((ss2.mean(), ax)) series.append(ss) if smoother: if show_avg: ss = smoother(ss, ss2) else: ss = smoother(ss) # Change to timedelta after iteration restriction. # for some reason slicing doesn't work on Timedeltas # Pandas doesn't support irregular Timedelta intervals on xaxis # see https://stackoverflow.com/questions/40621710/axis-interval-spacing-when-plotting-with-pandas-timedelta # and https://github.com/pandas-dev/pandas/issues/8711 ss.index = ss.index.astype(int) if per_sess: ss.plot.area(ax=ax, linewidth=0) else: ss.plot(ax=ax) ax.legend().remove() pu.cleanup_axis_bytes(ax.yaxis) if not unified_ylabel: ax.set_ylabel('Memory Usage') # Adjust x axis if unified_ylabel: axs[-1].xaxis.label.set_visible(False) else: axs[-1].set_xlabel('Time (s)') axs[-1].autoscale(axis='x') # xlim = axs[-1].get_xlim() axs[-1].set_xlim(left=0) pu.cleanup_axis_timedelta(axs[-1].xaxis, xformatter) # Draw avg line after adjust xaxis if show_avg: for d, ax in pending_avg: pu.axhlines(d, linestyle='--', ax=ax) def format_coord(x, y): return 'x={:.4f}, y={:.1f} MB'.format(x, y / 1024 / 1024) axs[-1].format_coord = format_coord fig = axs[-1].figure #fig.tight_layout() if unified_ylabel: fig.text(0.5, 0.02, 'Time (s)', ha='center') fig.text(0.02, 0.5, 'Memory Usage (bytes)', va='center', rotation='vertical') fig.subplots_adjust(left=0.1, bottom=0.13) return df, beginning, fig
pits = pits[~pits.index.str.contains('eval')] # only one batch size # only draw one batch size: the largest one pits = pits.reset_index() pits['Model'], pits['BatchSize'] = pits.Network.str.split('_').str pits.BatchSize.replace({'small': 1, 'medium': 5, 'large': 10}, inplace=True) pits['BatchSize'] = pd.to_numeric(pits.BatchSize) pits = pits.reset_index().loc[pits.reset_index().groupby( ['Model'])['BatchSize'].idxmax()] pits = pits.drop(['index', 'BatchSize', 'Network'], axis=1) pits = pits.rename(columns={'Model': 'Network'}).set_index('Network') with plt.style.context(['seaborn-paper', 'mypaper', 'color3']): ax = pits.plot.bar(legend=None) pu.axhlines(1.0, ax=ax, color='k', linestyle='--', linewidth=1) pu.bar_show_data(ax, pits.index.get_loc('superres'), pits.at['superres', 'Salus']) pu.bar_show_data(ax, pits.index.get_loc('vae'), pits.at['vae', 'Salus']) ax.set_ylim(0.9, 1.9) ax.set_xlabel('Workloads') ax.set_ylabel('Normalized Per Iteration\nTraining Time') # ax.legend() ax.tick_params(axis='x', labelsize=7) ax.figure.set_size_inches(3.25, 2.35, forward=True) ax.figure.tight_layout() ax.figure.savefig('/tmp/workspace/exp17.pdf', dpi=300,