Skip to content

Commit

Permalink
Script MultiheadAttention (#1524)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebookresearch/fairseq#1524

Make fairseq MultiheadAttention scriptable. Looking for feedbacks.

1. Add types
2. Move incremental state management logic from util functions to initializers. TorchScript in general doesn't support global dict. As a result modules with multihead attention in it would assign itself fairseq_instance_id in the initializer.
3. There might be opportunities to make assertions and annotations cleaner.

Differential Revision: D18772594

fbshipit-source-id: 81b830b16fbaa9c6fc34dee0672054f146060ea4
  • Loading branch information
cndn authored and facebook-github-bot committed Jan 10, 2020
1 parent c19fd91 commit 9c65372
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pytorch_translate/average_attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import torch
import torch.nn.functional as F
from fairseq import utils
from torch import nn
from fairseq.modules import BaseFairseqModule


class AttentionAbstract(nn.Module):
class AttentionAbstract(BaseFairseqModule):
"""Abstract class for attention modules
"""

Expand Down

0 comments on commit 9c65372

Please sign in to comment.