Skip to content

Commit

Permalink
Merge branch 'master' into training
Browse files Browse the repository at this point in the history
  • Loading branch information
wschin committed Jan 24, 2020
2 parents 77333af + bbd604e commit 9bd2c39
Show file tree
Hide file tree
Showing 41 changed files with 804 additions and 19 deletions.
61 changes: 59 additions & 2 deletions docs/Changelog.md
Expand Up @@ -13532,7 +13532,7 @@ This version of the operator has been available since version 11 of the default
<dt><tt>axis</tt> : int (default is 0)</dt>
<dd>Which axis to split on. A negative value means counting dimensions from the back. Accepted range is [-rank, rank-1] where r = rank(input).</dd>
<dt><tt>split</tt> : list of ints</dt>
<dd>length of each output</dd>
<dd>length of each output. Values should be >= 0.</dd>
</dl>

#### Inputs
Expand Down Expand Up @@ -13588,7 +13588,7 @@ This version of the operator has been available since version 11 of the default
<dt><tt>input</tt> : T</dt>
<dd>The tensor to split</dd>
<dt><tt>split</tt> (optional) : I</dt>
<dd>Length of each output. It can be either a scalar(tensor of empty shape), or a 1-D tensor. All values must be positive. </dd>
<dd>Length of each output. It can be either a scalar(tensor of empty shape), or a 1-D tensor. All values must be >= 0. </dd>
</dl>

#### Outputs
Expand Down Expand Up @@ -13965,6 +13965,63 @@ This version of the operator has been available since version 12 of the default
<dd>Constrain input and output types to all numeric tensors.</dd>
</dl>

### <a name="Einsum-12"></a>**Einsum-12**</a>

An einsum of the form ```term1, term2 -> output-term``` produces an output tensor using the following equation

```output[output-term] = reduce-sum( input1[term1] * input2[term] )```

where the reduce-sum performs a summation over all the indices occurring in in the input terms (term1, term2)
that do not occur in the output-term.

The Einsum operator evaluates algebraic tensor operations on a sequence of tensors, using the Einstein summation
convention. The equation string contains a comma-separated sequence of lower case letters. Each term corresponds to
an operand tensor, and the characters within the terms correspond to operands dimensions.

This sequence may be followed by "->" to separate the left and right hand side of the equation.
If the equation contains "->" followed by the right-hand side, the explicit (not classical) form of the Einstein
summation is performed, and the right-hand side indices indicate output tensor dimensions. In other cases,
output indices are (implicitly) set to the alphabetically sorted sequence of indices appearing exactly once in the
equation.

When a dimension character is repeated in the left-hand side, it represents summation along the dimension.

The equation may contain ellipsis ("...") to enable broadcasting. Ellipsis must indicate a fixed number of dimensions.
The right-hand side may contain exactly one ellipsis. In implicit mode, the ellipsis dimensions are set to the
beginning of the output. The equation string may contain space (U+0020) character.

#### Version

This version of the operator has been available since version 12 of the default ONNX operator set.

#### Attributes

<dl>
<dt><tt>equation</tt> : string (required)</dt>
<dd>Einsum expression string.</dd>
</dl>

#### Inputs (1 - &#8734;)

<dl>
<dt><tt>Inputs</tt> (variadic) : T</dt>
<dd>Operands</dd>
</dl>

#### Outputs

<dl>
<dt><tt>Output</tt> : T</dt>
<dd>Output tensor</dd>
</dl>

#### Type Constraints

<dl>
<dt><tt>T</tt> : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)</dt>
<dd>Constrain input and output types to all numerical tensor types.</dd>
</dl>

### <a name="Gradient-12"></a>**Gradient-12**</a>

Gradient operator computes the partial derivatives of a specific tensor to
Expand Down
193 changes: 191 additions & 2 deletions docs/Operators.md
Expand Up @@ -37,6 +37,7 @@
* <a href="#Det">Det</a>
* <a href="#Div">Div</a>
* <a href="#Dropout">Dropout</a>
* <a href="#Einsum">Einsum</a>
* <a href="#Elu">Elu</a>
* <a href="#Equal">Equal</a>
* <a href="#Erf">Erf</a>
Expand Down Expand Up @@ -4398,6 +4399,173 @@ expect(node, inputs=[X], outputs=[Y, Y_Scale, Y_ZeroPoint],
</details>


### <a name="Einsum"></a><a name="einsum">**Einsum**</a>

An einsum of the form ```term1, term2 -> output-term``` produces an output tensor using the following equation

```output[output-term] = reduce-sum( input1[term1] * input2[term] )```

where the reduce-sum performs a summation over all the indices occurring in in the input terms (term1, term2)
that do not occur in the output-term.

The Einsum operator evaluates algebraic tensor operations on a sequence of tensors, using the Einstein summation
convention. The equation string contains a comma-separated sequence of lower case letters. Each term corresponds to
an operand tensor, and the characters within the terms correspond to operands dimensions.

This sequence may be followed by "->" to separate the left and right hand side of the equation.
If the equation contains "->" followed by the right-hand side, the explicit (not classical) form of the Einstein
summation is performed, and the right-hand side indices indicate output tensor dimensions. In other cases,
output indices are (implicitly) set to the alphabetically sorted sequence of indices appearing exactly once in the
equation.

When a dimension character is repeated in the left-hand side, it represents summation along the dimension.

The equation may contain ellipsis ("...") to enable broadcasting. Ellipsis must indicate a fixed number of dimensions.
The right-hand side may contain exactly one ellipsis. In implicit mode, the ellipsis dimensions are set to the
beginning of the output. The equation string may contain space (U+0020) character.

#### Version

This version of the operator has been available since version 12 of the default ONNX operator set.

#### Attributes

<dl>
<dt><tt>equation</tt> : string (required)</dt>
<dd>Einsum expression string.</dd>
</dl>

#### Inputs (1 - &#8734;)

<dl>
<dt><tt>Inputs</tt> (variadic) : T</dt>
<dd>Operands</dd>
</dl>

#### Outputs

<dl>
<dt><tt>Output</tt> : T</dt>
<dd>Output tensor</dd>
</dl>

#### Type Constraints

<dl>
<dt><tt>T</tt> : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)</dt>
<dd>Constrain input and output types to all numerical tensor types.</dd>
</dl>


