[Torchscript] Add Date feature preprocessing #2178
Merged
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.
This PR implements Date feature preprocessing in Torchscript.
Date feature preprocessing in Torchscript deviates from vanilla preprocessing in one key way: instead of being able to pass in the raw date-formatted string into the torchscript model, the user must first featurize it into a vector with the values found in
vector
(below).A utility function for converting
datetime
objects into this exact type of vector can be found atludwig.features.date_feature.create_vector_from_datetime_obj
.This deviation occurs because the
datetime
anddateutil
libraries are not currently scriptable (https://pytorch.org/docs/stable/jit.html#python-functions-and-modules).In general, if the user plans on deploying with Torchscript with a Python backend, they can use the utility function
ludwig.models.inference.to_inference_module_input_from_dataframe
to ensure that their input features are being passed into the torchscript model correctly.