Skip to content

[Performance] contirb.seq2seq.attention_wrapper slower due to using matmul instead of reduce_sum #10765

Closed

Description

@chenghuige

tf version '1.2.0-rc0' contirb.seq2seq.attention_wrapper is great, it make using attention much easier.
However I found using attention_wrapper will be much slower then tf version 1.0.
After some experiment I found it is due to using matmul instead of reduce_sum.

from attetntion_wrapper.py 731

  expanded_alignments = array_ops.expand_dims(alignments, 1)
  attention_mechanism_values = self._attention_mechanism.values
  context = math_ops.matmul(expanded_alignments, attention_mechanism_values)
  context = array_ops.squeeze(context, [1])

Using above code for one of my application got 2.2 batch/s, after changing to use reduce_sum(as tf version 1.0 did), the speed is 3.4 batch/s, improve a lot.

  expanded_alignments = array_ops.expand_dims(alignments, 2)
  attention_mechanism_values = self._attention_mechanism.values
  context = math_ops.reduce_sum(expanded_alignments * attention_mechanism_values, [1])

Activity

  1. changed the title [-]contirb.seq2seq.attention_wrapper slower due to using matmul instead of reduce_sum[/-] [+]【Performance】contirb.seq2seq.attention_wrapper slower due to using matmul instead of reduce_sum[/+] on Jun 16, 2017
  2. changed the title [-]【Performance】contirb.seq2seq.attention_wrapper slower due to using matmul instead of reduce_sum[/-] [+][Performance] contirb.seq2seq.attention_wrapper slower due to using matmul instead of reduce_sum[/+] on Jun 16, 2017
  3. tensorflowbutler commented on Aug 24, 2018

    @tensorflowbutler
    Member

    Nagging Assignee @tfboyd: It has been 433 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.

  4. chenghuige commented on Sep 5, 2018

    @chenghuige
    Author

    Closing this as prefer to use eager mode seq2seq.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions