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

skip dummy inference and run_shape_analysis #3212

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

lanluo-nvidia
Copy link
Collaborator

@lanluo-nvidia lanluo-nvidia commented Oct 6, 2024

Description

There is two changes introduced in this PR:

  1. during the compile stage:
    skipped dummy inference and use graph inspection instead to get the output_node.meta['val']

  2. during the save stage:
    skipped run_shape_analysis and use graph inspection instead to get the output_node.meta['val']

Fixes # (issue)

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

@lanluo-nvidia lanluo-nvidia self-assigned this Oct 6, 2024
@lanluo-nvidia lanluo-nvidia added WIP Work is in progress, pull request should not be merged yet and removed cla signed labels Oct 6, 2024
@github-actions github-actions bot added component: conversion Issues re: Conversion stage component: api [Python] Issues re: Python API component: runtime component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Oct 6, 2024
@github-actions github-actions bot requested a review from gs-olive October 6, 2024 05:36
@github-actions github-actions bot added the component: tests Issues re: Tests label Oct 6, 2024
@lanluo-nvidia lanluo-nvidia requested review from peri044 and removed request for gs-olive October 6, 2024 16:27
@lanluo-nvidia lanluo-nvidia changed the title skip run_shape_analysis skip run_shape_analysis and get the output_shapes from compile stage saved in the TorchTensorRTModule Oct 13, 2024
@lanluo-nvidia lanluo-nvidia removed the WIP Work is in progress, pull request should not be merged yet label Oct 13, 2024
@lanluo-nvidia lanluo-nvidia marked this pull request as ready for review October 13, 2024 18:25
@peri044
Copy link
Collaborator

peri044 commented Oct 16, 2024

Here's what I think could be a simpler way of doing this

  1. We probably don't have to store output_shapes in TorchTensorRTModule class. Once the compilation is finished, verify if the nodes of the TRT graph modules have metadata in them (if not we can update it by node.meta["val"] = original metadata)
    Reference:
    for name, trt_module in trt_modules.items():
    setattr(partitioned_module, name, trt_module)
    if settings.lazy_engine_init:
    getattr(partitioned_module, name).setup_engine()

Here the node corresponding to _run_on_acc0 can be queried as

trt_module_node = [node for node in gm.graph.nodes if node.name == "_run_on_acc0"]
trt_module_node.meta["val"] - This should already have fake tensors which need to be used in the exporter. 
  1. exporter
    We have the TRT module node here :
    trt_module_node = [node for node in gm.graph.nodes if node.name == name]

    We could directly set (ensuring trt_module_node.meta["val"] always exists)
trt_node.meta["val"] = trt_module_node.meta["val"]
  1. infer_module_types
    We can replace the dummy inference with graph inspection by reading output metadata. The output of this function could be a list of FakeTensors and we can extract the dtypes from this to pass it to TRTInterpreter.

Replacing the dummy inference will also need changes to our converter test suite.

@lanluo-nvidia lanluo-nvidia changed the title skip run_shape_analysis and get the output_shapes from compile stage saved in the TorchTensorRTModule skip dummy inference and run_shape_analysis Oct 20, 2024
@github-actions github-actions bot added the component: lowering Issues re: The lowering / preprocessing passes label Oct 21, 2024
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: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: lowering Issues re: The lowering / preprocessing passes component: tests Issues re: Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants