# Is there any different between torch.sigmoid and torch.nn.functional.sigmoid?

**URL:** <https://discuss.pytorch.org/t/is-there-any-different-between-torch-sigmoid-and-torch-nn-functional-sigmoid/995>\
**Category:** Uncategorized\
**Created:** [March 11, 2017, 7:14am UTC](https://discuss.pytorch.org/t/is-there-any-different-between-torch-sigmoid-and-torch-nn-functional-sigmoid/995 "2017-03-11T07:14:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Teaonly](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/teaonly/32/3300_2.png) [@Teaonly](https://discuss.pytorch.org/u/Teaonly)\
**Post date:** [March 11, 2017, 7:14am UTC](https://discuss.pytorch.org/t/is-there-any-different-between-torch-sigmoid-and-torch-nn-functional-sigmoid/995/1 "2017-03-11T07:14:10Z")

</div>

I am confused with torch.xxxx which support Tensor and Variable, it should be a function accepting Variable or just a normal function which handling input tensors. But what different between torch.xxxx and [torch.nn.functional.xxx](http://torch.nn.functional.xxx) when input is a Variable ?

---

<div class="post-metadata">

**Author:** ![apaszke](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/apaszke/32/21_2.png) [@apaszke](https://discuss.pytorch.org/u/apaszke)\
**Post date:** [March 11, 2017, 10:33am UTC](https://discuss.pytorch.org/t/is-there-any-different-between-torch-sigmoid-and-torch-nn-functional-sigmoid/995/2 "2017-03-11T10:33:10Z")

</div>

`torch.*` functions work for both Tensors and Variables. There’s no difference between `torch.sigmoid` and `torch.nn.functional.sigmoid`.

---

<div class="post-metadata">

**Author:** ![fmassa](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/fmassa/32/58_2.png) [@fmassa](https://discuss.pytorch.org/u/fmassa)\
**Post date:** [March 11, 2017, 10:58am UTC](https://discuss.pytorch.org/t/is-there-any-different-between-torch-sigmoid-and-torch-nn-functional-sigmoid/995/3 "2017-03-11T10:58:27Z")

</div>

Actually, there is a difference.  
The implementations in `torch.xxx` have the [backward implemented using `python` calls](https://github.com/pytorch/pytorch/blob/master/torch/autograd/_functions/pointwise.py#L70), while the functional counterparts have their backward implemented entirely in [C](https://github.com/pytorch/pytorch/blob/master/torch/lib/THNN/generic/Sigmoid.c#L28)/[Cuda](https://github.com/pytorch/pytorch/blob/master/torch/lib/THCUNN/Sigmoid.cu#L20), so the `functional` backward code is more efficient.

---

<div class="post-metadata">

**Author:** ![Teaonly](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/teaonly/32/3300_2.png) [@Teaonly](https://discuss.pytorch.org/u/Teaonly)\
**Post date:** [March 11, 2017, 1:00pm UTC](https://discuss.pytorch.org/t/is-there-any-different-between-torch-sigmoid-and-torch-nn-functional-sigmoid/995/4 "2017-03-11T13:00:09Z")

</div>

Thanks, i see.

More different is help message, there are help text for python object, no text for registered functions in C.

---

<div class="post-metadata">

**Author:** ![cakeeatingpolarbear](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/c/c0e974/32.png) [@cakeeatingpolarbear](https://discuss.pytorch.org/u/cakeeatingpolarbear)\
**Post date:** [November 21, 2017, 11:41am UTC](https://discuss.pytorch.org/t/is-there-any-different-between-torch-sigmoid-and-torch-nn-functional-sigmoid/995/5 "2017-11-21T11:41:05Z")

</div>

Is this still the case? If so should be writing all my code using `functional` api?

---

<div class="post-metadata">

**Author:** ![Haydnspass](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/haydnspass/32/3780_2.png) [@Haydnspass](https://discuss.pytorch.org/u/Haydnspass)\
**Post date:** [May 3, 2019, 9:09am UTC](https://discuss.pytorch.org/t/is-there-any-different-between-torch-sigmoid-and-torch-nn-functional-sigmoid/995/6 "2019-05-03T09:09:15Z")

</div>

I guess this is deprecated (at least as of Pytorch 1.0.0). But since one can find it so easily via google, I wrote this reply 🙂

```auto
UserWarning: nn.functional.sigmoid is deprecated. Use torch.sigmoid instead.
  warnings.warn("nn.functional.sigmoid is deprecated. Use torch.sigmoid instead.")

```

---

<div class="post-metadata">

**Author:** ![drevicko](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/drevicko/32/14854_2.png) [@drevicko](https://discuss.pytorch.org/u/drevicko)\
**Post date:** [March 18, 2020, 1:27am UTC](https://discuss.pytorch.org/t/is-there-any-different-between-torch-sigmoid-and-torch-nn-functional-sigmoid/995/8 "2020-03-18T01:27:08Z")

</div>

Hi @fmassa: is this still the case?
