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

support XLM-R model Embedding in TorchScript #1278

Conversation

chenyangyu1988
Copy link
Contributor

Summary:
The main purpose of the diff is to create a TorchScript model for XLM-R model with embedding as output

How to TorchScriptify model with embedding?

XLM-R model
---- PyText: torchscript_export_with_embedder ---> ScriptPyTextEmbeddingModule (texts: Optional[List[str]])
---- Fluent2 wrapper: DocumentEmbedder (texts: texts: Optional[List[Optional[str]]], e.g SingleTextFeature)

Details:

  1. Create a general Script Embedding Module in PyText (e.g ScriptPyTextEmbeddingModule) ==> pytext/torchscript/module.py
  2. Generalize the fluent2 Script Embedding Wrapper in fluent2 (e.g DocumentEmbedder), support both text and token feature
    ==> fblearner/flow/projects/fluent2/definition/transformers/contrib/pytext/torchscript.py
  3. Combine xlm and xlm embedder (PyText one), implement embedding torchscriptify ==> pytext/pytext_embedder_helper.py
  4. PyTextDocumentClassifierWithEmbedding support text_feature

Reviewed By: kartikayk

Differential Revision: D20320641

Summary:
The main purpose of the diff is to create a TorchScript model for XLM-R model with embedding as output

How to TorchScriptify model with embedding?

XLM-R model
 ---- PyText: torchscript_export_with_embedder ---> ScriptPyTextEmbeddingModule (texts: Optional[List[str]])
 ---- Fluent2 wrapper: DocumentEmbedder (texts: texts: Optional[List[Optional[str]]], e.g SingleTextFeature)

Details:
1. Create a general Script Embedding Module in PyText (e.g ScriptPyTextEmbeddingModule) ==> pytext/torchscript/module.py
2. Generalize the fluent2 Script Embedding Wrapper in fluent2 (e.g DocumentEmbedder), support both text and token feature
==> fblearner/flow/projects/fluent2/definition/transformers/contrib/pytext/torchscript.py
3. Combine xlm and xlm embedder (PyText one), implement embedding torchscriptify ==> pytext/pytext_embedder_helper.py
4. PyTextDocumentClassifierWithEmbedding support text_feature

Reviewed By: kartikayk

Differential Revision: D20320641

fbshipit-source-id: 90c33f75b098836534ee0587fa052ba7b922cb7b
@facebook-github-bot facebook-github-bot added CLA Signed Do not delete this pull request or issue due to inactivity. fb-exported labels Mar 12, 2020
@facebook-github-bot
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 495e455.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA Signed Do not delete this pull request or issue due to inactivity. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants