Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support to metrics calculation #195

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

TaekyungHeo
Copy link
Contributor

summary

Add support to metrics calculation.

  1. Iteration E2E time;
  2. bandwidth;

test plan

srun -l -N 8 -n 64 --ntasks-per-node=8 --container-name=sanshang_test \
--container-mounts=/labhome/sanshang:/labhome/sanshang,/swgwork/sanshang:/labhome/sanshang/storage \
bash -c "comm_replay --trace-type et --trace-path ${ROOT_PATH}/et_trace_64gpus \
--output-path ${ROOT_PATH}/output \
--enable-profiler --profiler-num-replays-start 4 --profiler-num-replays 5 \
--do-warm-up --reuse-tensors --num-replays 10"

image
image

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 10, 2025
Copy link
Contributor

@briancoutinho briancoutinho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some suggestions. @shengfukevin also saw black formatting issues, which we would need to fix to pass linter, Sheng is there someway we can share the lint suggestions? Let's do that after next iteration of the PR

@@ -622,6 +622,9 @@ def barrier(self, collectiveArgs, name="dummy", retFlag=False):

if retFlag:
return retObj

def barrier_all_ranks(self):
dist.barrier(device_ids=[self.get_device().index] if dist.get_backend() == "nccl" else None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question, why is this changed from the simplle barrie() before?

Copy link

@sanshang-nv sanshang-nv Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is new added util function, not exist before. To make all dist API call be encapsulated in backend module.

Another point is, if not specify device id, there is warning in log to use GPU0 for barrier. So we should take here as a reference.

}

# refer to: https://github.com/NVIDIA/nccl-tests/blob/master/doc/PERFORMANCE.md
_busbw_correction_factors_tbl: Dict[str, Callable[[int], float]] = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit maybe call these functions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_busbw_correction_factors_fns

return correction_factor_func(group_size)

def calculate_bw_(trace_data):
nccl_events = [i for i in trace_data['traceEvents'] if i.get('cat', '') == 'kernel' and i['name'].startswith('ncclDevKernel_')]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit could be startswith('nccl') for older nccl kernel names that did not start with Device

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean, older nccl kernel in latest nccl verion? Is there some examples? I don't assume we need to be compatible with old nccl version. But if new nccl version has older nccl kernels, we need to consider refine this.

return correction_factor_func(group_size)

def calculate_bw_(trace_data):
nccl_events = [i for i in trace_data['traceEvents'] if i.get('cat', '') == 'kernel' and i['name'].startswith('ncclDevKernel_')]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to save memory consider using generator
nccl_events = (e for e in trace_data['traceEvents'] if e.get('cat', '') == 'kernel' and e['name'].startswith('ncclDevKernel_'))

evt['args']['busbw (GB/sec)'] = busbw
evt['args']['busbw_factor'] = busbw_factor
except ValueError as e:
logger.error('Error processing event: %s', e)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could events processing that failed and print at bottom

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if not len(nccl_events):
return 0

total_data_size = sum([_calculate_event_data_size(evt) * _get_event_busbw_factor(evt) for evt in nccl_events])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit this will work
total_data_size = sum(_calculate_event_data_size(evt) * _get_event_busbw_factor(evt) for evt in nccl_events)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


return total_data_size / (end_time_point - begin_time_point - total_idle_time) / 1e3

def pick_iter_e2e_time_(trace_data, tl):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add some doc on this function, not clear what it is doing, and what is tl

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


total_data_size = sum([_calculate_event_data_size(evt) * _get_event_busbw_factor(evt) for evt in nccl_events])

time_range_tree = IntervalTree([Interval(evt['ts'], evt['ts'] + evt['dur']) for evt in nccl_events])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Today i learned Interval tree class nice :)


# dump summary report
with open(os.path.join(report_dir, 'profiler_trace_summary_report.txt'), 'w', encoding='utf-8') as f:
f.write(f'avg. E2ETime of iters among all ranks: {sum(iter_e2e_time) / len(iter_e2e_time) / 1e3 :.3f} ms\n')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can consider using tabulate library since you are considering adding dependency.

facebook-github-bot pushed a commit that referenced this pull request Jan 23, 2025
Summary:
Add support to metrics calculation.

1. Iteration E2E time
2. bandwidth

This is the copy of #195 for importing it into Meta.


Differential Revision: D68038126

Pulled By: shengfukevin
@shengfukevin
Copy link
Contributor

@briancoutinho @sanshang-nv @TaekyungHeo , I copied this PR and imported to Meta, this is the new diff #196. Please update on PR 196.

I have two issues that need fix:

  1. When profiler is on, this PR will create two profilers, one for meta internal, one for OSS. I fixed that in PR196.
  2. Meta internal need to support uploading report to a Meta internal repository when --output is in the options. I am still working on it.

@sanshang-nv
Copy link

When profiler is on, this PR will create two profilers, one for meta internal, one for OSS. I fixed that in PR196.
@shengfukevin what do you mean 2 profilers? When meta internal works, I will skip to not make public profiler work.

@sanshang-nv
Copy link

PR196 seems not include this commit: 57f619e

@sanshang-nv
Copy link

Hi, @shengfukevin
Has updated to:

  1. solve your 1st issue of 2 profilers when running inside Meta
  2. resolve some comments from Brian.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants