akankshakshurai/cuda-error-resolution-analysis huggingface dataset:
Question related to Tensor functions

helloWorld: <p>Hey, I wanted to uunderstand a little bit more about the following functions in the torch.Tensor class :</p>
<p>add_(value=1, other) → Tensor, If I active weights.add_(learning_rate,gradient), then it should add to the weights (learning_rate*gradient) ? or it would sum both learning rate and gradient ? In addition, does the changes apply to the tensor that run the function (in this case weights is a tensor) or it will return a new tensor ?</p>
<p><code>addcdiv</code> ( <em>value=1</em> ,  <em>tensor1</em> ,  <em>tensor2</em> ) → Tensor : it will add c to the current tensor and devide by which  of the tensors (1/2 ) ?</p>
<p>Thanks.</p>

helloWorld: <p>Found an answer :<br>
<code>torch.</code> <code>addcdiv</code> ( <em>input</em> ,  <em>value=1</em> ,  <em>tensor1</em> ,  <em>tensor2</em> ,  <em>out=None</em> ) → Tensor<br>
Performs the element-wise division of  <code>tensor1</code>  by  <code>tensor2</code> , multiply the result by the scalar  <code>value</code>  and add it to  <code>input</code></p>
<p><code>torch.</code> <code>add</code> ( <em>input</em> ,  <em>other</em> ,  <em>alpha=1</em> ,  <em>out=None</em> )</p>
<p>Each element of the tensor  <code>other</code>  is multiplied by the scalar  <code>alpha</code>  and added to each element of the tensor  <code>input</code> .</p>
<p>\text{out} = \text{input} + \text{alpha} \times \text{other}</p>
Expected stride to be a single integer value or a list of 1 values to match the convolution dimensions,

111220: <p>This error has appeared on the forum many times, but it doesn’t seem to be the same as my question.</p>
<p>I’m trying to learn how to use the convolution transpose API,and this is my code:</p>
<p>I use the transpose convolution and its kernel size is (1,1),stride is (2,2). And I then customized the weights so that I could see the end result</p>
<pre><code class="lang-auto">Input=np.asarray([[1,2],[3,4]])
Input=Input.reshape((1,1,2,2))
Input=torch.from_numpy(Input).float()
print(Input.shape)

model=torch.nn.Sequential()
transpose=torch.nn.ConvTranspose2d(1,1,kernel_size=1,stride=2)
weight=np.asarray([[[1]]])
bias=np.asarray([1])
weight=torch.Tensor(weight)
bias=torch.Tensor(bias)
transpose.weight=torch.nn.Parameter(weight)
transpose.bias=torch.nn.Parameter(bias)




model.add_module('transpose',transpose)
yhat=model(Input)
yhat=yhat.reshape((4,4))
print(yhat)

</code></pre>
<p>And the error is:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/6/2634b114cce812ffb675abeb724a32422872bce0.png" data-download-href="https://discuss.pytorch.org/uploads/default/2634b114cce812ffb675abeb724a32422872bce0" title="捕获"><img src="https://discuss.pytorch.org/uploads/default/original/3X/2/6/2634b114cce812ffb675abeb724a32422872bce0.png" alt="捕获" data-base62-sha1="5rZ2bYGHDIgMQexqqImtny8eFG0" width="690" height="251" data-dominant-color="333135"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">捕获</span><span class="informations">1233×449 25.1 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

albanD: <p>Hi,</p>
<p>Why do you try to change the weights?<br>
You can check just after creating the layer what are the correct sizes:</p>
<pre><code class="lang-python">transpose=torch.nn.ConvTranspose2d(1,1,kernel_size=1,stride=2)
print(transpose.weight.size())
print(transpose.bias.size())
</code></pre>
<p>The weight and bias Tensors you create are not of the right size.</p>

111220: <p>Thanks, You help me solve this question!</p>