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 profiler_range #59634

Merged
merged 6 commits into from
Dec 7, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions python/paddle/profiler/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,20 @@ def _nvprof_range(iter_id, start, end, exit_after_prof=True):
core.nvprof_stop()
if exit_after_prof:
sys.exit()


@contextmanager
def profiler_range(iter_id, start, end, exit_after_prof=True):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def profiler_range(iter_id, start, end, exit_after_prof=True):
def job_schedule_profiler_range(iter_id, start, end, exit_after_prof=True):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

if start >= end:
yield False
return

try:
if (iter_id == start) or (iter_id >= start):
Copy link
Contributor

Choose a reason for hiding this comment

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

这个判断逻辑看起来很奇怪,而且在exit_after_prof==false的时候看起来是错的。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个判断逻辑看起来很奇怪,而且在exit_after_prof==false的时候看起来是错的。

已修复

@contextmanager
def job_schedule_profiler_range(iter_id, start, end, exit_after_prof=True):
    if start >= end:
        yield False
        return

    try:
        if iter_id >= start and iter_id < end:
            yield True
        else:
            yield False
    finally:
        if iter_id == end - 1:
            if exit_after_prof:
                sys.exit()

yield True
else:
yield False
finally:
if iter_id == end - 1:
if exit_after_prof:
sys.exit()