-
Notifications
You must be signed in to change notification settings - Fork 364
Gather Implementation #2457
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
Closed
Closed
Gather Implementation #2457
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
380b698
Gather in impl
apbose af10403
changing gather signature
apbose 99e7de9
Linting fix and adding test case
apbose e194877
linting error fix
apbose b253bd1
Correct sparse arg in aten::gather
apbose 3d2ada6
converting indices to fp32 tensors
apbose 4ad2791
Linting fix
apbose a0ff737
Correcting index test cas
apbose b304233
removing gather test
apbose 9f751c2
select converter implementation correction
apbose a3e6586
removing aten ops gather and changing th e gather tensor
apbose 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
from torch_tensorrt.dynamo.conversion._ConversionContext import ConversionContext | ||
from torch_tensorrt.dynamo.conversion.converter_utils import ( | ||
broadcastable, | ||
cast_trt_tensor, | ||
get_positive_dim, | ||
get_trt_tensor, | ||
to_numpy, | ||
|
@@ -68,11 +69,30 @@ def select( | |
indices_tensor = ctx.net.add_constant( | ||
index_value.shape, to_numpy(index_value) | ||
).get_output(0) | ||
layer = ctx.net.add_gather(input, indices_tensor, dim) | ||
out = layer.get_output(0) | ||
return gather(ctx, target, source_ir, name, input, dim, indices_tensor) | ||
|
||
|
||
def gather( | ||
ctx: ConversionContext, | ||
target: Target, | ||
source_ir: Optional[SourceIR], | ||
name: str, | ||
input: TRTTensor, | ||
dim: int, | ||
index: Union[TRTTensor, np.ndarray, torch.Tensor], | ||
) -> TRTTensor: | ||
if not isinstance(index, TRTTensor): | ||
index = get_trt_tensor(ctx, index, name + f"_index_to_fp32_tensor") | ||
# This is for the case where torch.ops.aten.gather requires torch.int64 | ||
# However TRTInterpreter complains that torch.int64 is not a supported type | ||
# So the below cast does not help | ||
# index = cast_trt_tensor(ctx, input, trt.int32, name, target, source_ir) | ||
gather_layer = ctx.net.add_gather(input, index, dim) | ||
set_layer_name(gather_layer, target, name + "_gather", source_ir) | ||
out = gather_layer.get_output(0) | ||
if len(out.shape) != 1: | ||
layer = ctx.net.add_shuffle(out) | ||
return layer.get_output(0) | ||
gather_layer = ctx.net.add_shuffle(out) | ||
return gather_layer.get_output(0) | ||
|
||
|
||
def index( | ||
|
@@ -127,9 +147,7 @@ def index( | |
) | ||
index = adv_indx_indices[0] | ||
_LOGGER.debug(f"The advanced index indices is {adv_indx_indices}") | ||
gather_layer = ctx.net.add_gather(input, indices_tensor, index) | ||
set_layer_name(gather_layer, target, name + "_index_gather", source_ir) | ||
return gather_layer.get_output(0) | ||
return gather(ctx, target, source_ir, name, input, index, indices_tensor) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line |
||
else: | ||
input_shape = input.shape | ||
_LOGGER.debug(f"The input shape is {input.shape}") | ||
|
@@ -242,11 +260,9 @@ def index( | |
dim_tensor_list[adv_indx_indices[i]], | ||
) | ||
|
||
gather_layer_element = ctx.net.add_gather(flatten_tensor, cum_adv_index, 0) | ||
set_layer_name( | ||
gather_layer_element, target, name + "_index_gather_element", source_ir | ||
gather_out = gather( | ||
ctx, target, source_ir, name, flatten_tensor, 0, cum_adv_index | ||
) | ||
gather_out = gather_layer_element.get_output(0) | ||
_LOGGER.debug(f"The shape after cumultative gather is {gather_out.shape}") | ||
_LOGGER.debug(f"The shape for cumulative adv index is {cum_adv_index}") | ||
|
||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this issue still occur in the test cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it does. aten.scatter has similar use cases, so I am working on that. The casting of nodes in the TRT test infrastructure can be used here to get over. This is the PR- #2664.