New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[torchscript] stop serializing default arguments #54613
Comments
related SEV4: S226373 |
Is there any concern that the behavior of the underlying function will silently change? Because if the old runner does not support that argument, then running that code with an older version won't give the same result as running with the new version (which is the one expected by the user when serializing). |
@albanD - if that's the case then whoever added the new argument in the first place has broken the backward compatibility already. In the above example The only case where there would be a different if we implement this issue if we at any point decide to change the default value of an argument. I'd argue it's a pretty rare situation and kind of a sketchy thing to do in any case because it might break some python code inadvertently. cc @raziel fyi |
I think the right fix is to not include default values of arguments when user code doesn't specify it. On top of the reasons @dzhulgakov mentioned, I think not saving default values is more aligned with PyTorch eager and future torch.package behavior, which both faithfully record exact Python code user writes. In this case, the user code is arguably forward-compatible, it is TorchScript's implementation that breaks originally forward-compatible user code. Additionally, TorchScript is currently in a slightly strange state in terms of "providing hermetic packaging for PyTorch program". As we have seen in this case, TorchScript pull information (default value of argument) from |
sooo anyone gonna work on this? |
Update: The approach is to find values that are
During serialization, do not print this argument, instead relying on future compilation to fill up needed arguments according to schemas available. On mobile side, this isn't enabled yet due to 1) needing backport feature because this changes breaks backward compatibility (WIP) 2) long deployment timeline on mobile devices |
Update: |
@gmagogsfm could you please tag which PR fixed this for server and mobile? |
Today, when serializing TorchScript code we make no distinction between arguments that were explicitly specified by the user, and arguments that can from defaults. This leads us to "burn in" default arguments.
This behavior causes forward compatibility problems when a new argument with a default value is added to an operator. Consider:
becoming
The serialized code at version 2 looks like:
so when you try to run it in a binary at version 1, you get a "too many arguments for schema" error.
One option is to not serialize the default value, so then the serialized code at version 2 looks like:
and thus we retain compatibility.
This is a practically important issue, currently adding a new default value to a custom op will break PyPER due to forward compat issues: https://fburl.com/3fr2kjvn
cc @ezyang @gchanan @zou3519 @bdhirsh @jbschlosser @anjali411 @gmagogsfm
The text was updated successfully, but these errors were encountered: