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

The attributes of Slice #3686

Closed
ZJG0 opened this issue Aug 27, 2021 · 10 comments
Closed

The attributes of Slice #3686

ZJG0 opened this issue Aug 27, 2021 · 10 comments
Labels
question Questions about ONNX

Comments

@ZJG0
Copy link

ZJG0 commented Aug 27, 2021

Ask a Question

Question

When opset version<=9 the node of Slice have attribute which stores starts, end and axis. However, opset version >9
there isn't attribute, how can I get the value of starts, ends and axis?

Further information

  • I intend to convert onnx format of ViT model to Crypten. There is
    a error about Slice whose cause is that Crypten requires 'starts', ends and axis of Slice, but opset version>9 onnx doesn't have attribute, I can't find the starts etc.

  • Is this issue related to a specific model?
    Model name (e.g. mnist): ViT model and Crypten
    Model opset (e.g. 7): opset version>=10

Notes

Any additional information, code snippets.

@ZJG0 ZJG0 added the question Questions about ONNX label Aug 27, 2021
@jcwchen
Copy link
Member

jcwchen commented Aug 27, 2021

Hi @ZJG0,
In Slice-10 (opest version=10), the attributes for Slice like starts, ends axes, steps have been moved to input: https://github.com/onnx/onnx/blob/master/docs/Changelog.md#slice-10 Therefore, you should find those in input instead of attribute for higher opset version of Slice (opset version>=10).

@ZJG0
Copy link
Author

ZJG0 commented Aug 28, 2021

Thanks for your reply. I printed the information of node Slice.

input: "3020"
input: "3029"
input: "3030"
input: "3028"
output: "3031"
name: "Slice_1422"
op_type: "Slice"

Above input doesn't look like the value of starts etc. Do I need to find it based on the 3020?
Can you give me a demo on how to get the starts, ends and axis?

@jcwchen
Copy link
Member

jcwchen commented Aug 28, 2021

The input position is fixed -- Since your Slice node has 4 inputs, they respectively are data(3020), starts(3029), ends(3030), axes(3028), with the same order as the document.

@ZJG0
Copy link
Author

ZJG0 commented Aug 28, 2021

I may not describe my problem clearly. I don't understand the format of input. For example, Does axis(3028) mean the value of axis is 3028?Shouldn't axis be 0 or 1?

@jcwchen
Copy link
Member

jcwchen commented Aug 28, 2021

I thought you printed the Slice node info by onnx_model.graph.node[i]? If so, "3028" should be an input name instead.

@ZJG0
Copy link
Author

ZJG0 commented Aug 28, 2021

Yes. However, how can i get the value of axis based on name "3028"? I try to print input info by onnx_model.graph.input[i]
but i only get

name: "tensor.1"
type {
  tensor_type {
    elem_type: 1
    shape {
      dim {
        dim_value: 64
      }
      dim {
        dim_value: 3
      }
      dim {
        dim_value: 256
      }
      dim {
        dim_value: 256
      }
    }
  }
}

@ZJG0
Copy link
Author

ZJG0 commented Aug 30, 2021

All I need is that the real values of starts, ends, and axis when opset version >=10 as same as the contents of attribute(opset version<10).
However, now I only get the names of starts, ends and axis(210, 216, 208).

input: "206"
input: "210"
input: "216"
input: "208"
output: "217"
name: "Slice_142"
op_type: "Slice"

@jcwchen
Copy link
Member

jcwchen commented Aug 30, 2021

If you didn't find those input names of Slice node in your graph.initializer/graph.input, they are probably produced while forwarding the graph... That is to say, they are not static and their values can only obtained during runtime (giving inputs and going through the graph).

@gramalingam
Copy link
Contributor

Just to clarify: "210" here is the name of a tensor. You can check whether there is an initializer with that name, which will provide the value. If not, there must be some node with an output named "210". If it is a "Constant" node, then the value can be obtained from that node's attributes. Otherwise, it is probably computed at runtime, and so a value cannot be determined statically.

@askhade askhade closed this as completed Oct 27, 2021
@zoeStartover
Copy link

Hi. What a coincidence. I got the same problem when I used CrypTen. The reason why I cause the problem is I also change opset_operation into 11.
After I learn starts, ends axes, steps have been moved to input, I think a simple way to solve it is to modify the code in CrypTen. There is a class Slice in crypten.nn.module. The class contains three functions: init, forward, from_onnx. Modify the code so that parameters like 'start' don't exist in function from_onnx. Instead, as the program run in forward, you can get them from args.
I just provide a new angle to solve the problem. Hope it helps.

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

No branches or pull requests

5 participants