# Customize Linear Operation in nn.Conv2d

**URL:** <https://discuss.pytorch.org/t/customize-linear-operation-in-nn-conv2d/21150>\
**Category:** Uncategorized\
**Created:** [July 14, 2018, 9:58pm UTC](https://discuss.pytorch.org/t/customize-linear-operation-in-nn-conv2d/21150 "2018-07-14T21:58:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shen](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/4da419/32.png) [@Shen](https://discuss.pytorch.org/u/Shen)\
**Post date:** [July 14, 2018, 9:58pm UTC](https://discuss.pytorch.org/t/customize-linear-operation-in-nn-conv2d/21150/1 "2018-07-14T21:58:23Z")

</div>

Hi, currently I’m trying to replace all linear operation (i.e. y = WX + b) in a CNN with my own version. So far I can customize those linear operations in fully connected layers, but not the convolution layers. Is it possible to modify those in convolution layers?  
Thanks!!

---

<div class="post-metadata">

**Author:** ![Naman-ntc](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/naman-ntc/32/32044_2.png) [@Naman-ntc](https://discuss.pytorch.org/u/Naman-ntc)\
**Post date:** [July 15, 2018, 12:41am UTC](https://discuss.pytorch.org/t/customize-linear-operation-in-nn-conv2d/21150/2 "2018-07-15T00:41:43Z")

</div>

We can’t help alot if you won’t tell how to modifyby ‘your version’, Try looking at [functional nn](https://pytorch.org/docs/stable/_modules/torch/nn/functional.html) maybe it’ll be a good place to start…

---

<div class="post-metadata">

**Author:** ![Shen](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/4da419/32.png) [@Shen](https://discuss.pytorch.org/u/Shen)\
**Post date:** [July 15, 2018, 1:58am UTC](https://discuss.pytorch.org/t/customize-linear-operation-in-nn-conv2d/21150/3 "2018-07-15T01:58:48Z")

</div>

Actually, I want to use the hardware to perform this linear computation, and use the result in the CNN. In order to do this, I need to first ensure the linear operations can be replaced properly.

I have checked the document you provided, it seems the conv2d function has the form **\_add\_docstr(torch.conv2d, …)**, and **\_add\_docstr** function is imported from **torch.\_C** library. I guess the convolution operation was implemented in C (correct me if I’m wrong). Does it mean I need to modify C code in order to achieve my goal?

---

<div class="post-metadata">

**Author:** ![Naman-ntc](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/naman-ntc/32/32044_2.png) [@Naman-ntc](https://discuss.pytorch.org/u/Naman-ntc)\
**Post date:** [July 15, 2018, 2:46am UTC](https://discuss.pytorch.org/t/customize-linear-operation-in-nn-conv2d/21150/4 "2018-07-15T02:46:35Z")

</div>

You would probably be using gpu and it would be cuda modules…

---

<div class="post-metadata">

**Author:** ![Shen](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/4da419/32.png) [@Shen](https://discuss.pytorch.org/u/Shen)\
**Post date:** [July 15, 2018, 5:02am UTC](https://discuss.pytorch.org/t/customize-linear-operation-in-nn-conv2d/21150/5 "2018-07-15T05:02:03Z")

</div>

Thanks for your reply. I think about it again, eventually I would like to replace the original linear operation (i.e. y = WX + b) with some additional noise (i.e. y = WX + b + n where **_n_** is some customized noise). Is there a simple way to do it for convolutional layers?
