Code for ParametrizedConv1d in transformer code for wav2vec2 for ctc

mi_gupta: <p>Hi i want to write code for<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/a/3/a35e04eec2b56d4330b5be653af06ac52a46b970.png" data-download-href="https://discuss.pytorch.org/uploads/default/a35e04eec2b56d4330b5be653af06ac52a46b970" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/a/3/a35e04eec2b56d4330b5be653af06ac52a46b970.png" alt="image" data-base62-sha1="njdgj6UJ65RvYXDHTdwCwLN34hG" width="690" height="191" data-dominant-color="3F3F3F"><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">image</span><span class="informations">801×222 6.25 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><br>
i have written the code , but for the weight file i’m getting keys as :</p>
<p>conv.conv.bias<br>
conv.conv.weight_g<br>
conv.conv.weight_v<br>
conv.parametrizations.weight.bias<br>
conv.parametrizations.weight.weight_g<br>
conv.parametrizations.weight.weight_v</p>
<p>but i need only first 3 keys of the saved weight in code also.<br>
what changes do i need to make<br>
{<br>
conv.conv.bias<br>
conv.conv.weight_g<br>
conv.conv.weight_v<br>
}</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/5/5/55caf8be3378126ae1c3ffd596fe967c9acf3e6d.png" data-download-href="https://discuss.pytorch.org/uploads/default/55caf8be3378126ae1c3ffd596fe967c9acf3e6d" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/5/5/55caf8be3378126ae1c3ffd596fe967c9acf3e6d.png" alt="image" data-base62-sha1="ceXrSPqnJqlsY8IZ8slZoplqxJz" width="690" height="325" data-dominant-color="242524"><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">image</span><span class="informations">1347×635 27.8 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>
<blockquote>
<p>import torch<br>
import torch.nn as nn</p>
<p>class _WeightNorm(nn.Module):<br>
def <strong>init</strong>(self):<br>
super(_WeightNorm, self).<strong>init</strong>()</p>
<pre><code>def forward(self, x):
    return x
</code></pre>
<p>class ParametrizedConv1d(nn.Module):<br>
def <strong>init</strong>(self, in_channels, out_channels, kernel_size, stride, padding, groups):<br>
super(ParametrizedConv1d, self).<strong>init</strong>()<br>
self.conv = nn.Conv1d(in_channels, out_channels, kernel_size=kernel_size, stride=stride, padding=padding, groups=groups)<br>
self.parametrizations = nn.ModuleDict({‘weight’: nn.utils.weight_norm(self.conv, name=‘weight’)})</p>
<pre><code>def forward(self, x):
    return self.conv(x)
</code></pre>
<p>class ConvolutionalPositionalEmbedding(nn.Module):<br>
def <strong>init</strong>(self, input_dim=768, output_dim=768, kernel_size=128, stride=1, padding=64, groups=16):<br>
super(ConvolutionalPositionalEmbedding, self).<strong>init</strong>()<br>
self.conv = ParametrizedConv1d(input_dim, output_dim, kernel_size=kernel_size, stride=stride, padding=padding, groups=groups)</p>
<pre><code>def forward(self, x):
    return self.conv(x)
</code></pre>
</blockquote>