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

Script Fairseq transformer #1620

Closed
wants to merge 2 commits into from
Closed

Conversation

cndn
Copy link
Contributor

@cndn cndn commented Jan 14, 2020

Summary:
Make Fairseq transformer scriptable. Discussion points on code quality:

(1) Original decoder output is a tuple (x, {"attn": attn, "inner_states": inner_states}). TorchScript does not support dictionary with values of different types (attn: Tensor, inner_states: List[Tensor]). Current workaround is to use [attn] for attention field and access via output["attn"][0] in downstream. This is currently used in fairspeq custom transformer code. Another (maybe) cleaner alternative is to use namedtuple for decoder output but involves tons of downstream changes too.

(2) Currently TorchScript doesn't support **kwargs. Some unused arguments might get passed in due to polymorphism. Now the only workaround I can think of is to add possible unused arguments, (e.g. line 666 in transformer.py)

Differential Revision: D19234599

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D19234599

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D19234599

1 similar comment
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D19234599

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D19234599

Differential Revision: D19382299

fbshipit-source-id: 56cbdc3462a19ff87d3c9b8b79878ed3b44806f9
Summary:
Pull Request resolved: fairinternal/fairseq-py#1011

Pull Request resolved: facebookresearch#1620

Make Fairseq transformer scriptable. Discussion points on possible code refactoring:

(1) Original decoder output is a tuple (x, {"attn": attn, "inner_states": inner_states}). TorchScript does not support dictionary with values of different types (attn: Tensor, inner_states: List[Tensor]). Current workaround is to use [attn] for attention field and access via output["attn"][0] in downstream. This is currently used in fairspeq custom transformer code. Another (maybe) cleaner alternative is to use namedtuple for decoder output but involves tons of downstream changes too.

(2) Currently TorchScript doesn't support **kwargs. Some unused arguments might get passed in due to polymorphism. Now the only workaround I can think of is to add possible unused arguments, (e.g. line 666 in transformer.py)

Differential Revision: D19234599

fbshipit-source-id: 64b8a64995bd2bf9a24f6b0665609a2856dad840
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D19234599

facebook-github-bot pushed a commit to pytorch/translate that referenced this pull request Jan 30, 2020
Summary:
Pull Request resolved: fairinternal/fairseq-py#1011

Pull Request resolved: facebookresearch/fairseq#1620

Make Fairseq transformer scriptable. Discussion points on possible code refactoring:

(1) Original decoder output is a tuple (x, {"attn": attn, "inner_states": inner_states}). TorchScript does not support dictionary with values of different types (attn: Tensor, inner_states: List[Tensor]). Current workaround is to use [attn] for attention field and access via output["attn"][0] in downstream. This is currently used in fairspeq custom transformer code. Another (maybe) cleaner alternative is to use namedtuple for decoder output but involves tons of downstream changes too.

(2) Currently TorchScript doesn't support **kwargs. Some unused arguments might get passed in due to polymorphism. Now the only workaround I can think of is to add possible unused arguments, (e.g. line 666 in transformer.py)

Reviewed By: myleott

Differential Revision: D19234599

fbshipit-source-id: db3dd364ecf3ae14fb7ac8c0928bd0ebe250f19d
@facebook-github-bot
Copy link
Contributor

This pull request has been merged in a07cb6f.

moussaKam pushed a commit to moussaKam/language-adaptive-pretraining that referenced this pull request Sep 29, 2020
Summary:
Pull Request resolved: fairinternal/fairseq-py#1011

Pull Request resolved: facebookresearch#1620

Make Fairseq transformer scriptable. Discussion points on possible code refactoring:

(1) Original decoder output is a tuple (x, {"attn": attn, "inner_states": inner_states}). TorchScript does not support dictionary with values of different types (attn: Tensor, inner_states: List[Tensor]). Current workaround is to use [attn] for attention field and access via output["attn"][0] in downstream. This is currently used in fairspeq custom transformer code. Another (maybe) cleaner alternative is to use namedtuple for decoder output but involves tons of downstream changes too.

(2) Currently TorchScript doesn't support **kwargs. Some unused arguments might get passed in due to polymorphism. Now the only workaround I can think of is to add possible unused arguments, (e.g. line 666 in transformer.py)

Reviewed By: myleott

Differential Revision: D19234599

fbshipit-source-id: db3dd364ecf3ae14fb7ac8c0928bd0ebe250f19d
yzpang pushed a commit to yzpang/gold-off-policy-text-gen-iclr21 that referenced this pull request Feb 19, 2021
Summary:
Pull Request resolved: fairinternal/fairseq-py#1011

Pull Request resolved: facebookresearch/fairseq#1620

Make Fairseq transformer scriptable. Discussion points on possible code refactoring:

(1) Original decoder output is a tuple (x, {"attn": attn, "inner_states": inner_states}). TorchScript does not support dictionary with values of different types (attn: Tensor, inner_states: List[Tensor]). Current workaround is to use [attn] for attention field and access via output["attn"][0] in downstream. This is currently used in fairspeq custom transformer code. Another (maybe) cleaner alternative is to use namedtuple for decoder output but involves tons of downstream changes too.

(2) Currently TorchScript doesn't support **kwargs. Some unused arguments might get passed in due to polymorphism. Now the only workaround I can think of is to add possible unused arguments, (e.g. line 666 in transformer.py)

Reviewed By: myleott

Differential Revision: D19234599

fbshipit-source-id: db3dd364ecf3ae14fb7ac8c0928bd0ebe250f19d
yzpang pushed a commit to yzpang/gold-off-policy-text-gen-iclr21 that referenced this pull request Feb 19, 2021
Summary:
Pull Request resolved: fairinternal/fairseq-py#1011

Pull Request resolved: facebookresearch/fairseq#1620

Make Fairseq transformer scriptable. Discussion points on possible code refactoring:

(1) Original decoder output is a tuple (x, {"attn": attn, "inner_states": inner_states}). TorchScript does not support dictionary with values of different types (attn: Tensor, inner_states: List[Tensor]). Current workaround is to use [attn] for attention field and access via output["attn"][0] in downstream. This is currently used in fairspeq custom transformer code. Another (maybe) cleaner alternative is to use namedtuple for decoder output but involves tons of downstream changes too.

(2) Currently TorchScript doesn't support **kwargs. Some unused arguments might get passed in due to polymorphism. Now the only workaround I can think of is to add possible unused arguments, (e.g. line 666 in transformer.py)

Reviewed By: myleott

Differential Revision: D19234599

fbshipit-source-id: db3dd364ecf3ae14fb7ac8c0928bd0ebe250f19d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants