# torch.nn.Sigmoid vs torch.sigmoid

**URL:** <https://discuss.pytorch.org/t/torch-nn-sigmoid-vs-torch-sigmoid/57691>\
**Category:** Uncategorized\
**Created:** [October 8, 2019, 9:42am UTC](https://discuss.pytorch.org/t/torch-nn-sigmoid-vs-torch-sigmoid/57691 "2019-10-08T09:42:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rohan\_Kumar](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/rohan_kumar/32/10228_2.png) [@Rohan\_Kumar](https://discuss.pytorch.org/u/Rohan_Kumar)\
**Post date:** [October 8, 2019, 9:42am UTC](https://discuss.pytorch.org/t/torch-nn-sigmoid-vs-torch-sigmoid/57691/1 "2019-10-08T09:42:34Z")

</div>

what is the difference between these 2 sigmoid functions?

---

<div class="post-metadata">

**Author:** ![alex.veuthey](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/alex.veuthey/32/12176_2.png) [@alex.veuthey](https://discuss.pytorch.org/u/alex.veuthey)\
**Post date:** [October 8, 2019, 10:40am UTC](https://discuss.pytorch.org/t/torch-nn-sigmoid-vs-torch-sigmoid/57691/2 "2019-10-08T10:40:56Z")

</div>

AFAIK, `torch.nn.Sigmoid` calls `torch.nn.functional.sigmoid` in the background, and according to [this answer](https://discuss.pytorch.org/t/is-there-any-different-between-torch-sigmoid-and-torch-nn-functional-sigmoid/995/3), the functional and `torch.xxx` calls differ with their backwards implementation (which is more efficient and GPU capable in the `torch.nn` case).

---

<div class="post-metadata">

**Author:** ![KFrank](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/k/ecb155/32.png) [@KFrank](https://discuss.pytorch.org/u/KFrank)\
**Post date:** [October 8, 2019, 4:46pm UTC](https://discuss.pytorch.org/t/torch-nn-sigmoid-vs-torch-sigmoid/57691/3 "2019-10-08T16:46:15Z")

</div>

Hi Rohan!

> [@Rohan\_Kumar](#):
>
> what is the difference between these 2 sigmoid functions?

`torch.nn.Sigmoid` (note the capital “S”) is a _class_. When you  
instantiate it, you get a _function object_, that is, an object that you  
can call like a function. In contrast, `torch.sigmoid` is a function.

From the [source code](https://pytorch.org/docs/stable/_modules/torch/nn/modules/activation.html#Sigmoid) for `torch.nn.Sigmoid`, you can  
see that it calls `torch.sigmoid`, so the two are functionally  
same.

(Why even have such a class / function object? Because,  
although it isn’t the case for `Sigmoid`, in many cases when  
you construct a pytorch function object you can pass in  
parameters to the constructor that control the behavior of the  
function. This is useful in cases where where the caller isn’t  
able (or it might just be annoying) to pass in those parameters  
when actually calling the function.)

As far as Alex’s comment, he references  
`torch.nn.functional.sigmoid`, which is (probably) different  
than `torch.sigmoid`. (Again, in any event, directly from the  
source code, `torch.nn.Sigmoid` calls `torch.sigmoid`, so  
the two are functionally the same.)

As for the post Alex links to, about  
`torch.nn.functional.sigmoid` having a different backwards  
implementation than `torch.sigmoid`, I suspect that this is out  
of date (or perhaps just incorrect). Its documentation shows  
that it’s deprecated in favor of `torch.sigmoid()` and that is  
calls `input.sigmoid()`. I very much doubt that  
`torch.nn.functional.sigmoid` and `torch.sigmoid`  
do anything different (but since I can’t find any code for  
`torch.sigmoid` or `tensor.sigmoid` it’s hard to tie this  
up into a neat, little package).

Good luck.

K. Frank
