[Cherry-pick 2.0.1] Fix virtual function issue with CTC decoder (#3230) #3238
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
Currently, creating CTCDecoder object by passing a language model to
lm
argument without assigning it to a variable elsewhere causesRuntimeError: Tried to call pure virtual function "LM::start"
.According to discussions on PyBind11, (
pybind/pybind11#4013 and pybind/pybind11#2839
) this is due to Python object garbage-collected by the time it's used by code implemented in C++. It attempts to call methods defined in Python, which overrides the base pure virtual function, but the object which provides this override gets deleted by garbage collrector, as the original object is not reference counted.
This commit fixes this by simply assiging the given
lm
object as an attribute of CTCDecoder class.Address #3218
Pull Request resolved: #3230
Reviewed By: hwangjeff
Differential Revision: D44642989
Pulled By: mthrok
fbshipit-source-id: a90af828c7c576bc0eb505164327365ebaadc471