# Parameter is not getting iniatlized

**URL:** <https://discuss.pytorch.org/t/parameter-is-not-getting-iniatlized/116237>\
**Category:** Uncategorized\
**Created:** [March 28, 2021, 10:55am UTC](https://discuss.pytorch.org/t/parameter-is-not-getting-iniatlized/116237 "2021-03-28T10:55:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ADONAI\_TZEVAOT](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/adonai_tzevaot/32/31089_2.png) [@ADONAI\_TZEVAOT](https://discuss.pytorch.org/u/ADONAI_TZEVAOT)\
**Post date:** [March 28, 2021, 10:55am UTC](https://discuss.pytorch.org/t/parameter-is-not-getting-iniatlized/116237/1 "2021-03-28T10:55:23Z")

</div>

```auto
class A(nn.Module):
    def __init__ (self):
        super(A,self). __init__ ()
        self.p = nn.Parameter(torch.randn(1))

```

In def forward when I call `print(self.p.shape, self.p)`, it is returning :

```auto
torch.Size([0]) Parameter containing:
tensor([], requires_grad=True)

```

So, self.p is not initialized. How to initialize this ? Please help.

---

<div class="post-metadata">

**Author:** ![sio277](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/sio277/32/37684_2.png) [@sio277](https://discuss.pytorch.org/u/sio277)\
**Post date:** [March 28, 2021, 6:11pm UTC](https://discuss.pytorch.org/t/parameter-is-not-getting-iniatlized/116237/2 "2021-03-28T18:11:35Z")

</div>

It works for me.

```auto
import torch
import torch.nn as nn

class A(nn.Module):
    def __init__ (self):
        super(A,self). __init__ ()
        self.p = nn.Parameter(torch.randn(1))
        
    def forward(self):
        print(self.p.shape, self.p)
        
a = A()
a()

```

which prints out:

torch.Size([1]) Parameter containing:  
tensor([-0.3897], requires\_grad=True).

---

<div class="post-metadata">

**Author:** ![ADONAI\_TZEVAOT](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/adonai_tzevaot/32/31089_2.png) [@ADONAI\_TZEVAOT](https://discuss.pytorch.org/u/ADONAI_TZEVAOT)\
**Post date:** [March 28, 2021, 6:13pm UTC](https://discuss.pytorch.org/t/parameter-is-not-getting-iniatlized/116237/3 "2021-03-28T18:13:37Z")

</div>

I dunno what exactly the error was, it didn’t run in the beginning , now its running. I’m getting errors if I dont remove `A,self` inside `super()`. Any idea why.

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [March 30, 2021, 5:30am UTC](https://discuss.pytorch.org/t/parameter-is-not-getting-iniatlized/116237/4 "2021-03-30T05:30:26Z")

</div>

What kind of errors are you seeing if you keep `super(A, self). __init__ ()` and which Python version are you using?  
The arguments were only necessary in Python2, if I’m not mistaken, but I haven’t seen it’s raising an error in Python3.
