Skip to content

Make the starts and sizes definitions of slice op consistent and simplified #369

@huningxin

Description

@huningxin

Thanks @fdwr for pointing out the inconsistency of starts and sizes definitions of slice op when revisiting the PR #359 (comment), where Dwayne mentioned:

I just noticed slices parameter starts still has the negative number policy and accepts axis coordinates as long rather than unsigned long; and its sizes parameter has an unusual policy that -1 is special, whereas sizes in resample2D is sequence. Do we want to rationalize these for consistency too, having higher level policy like this determined by the calling framework?

In a followed comment, Dwayne also pointed out that

we see that every other sizes parameter is unsigned long (see below), leaving only slice as sequence sizes.

From my point of view, using unsigned integer for starts and sizes makes sense. It not only would help ensure the consistency across the spec but also would simplify the implementation. The native ML APIs, such as DirectML's DML_SLICE1_OPERATOR_DESC and XNNPACK's xnn_define_static_slice, usually use unsigned integer starts/offsets and sizes.

Another simplification idea is whether the MLSliceOptions should be removed. MLSliceOptions.axes is used to indicate the dimensions of the input shape to which starts and sizes apply. However, native ML APIs, e.g. DirectML's DML_SLICE1_OPERATOR_DESC, XNNPACK's xnn_define_static_slice and MLCompute's MLCSliceLayer, usually expect the starts and offsets for all dimensions to be provided.

With that, a possible simplified slice op definition would be

partial interface MLGraphBuilder {
  // The length of `starts` and `sizes` sequences should equal to the rank of input tensor.
  MLOperand slice(MLOperand input, sequence<unsigned long> starts, sequence<unsigned long> sizes);
};

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions