After summing parameters of two models and storing that parameters to one of that model I am getting zero output but why?

CVLab_005: <p>So I am trying to implement paper named Cross Domain FRCN for few shot. There I had to do this,</p>
<p>teacher_parameters = teacher_parameters + ALPHA * student_parameters</p>
<p>So I am doing this,<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/3/6/36bfb9c2ad592596f096eb3190f1607471485020.png" data-download-href="https://discuss.pytorch.org/uploads/default/36bfb9c2ad592596f096eb3190f1607471485020" title="update_fn"><img src="https://discuss.pytorch.org/uploads/default/original/3X/3/6/36bfb9c2ad592596f096eb3190f1607471485020.png" alt="update_fn" data-base62-sha1="7OkykhURq33nWTFlVW9yCEii9Vu" width="690" height="214" data-dominant-color="232424"><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">update_fn</span><span class="informations">994×309 9.11 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>
<p>But when I am doing testing the output for bounding boxes are empty.<br>
Interesting part is this empty output occurs if I sum two parameters. If I just scale one parameter my model gives output. Like,</p>
<p>teacher_parameters = ALPHA * student_parameters</p>
<p>So the problem occurs only if I sum two parameters.</p>
<p><em>ADDITIONAL INFORMATION</em></p>
<ol>
<li>Two models are this one “torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=True)”</li>
<li>You can see one teacher and one student model. I am using teacher model for the inference stage.</li>
</ol>

AlphaBetaGamma96: <p>Hi <a class="mention" href="/u/cvlab_005">@CVLab_005</a>,</p>
<p>Firstly, can you share code via 3 backticks ``` instead of sharing screenshots. (Including minimal reproducible example with expected behavior).</p>
<p>Secondly, I think you may have a problem when you’re re-wrapping your parameters and registering them to the <code>.data</code> attribute, which is deprecated. Try the following,</p>
<pre><code class="lang-auto">for p_out, p_in1, p_in2 in zip(teacher.parmeters(), student.parameters(), teacher.parameters()):
  p_out.fill_(p_in1 + p_in2)
</code></pre>
<p>Also, could you not simplify this via doing an in-place add?</p>
<pre><code class="lang-auto">for t, s in zip(teacher.parameters(), student.parameters()):
  t.add_(s)
</code></pre>

CVLab_005: <p>Thank you for the reply.<br>
But this,</p>
<pre><code class="lang-auto">for p_out, p_in1, p_in2 in zip(teacher.parmeters(), student.parameters(), teacher.parameters()):
  p_out.fill_(p_in1 + p_in2)
</code></pre>
<p>gives error telling fill_ can only work on tensor with 0 dimension. But my parameters will have more than 0 dimensions.<br>
And I also tried this earlier.</p>
<pre><code class="lang-auto">with torch.no_grad():
  for t_param,s_param in zip(teacher.parameters(),student.parameters()):

  #print(type(t_param.data))

   t_param.add_(s_param)
</code></pre>
<p>But gives empty output.<br>
I tried another thing like this one,</p>
<pre><code class="lang-auto">def update_parameters():

  with torch.no_grad():
    for tparam,sparam in zip(teacher.parameters(),student.parameters()):
      tparam[:2] = tparam[:2] + ALPHA * sparam[:2] 
</code></pre>
<p>This works for only once. I mean I can update only once and it works. But if I call this update_parameters function multiple times then it again gives me empty outputs.</p>

CVLab_005: <p>Guys I found out the mistake I made while coding. The equation is,<br>
teacher_parameters = ALPHA * teacher_parameters + ( 1 - ALPHA ) * student_parameters<br>
not this,<br>
teacher_parameters = teacher_parameters + ALPHA * student_parameters</p>
<p>Since my teacher’s parameters kept increasing, at the end my bounding boxes kept decresing in size with every iteration and after some iteration it vanishes.</p>
<p>After correcting my code every solution provided above works.<br>
Sorry for the inconvenience and Thanks for the help.</p>