Skip to content
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

[PT FE] Allow setting kwargs for tracing in TS decoder #28328

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(
skip_freeze=False,
constant_cache=None,
module_extensions=None,
trace_kwargs=None,
):
super().__init__()
# We store every decoder created by this decoder so that all them are not deleted until the first decoder is deleted
Expand All @@ -57,7 +58,7 @@ def __init__(
self.config = pt_module.config.to_dict()
try:
pt_module = self._get_scripted_model(
pt_module, example_input, skip_freeze)
pt_module, example_input, skip_freeze, trace_kwargs)
except Exception as e:
if example_input is not None:
msg = "tracing"
Expand Down Expand Up @@ -109,7 +110,7 @@ def _get_preserved_attributes(model) -> list:
preserved_attributes.append(name)
return preserved_attributes

def _get_scripted_model(self, pt_module, example_inputs=None, skip_freeze=False):
def _get_scripted_model(self, pt_module, example_inputs=None, skip_freeze=False, trace_kwargs=None):
freeze_by_default = False
if isinstance(pt_module, torch.nn.Module):
pt_module.eval()
Expand Down Expand Up @@ -154,9 +155,11 @@ def _get_scripted_model(self, pt_module, example_inputs=None, skip_freeze=False)
quantized.unpatch_quantized(pt_module)
patched = False

if trace_kwargs is None:
trace_kwargs = {}
try:
scripted = torch.jit.trace(
pt_module, **input_parameters, strict=False)
pt_module, **input_parameters, strict=False, **trace_kwargs)
finally:
if patched:
quantized.unpatch_quantized(pt_module)
Expand Down
Loading