-
Notifications
You must be signed in to change notification settings - Fork 363
add dynamic shape support for scaled_dot_product_attention, logical_or/xor #2975
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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9371581
add dynamic shape support for scaledDotProductionAttention
lanluo-nvidia 6e45774
add testcases
lanluo-nvidia f035f74
add testcases
lanluo-nvidia 760fd7f
test
lanluo-nvidia dfc715c
added support when scale is none and query.shape[-1] is dynamic shape
lanluo-nvidia 63a2c5e
test
lanluo-nvidia 45bfd23
add dynamic support for sdpa
lanluo-nvidia a0e39f5
Merge branch 'main' into lluo/ds_4
lanluo-nvidia 8ef9f8c
test
lanluo-nvidia e54d74a
fix typo
lanluo-nvidia e804fe0
test
lanluo-nvidia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
from . import ( | ||
activation, | ||
addmm, | ||
arange, | ||
attention, | ||
cast, | ||
cat, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from typing import Optional, Union | ||
|
||
import numpy as np | ||
import tensorrt as trt | ||
from torch.fx.node import Target | ||
from torch_tensorrt.dynamo.conversion import impl | ||
from torch_tensorrt.dynamo.conversion._ConversionContext import ConversionContext | ||
from torch_tensorrt.dynamo.conversion.converter_utils import ( | ||
SourceIR, | ||
cast_trt_tensor, | ||
get_trt_tensor, | ||
) | ||
from torch_tensorrt.fx.types import TRTTensor | ||
|
||
|
||
def arange( | ||
ctx: ConversionContext, | ||
target: Target, | ||
source_ir: Optional[SourceIR], | ||
name: str, | ||
start: Union[int, TRTTensor], | ||
end: Union[int, TRTTensor], | ||
step: Union[int, TRTTensor], | ||
) -> TRTTensor: | ||
|
||
if any(isinstance(tensor, TRTTensor) for tensor in (start, end, step)): | ||
start_rank_0 = get_trt_tensor(ctx, start, name + "_start_rank_0", min_rank=0) | ||
start_rank_1 = get_trt_tensor(ctx, start, name + "_start_rank_1", min_rank=1) | ||
end = get_trt_tensor(ctx, end, name + "_end", min_rank=1) | ||
step = get_trt_tensor(ctx, step, name + "_step", min_rank=1) | ||
# Calculate shape = (end-start) / step | ||
shape = impl.elementwise.sub( | ||
ctx, | ||
target, | ||
source_ir, | ||
name + "_sub", | ||
end, | ||
start_rank_1, | ||
) | ||
shape = impl.elementwise.trunc_div( | ||
ctx, | ||
target, | ||
source_ir, | ||
name + "_shape", | ||
shape, | ||
step, | ||
) | ||
shape = cast_trt_tensor(ctx, shape, end.dtype, name + "_shape_casted") | ||
fill_layer = ctx.net.add_fill( | ||
shape.shape, trt.FillOperation.LINSPACE, shape.dtype | ||
) | ||
fill_layer.set_input(0, shape) | ||
# Set start index | ||
fill_layer.set_input(1, start_rank_0) | ||
# Set delta/step | ||
fill_layer.set_input(2, step) | ||
return fill_layer.get_output(0) | ||
return np.arange(start, end, step) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.