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

expand unsupported #486

Closed
jaybdub opened this issue Jan 13, 2021 · 3 comments
Closed

expand unsupported #486

jaybdub opened this issue Jan 13, 2021 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@jaybdub
Copy link
Contributor

jaybdub commented Jan 13, 2021

expand broadcasts tensors along specified dimensions.

https://pytorch.org/docs/stable/tensors.html

@jaybdub jaybdub added the enhancement New feature or request label Jan 13, 2021
@jaybdub jaybdub self-assigned this Jan 13, 2021
@jaybdub
Copy link
Contributor Author

jaybdub commented Jan 13, 2021

Following converter seems to work

@torch2trt.tensorrt_converter('torch.Tensor.expand')
def convert_expand(ctx):
    input = ctx.method_args[0]
    sizes = ctx.method_args[1:]
    output = ctx.method_return
    
    inshape = tuple(input.shape)[1:]
    shape = sizes[1:] # exclude batch
    ndim = len(shape)
    start = tuple([0]*ndim)
    stride = tuple([int(i == o) for i, o in zip(inshape, shape)])  # stride == 1 if dimensions match, 0 otherwise
    
    layer = ctx.network.add_slice(input._trt, start, shape, stride)
    
    output._trt = layer.get_output(0)
    print(output._trt.shape)

@jaybdub
Copy link
Contributor Author

jaybdub commented Jan 15, 2021

converter now added in master as of #487

@jaybdub jaybdub closed this as completed Jan 15, 2021
@DaweiLi-Topcon
Copy link

DaweiLi-Topcon commented Dec 3, 2021

@jaybdub Hi John, I failed to pass this module, Here is the log I met.
File "/XXXX/networks.py", line 525, in forward
levels = levels.expand((xsize + [len(self.levels)]))
File "/XXXX/venv/lib/python3.6/site-packages/torch2trt-0.3.0-py3.6.egg/torch2trt/torch2trt.py", line 300, in wrapper
converter"converter"
File "/XXXX/lib/python3.6/site-packages/torch2trt-0.3.0-py3.6.egg/torch2trt/converters/expand.py", line 17, in convert_expand
layer = ctx.network.add_slice(input._trt, start, shape, stride)
AttributeError: 'Tensor' object has no attribute '_trt'

in the module of convert_expand, how can we change input to input._trt?

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

No branches or pull requests

2 participants