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

[converter] aten::{index_select, scalarImplicit} #183

Merged
merged 2 commits into from
Feb 21, 2023
Merged

Conversation

peterjc123
Copy link
Collaborator

@peterjc123 peterjc123 commented Feb 21, 2023

Fixes #181

@peterjc123 peterjc123 changed the title [converter] aten::index_select [converter] aten::{index_select, scalarImplicit} Feb 21, 2023
@peterjc123 peterjc123 merged commit f1fe949 into main Feb 21, 2023
@peterjc123 peterjc123 deleted the pr/index_select branch February 21, 2023 02:46
@LUOBO123LUOBO123
Copy link

Another way to achieve。

class ATenIndexSelectOperator(ATenSliceSchema):
def parse(self, node, attrs, args, graph_converter):
super().parse(node, attrs, args, graph_converter)

    self.run(node)
    input_tensor = self.find_or_create_input(0, graph_converter)
    dim, index = self.input_tensors[1:]

    start_index = int(index[0])

    starts = np.zeros(input_tensor.tensor.ndim, dtype='int32')
    starts[dim] = start_index
    start_tensor = self.create_attr_tensor(starts)

    sizes = np.zeros(input_tensor.tensor.ndim, dtype='int32') - 1
    sizes[dim] = len(index)
    size_tensor = self.create_attr_tensor(sizes)

    inputs = [input_tensor, start_tensor, size_tensor]
    outputs = self.to_tfl_tensors(self.output_names, self.output_tensors)
    graph_converter.add_operator(tfl.SliceOperator(inputs, outputs)

@peterjc123
Copy link
Collaborator Author

Another way to achieve。

class ATenIndexSelectOperator(ATenSliceSchema): def parse(self, node, attrs, args, graph_converter): super().parse(node, attrs, args, graph_converter)

    self.run(node)
    input_tensor = self.find_or_create_input(0, graph_converter)
    dim, index = self.input_tensors[1:]

    start_index = int(index[0])

    starts = np.zeros(input_tensor.tensor.ndim, dtype='int32')
    starts[dim] = start_index
    start_tensor = self.create_attr_tensor(starts)

    sizes = np.zeros(input_tensor.tensor.ndim, dtype='int32') - 1
    sizes[dim] = len(index)
    size_tensor = self.create_attr_tensor(sizes)

    inputs = [input_tensor, start_tensor, size_tensor]
    outputs = self.to_tfl_tensors(self.output_names, self.output_tensors)
    graph_converter.add_operator(tfl.SliceOperator(inputs, outputs)

Thanks for sharing. This inspires me to think of some graph optimization work that can be done. I opened a new issue for that. #184

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

不支持pytorch之中的index_select算子
2 participants