Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

TorchScript BART models #3459

Merged
merged 127 commits into from Mar 19, 2021
Merged

TorchScript BART models #3459

merged 127 commits into from Mar 19, 2021

Conversation

stephenroller
Copy link
Contributor

@stephenroller stephenroller commented Feb 21, 2021

Enable TorchScripting of a BART-based TransformerGeneratorModel. Support for other Transformer variants may come at a later time.

Distilled MultiWoZ-tuned model (BART)

Known good conversation

Call to interact with model:

parlai interactive \
--model-file ${MODEL_FILE} \
--model bart \
--no-cuda

Output:

Enter Your Message: I am looking for a restaurant in the west part of town.
[Bart]: APICALL: Restaurant.area = west
Enter Your Message: APIRESP: Restaurant 14 matches
[Bart]: there are [value_count] restaurant -s in the [value_area] part of town . do you have a preference ?

Exporting model

Call to export model:

parlai torchscript \
--model-file ${MODEL_FILE} \
--model bart \
--no-cuda \
--scripted-model-file ~/_test_scripted_model__bart.pt \
--input 'I am looking for a restaurant in the west part of town.|APIRESP: Restaurant 14 matches'

Output:

Generating given the original unscripted module:
 TEXT: I am looking for a restaurant in the west part of town.
LABEL: APICALL: Restaurant.area = west
 TEXT: APIRESP: Restaurant 14 matches
LABEL: there are [value_count] restaurant -s in the [value_area] part of town . do you have a preference ?

Generating given the scripted module:
 TEXT: I am looking for a restaurant in the west part of town.
LABEL: APICALL: Restaurant.area = west
 TEXT: APIRESP: Restaurant 14 matches
LABEL: there are [value_count] restaurant -s in the [value_area] part of town . do you have a preference ?

Testing loading in and using exported model

Call:

python parlai/torchscript/scripts/test_exported_model.py \
--scripted-model-file ~/_test_scripted_model__bart.pt \
--input 'I am looking for a restaurant in the west part of town.|APIRESP: Restaurant 14 matches'

Output:

Generating given the scripted module:
 TEXT: I am looking for a restaurant in the west part of town.
LABEL: APICALL: Restaurant.area = west
 TEXT: APIRESP: Restaurant 14 matches
LABEL: there are [value_count] restaurant -s in the [value_area] part of town . do you have a preference ?

Additional testing

  • Unit test: pytest tests/test_torchscript.py
  • Agent: parlai interactive --model-file ~/_test_scripted_model__bart.pt --model parlai.torchscript.agents:TorchScriptAgent

@EricMichaelSmith
Copy link
Contributor

Ha, reminds me of the shenanigans I had to go through with ONNX (i.e. removing FusedLayerNorm, etc.)

@stephenroller
Copy link
Contributor Author

Ha, reminds me of the shenanigans I had to go through with ONNX (i.e. removing FusedLayerNorm, etc.)

ya that's what we need to discuss lol

@EricMichaelSmith
Copy link
Contributor

@stephenroller Yes, I've re-split the incremental-state reordering logic back into TransformerDecoderLayer and MultiHeadAttention

@EricMichaelSmith EricMichaelSmith merged commit 6bc04cc into master Mar 19, 2021
@EricMichaelSmith EricMichaelSmith deleted the jittest branch March 19, 2021 17:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants