Skip to content

Constant folding crashes if model opt is not installed #3564

Closed
@narendasan

Description

@narendasan

There was an implicit dependency added to constant folding on model opt operations that causes a failure if model opt is not installed.

When running a basic example:

Traceback (most recent call last):
  File "/home/naren/pytorch_org/tensorrt/examples/dynamo/torch_compile_resnet_example.py", line 116, in <module>
    trt_model = torch_tensorrt.compile(model, **compile_spec)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/naren/pytorch_org/tensorrt/py/torch_tensorrt/_compile.py", line 289, in compile
    trt_graph_module = dynamo_compile(
                       ^^^^^^^^^^^^^^^
  File "/home/naren/pytorch_org/tensorrt/py/torch_tensorrt/dynamo/_compiler.py", line 697, in compile
    gm = post_lowering(gm, settings)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/naren/pytorch_org/tensorrt/py/torch_tensorrt/dynamo/lowering/passes/_aten_lowering_pass.py", line 102, in post_lowering
    gm = ATEN_POST_LOWERING_PASSES(gm, settings)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/naren/pytorch_org/tensorrt/py/torch_tensorrt/dynamo/lowering/passes/pass_manager.py", line 56, in __call__
    out = _pass(out, settings)
          ^^^^^^^^^^^^^^^^^^^^
  File "/home/naren/.local/share/uv/python/cpython-3.11.12-linux-x86_64-gnu/lib/python3.11/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/naren/pytorch_org/tensorrt/py/torch_tensorrt/dynamo/lowering/passes/constant_folding.py", line 34, in constant_fold
    cf.run()
  File "/home/naren/pytorch_org/tensorrt/.venv/lib/python3.11/site-packages/torch/_inductor/constant_folding.py", line 295, in run
    return super().run(initial_env=env)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/naren/pytorch_org/tensorrt/.venv/lib/python3.11/site-packages/torch/fx/interpreter.py", line 171, in run
    self.env[node] = self.run_node(node)
                     ^^^^^^^^^^^^^^^^^^^
  File "/home/naren/pytorch_org/tensorrt/.venv/lib/python3.11/site-packages/torch/_inductor/constant_folding.py", line 267, in run_node
    if self.is_impure(node):
       ^^^^^^^^^^^^^^^^^^^^
  File "/home/naren/pytorch_org/tensorrt/py/torch_tensorrt/dynamo/lowering/passes/constant_folding.py", line 104, in is_impure
    if node.target in (torch.ops.tensorrt.quantize_op.default,):
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/naren/pytorch_org/tensorrt/.venv/lib/python3.11/site-packages/torch/_ops.py", line 1317, in __getattr__
    raise AttributeError(
AttributeError: '_OpNamespace' 'tensorrt' object has no attribute 'quantize_op'

if node.target in (torch.ops.tensorrt.quantize_op.default,):

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions