Skip to content

fix: Repair issue in Torch Constant Folder #2375

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

Merged
merged 1 commit into from
Oct 9, 2023
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
15 changes: 13 additions & 2 deletions py/torch_tensorrt/dynamo/lowering/passes/constant_folding.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Sequence
from typing import Any, Sequence

import torch
from torch_tensorrt._utils import sanitized_torch_version
Expand Down Expand Up @@ -32,7 +32,7 @@ def constant_fold(

Modifies the graph in-place and replaces node with constants
"""
cf = ConstantFolder(gm, skip_constructors=False)
cf = _TorchTensorRTConstantFolder(gm, skip_constructors=False)
cf.run()

for node, constant in cf.node_replacements.items():
Expand All @@ -58,3 +58,14 @@ def constant_fold(
logger.debug(f"Graph after constant folding:\n{gm.graph}")

return gm


# TODO: Delete this class when the following code is fixed in nightly:
# https://github.com/pytorch/pytorch/blob/4b881b0da390c1290bb12850ef9daad6f6eb2cb6/torch/_inductor/constant_folding.py#L53-L63
class _TorchTensorRTConstantFolder(ConstantFolder): # type: ignore[misc]
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)

# TODO: Update this function when quantization is added
def is_impure(self, node: torch.fx.node.Node) -> bool:
return False