# Add some new tensorflow ops

**URL:** <https://discuss.tvm.apache.org/t/add-some-new-tensorflow-ops/8217>\
**Category:** RFC\
**Created:** [October 20, 2020, 9:53am UTC](https://discuss.tvm.apache.org/t/add-some-new-tensorflow-ops/8217 "2020-10-20T09:53:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![alter-xp](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/alter-xp/32/2102_2.png) [@alter-xp](https://discuss.tvm.apache.org/u/alter-xp)\
**Post date:** [October 20, 2020, 9:53am UTC](https://discuss.tvm.apache.org/t/add-some-new-tensorflow-ops/8217/1 "2020-10-20T09:53:38Z")

</div>

## Motivation

In order to enrich the support of TF operator and the need of practical work, we add 15 operators to TVM. as follows: \* Expm1, Rint, Softsign, Cumprod, Cumsum \* SegmentMax, SegmentMin, SegmentMean, SegmentPord, SegmentSum \* UnsortedSegmentMax, UnsortedSegmentMin, UnsortedSegmentMean \* UnsortedSegmentPord, UnsortedSegmentSum

## Implementation Details

1. **Expm1** [https://tensorflow.google.cn/api\_docs/python/tf/math/expm1](https://tensorflow.google.cn/api_docs/python/tf/math/expm1) ![image](https://discuss.tvm.apache.org/uploads/default/original/2X/3/360c4a1c3b03a7fda6a99db43924786b11f6f306.png)
2. **Softsign** [https://tensorflow.google.cn/api\_docs/python/tf/nn/softsign](https://tensorflow.google.cn/api_docs/python/tf/nn/softsign) ![image](https://discuss.tvm.apache.org/uploads/default/original/2X/8/85ff3050bbca22aaf34f9995bbc7d093c8819724.png)
3. **Rint** [https://tensorflow.google.cn/api\_docs/python/tf/math/rint](https://tensorflow.google.cn/api_docs/python/tf/math/rint)
4. **Cumprod** [https://tensorflow.google.cn/api\_docs/python/tf/math/cumprod](https://tensorflow.google.cn/api_docs/python/tf/math/cumprod)
5. **Cumsum** [https://tensorflow.google.cn/api\_docs/python/tf/math/cumsum](https://tensorflow.google.cn/api_docs/python/tf/math/cumsum)
6. **SegmentMax** [https://tensorflow.google.cn/api\_docs/python/tf/math/segment\_max](https://tensorflow.google.cn/api_docs/python/tf/math/segment_max)
7. **SegmentMin** [https://tensorflow.google.cn/api\_docs/python/tf/math/segment\_min](https://tensorflow.google.cn/api_docs/python/tf/math/segment_min)
8. **SegmentMean** [https://tensorflow.google.cn/api\_docs/python/tf/math/segment\_mean](https://tensorflow.google.cn/api_docs/python/tf/math/segment_mean)
9. **SegmentPord** [https://tensorflow.google.cn/api\_docs/python/tf/math/segment\_prod](https://tensorflow.google.cn/api_docs/python/tf/math/segment_prod)
10. **SegmentSum** [https://tensorflow.google.cn/api\_docs/python/tf/math/segment\_sum](https://tensorflow.google.cn/api_docs/python/tf/math/segment_sum)
11. **UnsortedSegmentMax** [https://tensorflow.google.cn/api\_docs/python/tf/math/unsorted\_segment\_max](https://tensorflow.google.cn/api_docs/python/tf/math/unsorted_segment_max)
12. **UnsortedSegmentMin** [https://tensorflow.google.cn/api\_docs/python/tf/math/unsorted\_segment\_min](https://tensorflow.google.cn/api_docs/python/tf/math/unsorted_segment_min)
13. **UnsortedSegmentMean** [https://tensorflow.google.cn/api\_docs/python/tf/math/unsorted\_segment\_mean](https://tensorflow.google.cn/api_docs/python/tf/math/unsorted_segment_mean)
14. **UnsortedSegmentProd** [https://tensorflow.google.cn/api\_docs/python/tf/math/unsorted\_segment\_prod](https://tensorflow.google.cn/api_docs/python/tf/math/unsorted_segment_prod)
15. **UnsortedSegmentSum** [https://tensorflow.google.cn/api\_docs/python/tf/math/unsorted\_segment\_sum](https://tensorflow.google.cn/api_docs/python/tf/math/unsorted_segment_sum)

In TF frontend, exmp1 composed by exp and subtraction. Softsign composed by abs and divide. Rint replaced by round. We provide a new implementation for Cumsum, Cumprod, SegmentMax, SegmentMin, SegmentMean, SegmentProd, and SegmentSum operators. For the UnsortedSegment operators, they share a set of implementation with Segment operators. The conversion is completed in TF frontend.

@Huyuwei @hlu1 @kazum @siju-samuel @FrozenGene

---

<div class="post-metadata">

**Author:** ![tiandiao123](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/tiandiao123/32/1891_2.png) [@tiandiao123](https://discuss.tvm.apache.org/u/tiandiao123)\
**Post date:** [October 20, 2020, 10:01pm UTC](https://discuss.tvm.apache.org/t/add-some-new-tensorflow-ops/8217/2 "2020-10-20T22:01:26Z")

</div>

nice job! If it works out, it will be really helpful!

---

<div class="post-metadata">

**Author:** ![FrozenGene](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/frozengene/32/1114_2.png) [@FrozenGene](https://discuss.tvm.apache.org/u/FrozenGene)\
**Post date:** [October 22, 2020, 8:09am UTC](https://discuss.tvm.apache.org/t/add-some-new-tensorflow-ops/8217/3 "2020-10-22T08:09:41Z")

</div>

I think we could just send pr directly. Of course, we could make them be several prs, not one big pr.

---

<div class="post-metadata">

**Author:** ![masahi](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/masahi/32/74_2.png) [@masahi](https://discuss.tvm.apache.org/u/masahi)\
**Post date:** [October 22, 2020, 8:36am UTC](https://discuss.tvm.apache.org/t/add-some-new-tensorflow-ops/8217/4 "2020-10-22T08:36:15Z")

</div>

I’m curious, how did you implement cumsum? I also wanted cumsum op a while back, but for me it was not clear how it can be implemented efficiently in TVM.

---

<div class="post-metadata">

**Author:** ![alter-xp](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/alter-xp/32/2102_2.png) [@alter-xp](https://discuss.tvm.apache.org/u/alter-xp)\
**Post date:** [October 23, 2020, 2:26am UTC](https://discuss.tvm.apache.org/t/add-some-new-tensorflow-ops/8217/5 "2020-10-23T02:26:43Z")

</div>

I’ll make them down into several prs, than send them directly. Thank you.

---

<div class="post-metadata">

**Author:** ![alter-xp](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/alter-xp/32/2102_2.png) [@alter-xp](https://discuss.tvm.apache.org/u/alter-xp)\
**Post date:** [October 23, 2020, 3:06am UTC](https://discuss.tvm.apache.org/t/add-some-new-tensorflow-ops/8217/6 "2020-10-23T03:06:42Z")

</div>

We have tried using te.scan and te.compute to implement cumsum. But it seems that there is no way to use the same formula to adapt to all situations. Finally, we implement it with te.extern.

---

<div class="post-metadata">

**Author:** ![masahi](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/masahi/32/74_2.png) [@masahi](https://discuss.tvm.apache.org/u/masahi)\
**Post date:** [October 23, 2020, 3:45am UTC](https://discuss.tvm.apache.org/t/add-some-new-tensorflow-ops/8217/7 "2020-10-23T03:45:02Z")

</div>

Thanks, yeah I also remember `te.scan` only supports scanning along the first axis. I think `te.extern` is good as a first step.
