Skip to content

chore: Fix expand DS support #2962

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 6 commits into from
Jun 27, 2024
Merged

chore: Fix expand DS support #2962

merged 6 commits into from
Jun 27, 2024

Conversation

peri044
Copy link
Collaborator

@peri044 peri044 commented Jun 26, 2024

Description

This PR fixes bugs in expand converter when the input is dynamic

Type of change

Please delete options that are not relevant and/or add your own.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project (You can use the linters)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas and hacks
  • I have made corresponding changes to the documentation
  • I have added tests to verify my fix or my feature
  • New and existing unit tests pass locally with my changes
  • I have added the relevant labels to my PR in so that relevant reviewers are notified

@github-actions github-actions bot added component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Jun 26, 2024
@github-actions github-actions bot requested a review from zewenli98 June 26, 2024 19:45
@github-actions github-actions bot added the component: tests Issues re: Tests label Jun 26, 2024
@peri044 peri044 requested a review from apbose June 26, 2024 20:55
Copy link
Collaborator

@apbose apbose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@peri044 peri044 merged commit 83b9f93 into full Jun 27, 2024
55 of 61 checks passed
@Hukongtao
Copy link

Hello, I want to use torch_tensorrt to accelerate the vit model, but I encountered the following problem. It seems that there are still some problems with the expand operator?

INFO:torch_tensorrt [TensorRT Conversion Context]:Global timing cache in use. Profiling results in this builder pass will be stored.
ERROR:torch_tensorrt [TensorRT Conversion Context]:IBuilder::buildSerializedNetwork: Error Code 4: Internal Error (kOPT values for profile 0 violate shape constraints: [SLICE]-[aten_ops.expand.default]-[/vit_embeddings/expand]: ISliceLayer has out of bounds access on axis 0 Condition '<' violated: 3 >= 1.)
Traceback (most recent call last):
  File "/mnt/bn/hukongtao-infer-speed/mlx/users/kongtao.hu/codebase/EasyGuard_0617/speed_vit_test.py", line 59, in <module>
    trt_gm = torch_tensorrt.compile(
  File "/usr/local/lib/python3.9/dist-packages/torch_tensorrt/_compile.py", line 250, in compile
    trt_graph_module = dynamo_compile(
  File "/usr/local/lib/python3.9/dist-packages/torch_tensorrt/dynamo/_compiler.py", line 243, in compile
    trt_gm = compile_module(gm, inputs, settings)
  File "/usr/local/lib/python3.9/dist-packages/torch_tensorrt/dynamo/_compiler.py", line 431, in compile_module
    trt_module = convert_module(
  File "/usr/local/lib/python3.9/dist-packages/torch_tensorrt/dynamo/conversion/_conversion.py", line 107, in convert_module
    interpreter_result = interpret_module_to_result(module, inputs, settings)
  File "/usr/local/lib/python3.9/dist-packages/torch_tensorrt/dynamo/conversion/_conversion.py", line 88, in interpret_module_to_result
    interpreter_result = interpreter.run()
  File "/usr/local/lib/python3.9/dist-packages/torch_tensorrt/dynamo/conversion/_TRTInterpreter.py", line 350, in run
    assert serialized_engine
AssertionError

my code:

import time

import torch
import torch_tensorrt
from PIL import Image
from transformers import ViTForImageClassification, ViTImageProcessor
from torchvision.models import ResNet50_Weights, resnet50
from transformers.trainer_utils import set_seed
set_seed(0)
model = ViTForImageClassification.from_pretrained('google/vit-base-patch16-224')
# model = resnet50(weights=ResNet50_Weights.IMAGENET1K_V1)
model = model.eval().cuda()
print(type(model))
inputs = [
    torch_tensorrt.Input(
        min_shape=[1, 3, 224, 224],
        opt_shape=[4, 3, 224, 224],
        max_shape=[8, 3, 224, 224],
        dtype=torch.float32
    )
]
trt_gm = torch_tensorrt.compile(
    model, "dynamo", inputs, enabled_precisions={torch.float, torch.half}
)

@Hukongtao
Copy link

#3016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed component: api [Python] Issues re: Python API component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: tests Issues re: Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants