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

Slice mode attribute is not exposed to Python. #3979

Closed
jxchenus opened this issue Jul 3, 2024 · 2 comments
Closed

Slice mode attribute is not exposed to Python. #3979

jxchenus opened this issue Jul 3, 2024 · 2 comments

Comments

@jxchenus
Copy link

jxchenus commented Jul 3, 2024

Description

slice has 4 attributes, but the add_slice function only takes the first 3, leaving out mode. If the 4th input fill_value is specified, the following error is thrown:

[sliceLayer.cpp::validate::190] Error Code 2: Internal Error (Assertion params.mode == SampleMode::kFILL || inputForms.size() <= 4 failed. Fill input should only be provided when SampleMode is kFILL)

Environment

AWS p3.3xlarge

TensorRT Version: 10.0.1

NVIDIA GPU: Tesla V100-SXM2-16GB

NVIDIA Driver Version: 535.161.07

CUDA Version: 12.2

CUDNN Version:

Operating System:

Python Version (if applicable): Python 3.10.12

Tensorflow Version (if applicable):

PyTorch Version (if applicable):

Baremetal or Container (if so, version):

Relevant Files

Model link:

Steps To Reproduce

Commands or scripts:

...
ndim = input.rank()
layer = default_trtnet().add_slice(
input.trt_tensor,
start=[0 for _ in range(ndim)],
shape=[1 for _ in range(ndim)], # unused dummy value
stride=[1 for _ in range(ndim)] # unused dummy value
)

# The stride is either:
#   0 for dimensions of size 1 (i.e. shape(input, i) - 1 == 1 - 1 == 0) or,
#   1 for dimensions of size > 1 since minimum(value >= 1, 1) == 1.
stride_tensor = concat(
    [minimum((shape(input, i) - 1), 1) for i in range(ndim)])

layer.set_input(2, expand_shape.trt_tensor)
layer.set_input(3, stride_tensor.trt_tensor)
if fill_value is not None:
    layer.set_input(4, fill_value.trt_tensor)
return _create_tensor(layer.get_output(0), layer)

...

Have you tried the latest release?: no

Can this model run on other frameworks? For example run ONNX model with ONNXRuntime (polygraphy run <model.onnx> --onnxrt):

@lix19937
Copy link

lix19937 commented Jul 4, 2024

For you ref, Slice Fill mode

in1 = network.add_input("input1", dtype=trt.float32, shape=(2, 2))
layer = network.add_slice(in1, start=(0, 0), shape=(3, 3), stride=(1, 1))
fill_constant = network.add_input("fill_constant", dtype=trt.float32, shape=())
layer.mode = trt.SampleMode.FILL  ## !!!   
layer.set_input(4, fill_constant)
network.mark_output(layer.get_output(0))

inputs[in1.name] = np.zeros(shape=(2, 2))
inputs[fill_constant.name] = np.array([1.0])

outputs[layer.get_output(0).name] = layer.get_output(0).shape
expected[layer.get_output(0).name] = np.array([[0, 0, 1], [0, 0, 1], [1, 1, 1]])

@jxchenus
Copy link
Author

jxchenus commented Jul 4, 2024

That worked! Thank you @lix19937 !

When you get a chance, can you take a look at this one too?

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

No branches or pull requests

2 participants