#### Examples

<details>
<summary>einsum_batch_diagonal</summary>

```python
Eqn = '...ii ->...i'
node = onnx.helper.make_node(
'Einsum',
inputs=['x'],
outputs=['y'],
equation=Eqn
)

X = np.random.randn(3, 5, 5)
Z = einsum_reference_implementation(Eqn, (X,))

expect(node, inputs=[X], outputs=[Z], name='test_einsum_batch_diagonal')
```

</details>


<details>
<summary>einsum_batch_matmul</summary>

```python
Eqn = 'bij, bjk -> bik'
node = onnx.helper.make_node(
'Einsum',
inputs=['x', 'y'],
outputs=['z'],
equation=Eqn
)

X = np.random.randn(5, 2, 3)
Y = np.random.randn(5, 3, 4)
Z = einsum_reference_implementation(Eqn, (X, Y))

expect(node, inputs=[X, Y], outputs=[Z], name='test_einsum_batch_matmul')
```

</details>


<details>
<summary>einsum_inner_prod</summary>

```python
Eqn = 'i,i'
node = onnx.helper.make_node(
'Einsum',
inputs=['x', 'y'],
outputs=['z'],
equation=Eqn
)

X = np.random.randn(5)
Y = np.random.randn(5)
Z = einsum_reference_implementation(Eqn, (X, Y))

expect(node, inputs=[X, Y], outputs=[Z], name='test_einsum_inner_prod')
```

</details>


<details>
<summary>einsum_sum</summary>

```python
Eqn = 'ij->i'
node = onnx.helper.make_node(
'Einsum',
inputs=['x'],
outputs=['y'],
equation=Eqn
)

X = np.random.randn(3, 4)
Z = einsum_reference_implementation(Eqn, (X,))

expect(node, inputs=[X], outputs=[Z], name='test_einsum_sum')
```

</details>


<details>
<summary>einsum_transpose</summary>

```python
Eqn = 'ij->ji'
node = onnx.helper.make_node(
'Einsum',
inputs=['x'],
outputs=['y'],
equation=Eqn
)

X = np.random.randn(3, 4)
Y = einsum_reference_implementation(Eqn, (X,))

expect(node, inputs=[X], outputs=[Y], name='test_einsum_transpose')
```

</details>


### <a name="Elu"></a><a name="elu">**Elu**</a>

Elu takes one input data (Tensor<T>) and produces one output data
Expand Down Expand Up @@ -17034,7 +17202,7 @@ Other versions of this operator: <a href="Changelog.md#Split-1">Split-1</a>, <a
<dt><tt>axis</tt> : int (default is 0)</dt>
<dd>Which axis to split on. A negative value means counting dimensions from the back. Accepted range is [-rank, rank-1] where r = rank(input).</dd>
<dt><tt>split</tt> : list of ints</dt>
<dd>length of each output</dd>
<dd>length of each output. Values should be >= 0.</dd>
</dl>

#### Inputs
Expand Down Expand Up @@ -17158,6 +17326,27 @@ expect(node, inputs=[input], outputs=[y for y in expected_outputs], name='test_s
</details>


<details>
<summary>zero_size_splits</summary>

```python
input = np.array([]).astype(np.float32)

# Split emtpy tensor to tensors of size zero
node = onnx.helper.make_node(
'Split',
inputs=['input'],
outputs=['output_1', 'output_2', 'output_3'],
split=[0, 0, 0]
)

expected_outputs = [np.array([]).astype(np.float32), np.array([]).astype(np.float32), np.array([]).astype(np.float32)]
expect(node, inputs=[input], outputs=[y for y in expected_outputs], name='test_split_zero_size_splits')
```

</details>


### <a name="SplitToSequence"></a><a name="splittosequence">**SplitToSequence**</a>

Split a tensor into a sequence of tensors, along the specified
Expand Down Expand Up @@ -17190,7 +17379,7 @@ This version of the operator has been available since version 11 of the default
<dt><tt>input</tt> : T</dt>
<dd>The tensor to split</dd>
<dt><tt>split</tt> (optional) : I</dt>
<dd>Length of each output. It can be either a scalar(tensor of empty shape), or a 1-D tensor. All values must be positive. </dd>
<dd>Length of each output. It can be either a scalar(tensor of empty shape), or a 1-D tensor. All values must be >= 0. </dd>
</dl>

#### Outputs
Expand Down

0 comments on commit 9bd2c39

Please sign in to comment.