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

Marker op for profiling #33034

Merged
merged 3 commits into from
May 26, 2021

Conversation

FeixLiu
Copy link
Contributor

@FeixLiu FeixLiu commented May 21, 2021

PR types

New features

PR changes

OPs

Describe

marker op for profiling the forward and backward steps.

for now, these ops don't have api and should be inserted manually before train steps with these following codes:

            global_block = train_program.global_block() 
            global_block._insert_op(
                index=1,
                type='marker',
                outputs={'Out': temp_var},
                attrs={
                    'marker_role': 'forward',
                    'marker_pos': 'B',
                    'op_role': OpRole.Forward})
            offset = 0
            should_insert_forward_e_marker = True
            should_insert_backward_b_marker = True
            should_insert_backward_e_marker = True
            for idx, op in enumerate(list(global_block.ops)):
                if int(op.attr('op_role')) != int(OpRole.Forward) and int(op.attr('op_role')) != int(
                        OpRole.LRSched) and should_insert_forward_e_marker:
                    global_block._insert_op(
                        index=idx + offset,
                        type='marker',
                        outputs={'Out': temp_var},
                        attrs={
                            'marker_role': 'forward',
                            'marker_pos': 'E',
                            'op_role': OpRole.Forward})
                    should_insert_forward_e_marker = False
                    offset += 1
                if int(op.attr('op_role')) == int(OpRole.Backward) and should_insert_backward_b_marker:
                    global_block._insert_op(
                        index=idx + offset,
                        type='marker',
                        outputs={'Out': temp_var},
                        attrs={
                            'marker_role': 'backward',
                            'marker_pos': 'B',
                            'op_role': OpRole.Backward})
                    should_insert_backward_b_marker = False
                    offset += 1
                if int(op.attr('op_role')) == int(OpRole.Optimize) and should_insert_backward_e_marker:
                    global_block._insert_op(
                        index=idx + offset,
                        type='marker',
                        outputs={'Out': temp_var},
                        attrs={
                            'marker_role': 'backward',
                            'marker_pos': 'E',
                            'op_role': OpRole.Backward})
                    should_insert_backward_e_marker = False

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

Copy link
Contributor

@gongweibao gongweibao left a comment

Choose a reason for hiding this comment

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

LGTM

@gongweibao gongweibao merged commit 5c79dbb into PaddlePaddle:develop May 26, 2021
@FeixLiu FeixLiu deleted the marker_op_for_profiling branch May 27, 2021 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants