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

[Torchscript] Enable inference optimizations on the scripted model #4499

Merged
merged 1 commit into from
May 19, 2022

Conversation

pooyanamini
Copy link
Contributor

@pooyanamini pooyanamini commented Apr 11, 2022

Patch description
Enable inference optimization on the torchscripted model. This also
fixes a crash in inference from the torchscripted model when we had
multi-line context.

Testing steps
Tried scripting a model and running inference on it for multi-turn context and made sure we don't see the crash and the output is correct.
buck run //deeplearning/projects/parlai:parlaicmd -- torchscript --model-file manifold://cair_models/tree/cairaoke/experimental/christopherhlin/f335033955/cstudio_reminder_r4 --model fb:bart/cairaoke_bart --scripted-model-file manifold://cair_models/tree/cairaoke/experimental/test/script_reminder_debug.pt --no_cuda --input 'what are my reminders for tomorrow|api_resp: get_entity.date = 2021-07-12T00:00:00.000-07:00'

Other information

@EricMichaelSmith
Copy link
Contributor

@pooyanamini This makes sense to me, but the CI check at https://app.circleci.com/pipelines/github/facebookresearch/ParlAI/11294/workflows/18cf7bc2-284a-43f0-908e-477f2ce3f78e/jobs/92335 is failing now - can you address? I wonder if maybe we should make inference optimization a command-line flag if it wouldn't be backcompatible otherwise?

@pooyanamini
Copy link
Contributor Author

pooyanamini commented Apr 12, 2022

I tried reproducing the error by running this command:

buck run //deeplearning/projects/parlai:parlaicmd \
-- torchscript \
--model bart \
--scripted-model-file manifold://cair_models/tree/cairaoke/experimental/test/script_debug.pt \
--no_cuda \
--input "Don't have a cow, man!"

but the command above worked(the output of scripted and unscripted model matched and it did not crash). I will try to see if I can reproduce it and debug it. If not, I will add a flag as you suggested

@stephenroller
Copy link
Contributor

Can we check which version of PyTorch that inference-fast thing was introduced in?

@stephenroller
Copy link
Contributor

Also I don't know about --no-cuda

@pooyanamini
Copy link
Contributor Author

Can we check which version of PyTorch that inference-fast thing was introduced in?

optimize_for_inference was introduced in Pytorch 1.9.0 . However, there are changes for it as recent as Pytorch 1.11.

Also I don't know about --no-cuda

This flag is enabled in the test also code

@pooyanamini
Copy link
Contributor Author

@stephenroller these failures seem to be unrelated to the PR. can you please check if any other changes are needed to the PR?

@github-actions
Copy link

This PR has not had activity in 30 days. Closing due to staleness.

@github-actions github-actions bot added the stale label May 19, 2022
[Torchscript] Enable inference optimizations on the scripted model

Enable inference optimizations with a flag

remove extra line

Use _ in argument name

Use _ in argument name

Use _ in argument name

address black lint and comment

address comment
@pooyanamini
Copy link
Contributor Author

@stephenroller , @EricMichaelSmith it seems that finally the CI checks are passing. Can you please take a look?

@pooyanamini pooyanamini merged commit 46113ed into main May 19, 2022
@pooyanamini pooyanamini deleted the pamini-branch branch May 19, 2022 17:21
kushalarora pushed a commit that referenced this pull request Jun 15, 2022
[Torchscript] Enable inference optimizations on the scripted model

Enable inference optimizations with a flag

remove extra line

Use _ in argument name

Use _ in argument name

Use _ in argument name

address black lint and comment

address comment
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.

4 participants