项目文件夹

文件
Alexandre Défossez (autodoc) aeffa9f270 api_docs
2025-03-13 16:07:03 +00:00

810 行
41 KiB
HTML

此文件含有不可见的 Unicode 字符
此文件含有人类无法区分的不可见的 Unicode 字符,但可以由计算机进行不同的处理。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。
此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
<meta name="generator" content="pdoc3 0.11.5">
<title>audiocraft.modules.conv API documentation</title>
<meta name="description" content="">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/sanitize.min.css" integrity="sha512-y1dtMcuvtTMJc1yPgEqF0ZjQbhnc/bFhyvIyVNb9Zk5mIGtqVaAB1Ttl28su8AvFMOY0EwRbAe+HCLqj6W7/KA==" crossorigin>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/typography.min.css" integrity="sha512-Y1DYSb995BAfxobCkKepB1BqJJTPrOp3zPL74AWFugHHmmdcvO+C48WLrUOlhGMc0QG7AE3f7gmvvcrmX2fDoA==" crossorigin>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css" crossorigin>
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:1.5em;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:2em 0 .50em 0}h3{font-size:1.4em;margin:1.6em 0 .7em 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .2s ease-in-out}a:visited{color:#503}a:hover{color:#b62}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900;font-weight:bold}pre code{font-size:.8em;line-height:1.4em;padding:1em;display:block}code{background:#f3f3f3;font-family:"DejaVu Sans Mono",monospace;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source > summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible;min-width:max-content}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em 1em;margin:1em 0}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul ul{padding-left:1em}.toc > ul > li{margin-top:.5em}}</style>
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js" integrity="sha512-D9gUyxqja7hBtkWpPWGt9wfbfaMGVt9gnyCvYa+jojwwPHLCzUm5i8rpk7vD7wNee9bA35eYIjobYPaQuKS1MQ==" crossorigin></script>
<script>window.addEventListener('DOMContentLoaded', () => {
hljs.configure({languages: ['bash', 'css', 'diff', 'graphql', 'ini', 'javascript', 'json', 'plaintext', 'python', 'python-repl', 'rust', 'shell', 'sql', 'typescript', 'xml', 'yaml']});
hljs.highlightAll();
/* Collapse source docstrings */
setTimeout(() => {
[...document.querySelectorAll('.hljs.language-python > .hljs-string')]
.filter(el => el.innerHTML.length > 200 && ['"""', "'''"].includes(el.innerHTML.substring(0, 3)))
.forEach(el => {
let d = document.createElement('details');
d.classList.add('hljs-string');
d.innerHTML = '<summary>"""</summary>' + el.innerHTML.substring(3);
el.replaceWith(d);
});
}, 100);
})</script>
</head>
<body>
<main>
<article id="content">
<header>
<h1 class="title">Module <code>audiocraft.modules.conv</code></h1>
</header>
<section id="section-intro">
</section>
<section>
</section>
<section>
</section>
<section>
<h2 class="section-title" id="header-functions">Functions</h2>
<dl>
<dt id="audiocraft.modules.conv.apply_parametrization_norm"><code class="name flex">
<span>def <span class="ident">apply_parametrization_norm</span></span>(<span>module: torch.nn.modules.module.Module, norm: str = 'none')</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def apply_parametrization_norm(module: nn.Module, norm: str = &#39;none&#39;):
assert norm in CONV_NORMALIZATIONS
if norm == &#39;weight_norm&#39;:
return weight_norm(module)
elif norm == &#39;spectral_norm&#39;:
return spectral_norm(module)
else:
# We already check was in CONV_NORMALIZATION, so any other choice
# doesn&#39;t need reparametrization.
return module</code></pre>
</details>
<div class="desc"></div>
</dd>
<dt id="audiocraft.modules.conv.get_extra_padding_for_conv1d"><code class="name flex">
<span>def <span class="ident">get_extra_padding_for_conv1d</span></span>(<span>x: torch.Tensor, kernel_size: int, stride: int, padding_total: int = 0) > int</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def get_extra_padding_for_conv1d(x: torch.Tensor, kernel_size: int, stride: int,
padding_total: int = 0) -&gt; int:
&#34;&#34;&#34;See `pad_for_conv1d`.&#34;&#34;&#34;
length = x.shape[-1]
n_frames = (length - kernel_size + padding_total) / stride + 1
ideal_length = (math.ceil(n_frames) - 1) * stride + (kernel_size - padding_total)
return ideal_length - length</code></pre>
</details>
<div class="desc"><p>See <code><a title="audiocraft.modules.conv.pad_for_conv1d" href="#audiocraft.modules.conv.pad_for_conv1d">pad_for_conv1d()</a></code>.</p></div>
</dd>
<dt id="audiocraft.modules.conv.get_norm_module"><code class="name flex">
<span>def <span class="ident">get_norm_module</span></span>(<span>module: torch.nn.modules.module.Module,<br>causal: bool = False,<br>norm: str = 'none',<br>**norm_kwargs)</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def get_norm_module(module: nn.Module, causal: bool = False, norm: str = &#39;none&#39;, **norm_kwargs):
&#34;&#34;&#34;Return the proper normalization module. If causal is True, this will ensure the returned
module is causal, or return an error if the normalization doesn&#39;t support causal evaluation.
&#34;&#34;&#34;
assert norm in CONV_NORMALIZATIONS
if norm == &#39;time_group_norm&#39;:
if causal:
raise ValueError(&#34;GroupNorm doesn&#39;t support causal evaluation.&#34;)
assert isinstance(module, nn.modules.conv._ConvNd)
return nn.GroupNorm(1, module.out_channels, **norm_kwargs)
else:
return nn.Identity()</code></pre>
</details>
<div class="desc"><p>Return the proper normalization module. If causal is True, this will ensure the returned
module is causal, or return an error if the normalization doesn't support causal evaluation.</p></div>
</dd>
<dt id="audiocraft.modules.conv.pad1d"><code class="name flex">
<span>def <span class="ident">pad1d</span></span>(<span>x: torch.Tensor,<br>paddings: Tuple[int, int],<br>mode: str = 'constant',<br>value: float = 0.0)</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def pad1d(x: torch.Tensor, paddings: tp.Tuple[int, int], mode: str = &#39;constant&#39;, value: float = 0.):
&#34;&#34;&#34;Tiny wrapper around F.pad, just to allow for reflect padding on small input.
If this is the case, we insert extra 0 padding to the right before the reflection happen.
&#34;&#34;&#34;
length = x.shape[-1]
padding_left, padding_right = paddings
assert padding_left &gt;= 0 and padding_right &gt;= 0, (padding_left, padding_right)
if mode == &#39;reflect&#39;:
max_pad = max(padding_left, padding_right)
extra_pad = 0
if length &lt;= max_pad:
extra_pad = max_pad - length + 1
x = F.pad(x, (0, extra_pad))
padded = F.pad(x, paddings, mode, value)
end = padded.shape[-1] - extra_pad
return padded[..., :end]
else:
return F.pad(x, paddings, mode, value)</code></pre>
</details>
<div class="desc"><p>Tiny wrapper around F.pad, just to allow for reflect padding on small input.
If this is the case, we insert extra 0 padding to the right before the reflection happen.</p></div>
</dd>
<dt id="audiocraft.modules.conv.pad_for_conv1d"><code class="name flex">
<span>def <span class="ident">pad_for_conv1d</span></span>(<span>x: torch.Tensor, kernel_size: int, stride: int, padding_total: int = 0)</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def pad_for_conv1d(x: torch.Tensor, kernel_size: int, stride: int, padding_total: int = 0):
&#34;&#34;&#34;Pad for a convolution to make sure that the last window is full.
Extra padding is added at the end. This is required to ensure that we can rebuild
an output of the same length, as otherwise, even with padding, some time steps
might get removed.
For instance, with total padding = 4, kernel size = 4, stride = 2:
0 0 1 2 3 4 5 0 0 # (0s are padding)
1 2 3 # (output frames of a convolution, last 0 is never used)
0 0 1 2 3 4 5 0 # (output of tr. conv., but pos. 5 is going to get removed as padding)
1 2 3 4 # once you removed padding, we are missing one time step !
&#34;&#34;&#34;
extra_padding = get_extra_padding_for_conv1d(x, kernel_size, stride, padding_total)
return F.pad(x, (0, extra_padding))</code></pre>
</details>
<div class="desc"><p>Pad for a convolution to make sure that the last window is full.
Extra padding is added at the end. This is required to ensure that we can rebuild
an output of the same length, as otherwise, even with padding, some time steps
might get removed.
For instance, with total padding = 4, kernel size = 4, stride = 2:
0 0 1 2 3 4 5 0 0
# (0s are padding)
1
2
3
# (output frames of a convolution, last 0 is never used)
0 0 1 2 3 4 5 0
# (output of tr. conv., but pos. 5 is going to get removed as padding)
1 2 3 4
# once you removed padding, we are missing one time step !</p></div>
</dd>
<dt id="audiocraft.modules.conv.unpad1d"><code class="name flex">
<span>def <span class="ident">unpad1d</span></span>(<span>x: torch.Tensor, paddings: Tuple[int, int])</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def unpad1d(x: torch.Tensor, paddings: tp.Tuple[int, int]):
&#34;&#34;&#34;Remove padding from x, handling properly zero padding. Only for 1d!&#34;&#34;&#34;
padding_left, padding_right = paddings
assert padding_left &gt;= 0 and padding_right &gt;= 0, (padding_left, padding_right)
assert (padding_left + padding_right) &lt;= x.shape[-1]
end = x.shape[-1] - padding_right
return x[..., padding_left: end]</code></pre>
</details>
<div class="desc"><p>Remove padding from x, handling properly zero padding. Only for 1d!</p></div>
</dd>
</dl>
</section>
<section>
<h2 class="section-title" id="header-classes">Classes</h2>
<dl>
<dt id="audiocraft.modules.conv.NormConv1d"><code class="flex name class">
<span>class <span class="ident">NormConv1d</span></span>
<span>(</span><span>*args,<br>causal: bool = False,<br>norm: str = 'none',<br>norm_kwargs: Dict[str, Any] = {},<br>**kwargs)</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class NormConv1d(nn.Module):
&#34;&#34;&#34;Wrapper around Conv1d and normalization applied to this conv
to provide a uniform interface across normalization approaches.
&#34;&#34;&#34;
def __init__(self, *args, causal: bool = False, norm: str = &#39;none&#39;,
norm_kwargs: tp.Dict[str, tp.Any] = {}, **kwargs):
super().__init__()
self.conv = apply_parametrization_norm(nn.Conv1d(*args, **kwargs), norm)
self.norm = get_norm_module(self.conv, causal, norm, **norm_kwargs)
self.norm_type = norm
def forward(self, x):
x = self.conv(x)
x = self.norm(x)
return x</code></pre>
</details>
<div class="desc"><p>Wrapper around Conv1d and normalization applied to this conv
to provide a uniform interface across normalization approaches.</p>
<p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p></div>
<h3>Ancestors</h3>
<ul class="hlist">
<li>torch.nn.modules.module.Module</li>
</ul>
<h3>Class variables</h3>
<dl>
<dt id="audiocraft.modules.conv.NormConv1d.call_super_init"><code class="name">var <span class="ident">call_super_init</span> : bool</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="audiocraft.modules.conv.NormConv1d.dump_patches"><code class="name">var <span class="ident">dump_patches</span> : bool</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="audiocraft.modules.conv.NormConv1d.training"><code class="name">var <span class="ident">training</span> : bool</code></dt>
<dd>
<div class="desc"></div>
</dd>
</dl>
<h3>Methods</h3>
<dl>
<dt id="audiocraft.modules.conv.NormConv1d.forward"><code class="name flex">
<span>def <span class="ident">forward</span></span>(<span>self, x) > Callable[..., Any]</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def forward(self, x):
x = self.conv(x)
x = self.norm(x)
return x</code></pre>
</details>
<div class="desc"><p>Defines the computation performed at every call.</p>
<p>Should be overridden by all subclasses.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Although the recipe for forward pass needs to be defined within
this function, one should call the :class:<code>Module</code> instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.</p>
</div></div>
</dd>
</dl>
</dd>
<dt id="audiocraft.modules.conv.NormConv2d"><code class="flex name class">
<span>class <span class="ident">NormConv2d</span></span>
<span>(</span><span>*args, norm: str = 'none', norm_kwargs: Dict[str, Any] = {}, **kwargs)</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class NormConv2d(nn.Module):
&#34;&#34;&#34;Wrapper around Conv2d and normalization applied to this conv
to provide a uniform interface across normalization approaches.
&#34;&#34;&#34;
def __init__(self, *args, norm: str = &#39;none&#39;, norm_kwargs: tp.Dict[str, tp.Any] = {}, **kwargs):
super().__init__()
self.conv = apply_parametrization_norm(nn.Conv2d(*args, **kwargs), norm)
self.norm = get_norm_module(self.conv, causal=False, norm=norm, **norm_kwargs)
self.norm_type = norm
def forward(self, x):
x = self.conv(x)
x = self.norm(x)
return x</code></pre>
</details>
<div class="desc"><p>Wrapper around Conv2d and normalization applied to this conv
to provide a uniform interface across normalization approaches.</p>
<p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p></div>
<h3>Ancestors</h3>
<ul class="hlist">
<li>torch.nn.modules.module.Module</li>
</ul>
<h3>Class variables</h3>
<dl>
<dt id="audiocraft.modules.conv.NormConv2d.call_super_init"><code class="name">var <span class="ident">call_super_init</span> : bool</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="audiocraft.modules.conv.NormConv2d.dump_patches"><code class="name">var <span class="ident">dump_patches</span> : bool</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="audiocraft.modules.conv.NormConv2d.training"><code class="name">var <span class="ident">training</span> : bool</code></dt>
<dd>
<div class="desc"></div>
</dd>
</dl>
<h3>Methods</h3>
<dl>
<dt id="audiocraft.modules.conv.NormConv2d.forward"><code class="name flex">
<span>def <span class="ident">forward</span></span>(<span>self, x) > Callable[..., Any]</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def forward(self, x):
x = self.conv(x)
x = self.norm(x)
return x</code></pre>
</details>
<div class="desc"><p>Defines the computation performed at every call.</p>
<p>Should be overridden by all subclasses.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Although the recipe for forward pass needs to be defined within
this function, one should call the :class:<code>Module</code> instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.</p>
</div></div>
</dd>
</dl>
</dd>
<dt id="audiocraft.modules.conv.NormConvTranspose1d"><code class="flex name class">
<span>class <span class="ident">NormConvTranspose1d</span></span>
<span>(</span><span>*args,<br>causal: bool = False,<br>norm: str = 'none',<br>norm_kwargs: Dict[str, Any] = {},<br>**kwargs)</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class NormConvTranspose1d(nn.Module):
&#34;&#34;&#34;Wrapper around ConvTranspose1d and normalization applied to this conv
to provide a uniform interface across normalization approaches.
&#34;&#34;&#34;
def __init__(self, *args, causal: bool = False, norm: str = &#39;none&#39;,
norm_kwargs: tp.Dict[str, tp.Any] = {}, **kwargs):
super().__init__()
self.convtr = apply_parametrization_norm(nn.ConvTranspose1d(*args, **kwargs), norm)
self.norm = get_norm_module(self.convtr, causal, norm, **norm_kwargs)
self.norm_type = norm
def forward(self, x):
x = self.convtr(x)
x = self.norm(x)
return x</code></pre>
</details>
<div class="desc"><p>Wrapper around ConvTranspose1d and normalization applied to this conv
to provide a uniform interface across normalization approaches.</p>
<p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p></div>
<h3>Ancestors</h3>
<ul class="hlist">
<li>torch.nn.modules.module.Module</li>
</ul>
<h3>Class variables</h3>
<dl>
<dt id="audiocraft.modules.conv.NormConvTranspose1d.call_super_init"><code class="name">var <span class="ident">call_super_init</span> : bool</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="audiocraft.modules.conv.NormConvTranspose1d.dump_patches"><code class="name">var <span class="ident">dump_patches</span> : bool</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="audiocraft.modules.conv.NormConvTranspose1d.training"><code class="name">var <span class="ident">training</span> : bool</code></dt>
<dd>
<div class="desc"></div>
</dd>
</dl>
<h3>Methods</h3>
<dl>
<dt id="audiocraft.modules.conv.NormConvTranspose1d.forward"><code class="name flex">
<span>def <span class="ident">forward</span></span>(<span>self, x) > Callable[..., Any]</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def forward(self, x):
x = self.convtr(x)
x = self.norm(x)
return x</code></pre>
</details>
<div class="desc"><p>Defines the computation performed at every call.</p>
<p>Should be overridden by all subclasses.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Although the recipe for forward pass needs to be defined within
this function, one should call the :class:<code>Module</code> instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.</p>
</div></div>
</dd>
</dl>
</dd>
<dt id="audiocraft.modules.conv.NormConvTranspose2d"><code class="flex name class">
<span>class <span class="ident">NormConvTranspose2d</span></span>
<span>(</span><span>*args, norm: str = 'none', norm_kwargs: Dict[str, Any] = {}, **kwargs)</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class NormConvTranspose2d(nn.Module):
&#34;&#34;&#34;Wrapper around ConvTranspose2d and normalization applied to this conv
to provide a uniform interface across normalization approaches.
&#34;&#34;&#34;
def __init__(self, *args, norm: str = &#39;none&#39;, norm_kwargs: tp.Dict[str, tp.Any] = {}, **kwargs):
super().__init__()
self.convtr = apply_parametrization_norm(nn.ConvTranspose2d(*args, **kwargs), norm)
self.norm = get_norm_module(self.convtr, causal=False, norm=norm, **norm_kwargs)
def forward(self, x):
x = self.convtr(x)
x = self.norm(x)
return x</code></pre>
</details>
<div class="desc"><p>Wrapper around ConvTranspose2d and normalization applied to this conv
to provide a uniform interface across normalization approaches.</p>
<p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p></div>
<h3>Ancestors</h3>
<ul class="hlist">
<li>torch.nn.modules.module.Module</li>
</ul>
<h3>Class variables</h3>
<dl>
<dt id="audiocraft.modules.conv.NormConvTranspose2d.call_super_init"><code class="name">var <span class="ident">call_super_init</span> : bool</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="audiocraft.modules.conv.NormConvTranspose2d.dump_patches"><code class="name">var <span class="ident">dump_patches</span> : bool</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="audiocraft.modules.conv.NormConvTranspose2d.training"><code class="name">var <span class="ident">training</span> : bool</code></dt>
<dd>
<div class="desc"></div>
</dd>
</dl>
<h3>Methods</h3>
<dl>
<dt id="audiocraft.modules.conv.NormConvTranspose2d.forward"><code class="name flex">
<span>def <span class="ident">forward</span></span>(<span>self, x) > Callable[..., Any]</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def forward(self, x):
x = self.convtr(x)
x = self.norm(x)
return x</code></pre>
</details>
<div class="desc"><p>Defines the computation performed at every call.</p>
<p>Should be overridden by all subclasses.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Although the recipe for forward pass needs to be defined within
this function, one should call the :class:<code>Module</code> instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.</p>
</div></div>
</dd>
</dl>
</dd>
<dt id="audiocraft.modules.conv.StreamableConv1d"><code class="flex name class">
<span>class <span class="ident">StreamableConv1d</span></span>
<span>(</span><span>in_channels: int,<br>out_channels: int,<br>kernel_size: int,<br>stride: int = 1,<br>dilation: int = 1,<br>groups: int = 1,<br>bias: bool = True,<br>causal: bool = False,<br>norm: str = 'none',<br>norm_kwargs: Dict[str, Any] = {},<br>pad_mode: str = 'reflect')</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class StreamableConv1d(nn.Module):
&#34;&#34;&#34;Conv1d with some builtin handling of asymmetric or causal padding
and normalization.
&#34;&#34;&#34;
def __init__(self, in_channels: int, out_channels: int,
kernel_size: int, stride: int = 1, dilation: int = 1,
groups: int = 1, bias: bool = True, causal: bool = False,
norm: str = &#39;none&#39;, norm_kwargs: tp.Dict[str, tp.Any] = {},
pad_mode: str = &#39;reflect&#39;):
super().__init__()
# warn user on unusual setup between dilation and stride
if stride &gt; 1 and dilation &gt; 1:
warnings.warn(&#34;StreamableConv1d has been initialized with stride &gt; 1 and dilation &gt; 1&#34;
f&#34; (kernel_size={kernel_size} stride={stride}, dilation={dilation}).&#34;)
self.conv = NormConv1d(in_channels, out_channels, kernel_size, stride,
dilation=dilation, groups=groups, bias=bias, causal=causal,
norm=norm, norm_kwargs=norm_kwargs)
self.causal = causal
self.pad_mode = pad_mode
def forward(self, x):
B, C, T = x.shape
kernel_size = self.conv.conv.kernel_size[0]
stride = self.conv.conv.stride[0]
dilation = self.conv.conv.dilation[0]
kernel_size = (kernel_size - 1) * dilation + 1 # effective kernel size with dilations
padding_total = kernel_size - stride
extra_padding = get_extra_padding_for_conv1d(x, kernel_size, stride, padding_total)
if self.causal:
# Left padding for causal
x = pad1d(x, (padding_total, extra_padding), mode=self.pad_mode)
else:
# Asymmetric padding required for odd strides
padding_right = padding_total // 2
padding_left = padding_total - padding_right
x = pad1d(x, (padding_left, padding_right + extra_padding), mode=self.pad_mode)
return self.conv(x)</code></pre>
</details>
<div class="desc"><p>Conv1d with some builtin handling of asymmetric or causal padding
and normalization.</p>
<p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p></div>
<h3>Ancestors</h3>
<ul class="hlist">
<li>torch.nn.modules.module.Module</li>
</ul>
<h3>Class variables</h3>
<dl>
<dt id="audiocraft.modules.conv.StreamableConv1d.call_super_init"><code class="name">var <span class="ident">call_super_init</span> : bool</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="audiocraft.modules.conv.StreamableConv1d.dump_patches"><code class="name">var <span class="ident">dump_patches</span> : bool</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="audiocraft.modules.conv.StreamableConv1d.training"><code class="name">var <span class="ident">training</span> : bool</code></dt>
<dd>
<div class="desc"></div>
</dd>
</dl>
<h3>Methods</h3>
<dl>
<dt id="audiocraft.modules.conv.StreamableConv1d.forward"><code class="name flex">
<span>def <span class="ident">forward</span></span>(<span>self, x) > Callable[..., Any]</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def forward(self, x):
B, C, T = x.shape
kernel_size = self.conv.conv.kernel_size[0]
stride = self.conv.conv.stride[0]
dilation = self.conv.conv.dilation[0]
kernel_size = (kernel_size - 1) * dilation + 1 # effective kernel size with dilations
padding_total = kernel_size - stride
extra_padding = get_extra_padding_for_conv1d(x, kernel_size, stride, padding_total)
if self.causal:
# Left padding for causal
x = pad1d(x, (padding_total, extra_padding), mode=self.pad_mode)
else:
# Asymmetric padding required for odd strides
padding_right = padding_total // 2
padding_left = padding_total - padding_right
x = pad1d(x, (padding_left, padding_right + extra_padding), mode=self.pad_mode)
return self.conv(x)</code></pre>
</details>
<div class="desc"><p>Defines the computation performed at every call.</p>
<p>Should be overridden by all subclasses.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Although the recipe for forward pass needs to be defined within
this function, one should call the :class:<code>Module</code> instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.</p>
</div></div>
</dd>
</dl>
</dd>
<dt id="audiocraft.modules.conv.StreamableConvTranspose1d"><code class="flex name class">
<span>class <span class="ident">StreamableConvTranspose1d</span></span>
<span>(</span><span>in_channels: int,<br>out_channels: int,<br>kernel_size: int,<br>stride: int = 1,<br>causal: bool = False,<br>norm: str = 'none',<br>trim_right_ratio: float = 1.0,<br>norm_kwargs: Dict[str, Any] = {})</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class StreamableConvTranspose1d(nn.Module):
&#34;&#34;&#34;ConvTranspose1d with some builtin handling of asymmetric or causal padding
and normalization.
&#34;&#34;&#34;
def __init__(self, in_channels: int, out_channels: int,
kernel_size: int, stride: int = 1, causal: bool = False,
norm: str = &#39;none&#39;, trim_right_ratio: float = 1.,
norm_kwargs: tp.Dict[str, tp.Any] = {}):
super().__init__()
self.convtr = NormConvTranspose1d(in_channels, out_channels, kernel_size, stride,
causal=causal, norm=norm, norm_kwargs=norm_kwargs)
self.causal = causal
self.trim_right_ratio = trim_right_ratio
assert self.causal or self.trim_right_ratio == 1., \
&#34;`trim_right_ratio` != 1.0 only makes sense for causal convolutions&#34;
assert self.trim_right_ratio &gt;= 0. and self.trim_right_ratio &lt;= 1.
def forward(self, x):
kernel_size = self.convtr.convtr.kernel_size[0]
stride = self.convtr.convtr.stride[0]
padding_total = kernel_size - stride
y = self.convtr(x)
# We will only trim fixed padding. Extra padding from `pad_for_conv1d` would be
# removed at the very end, when keeping only the right length for the output,
# as removing it here would require also passing the length at the matching layer
# in the encoder.
if self.causal:
# Trim the padding on the right according to the specified ratio
# if trim_right_ratio = 1.0, trim everything from right
padding_right = math.ceil(padding_total * self.trim_right_ratio)
padding_left = padding_total - padding_right
y = unpad1d(y, (padding_left, padding_right))
else:
# Asymmetric padding required for odd strides
padding_right = padding_total // 2
padding_left = padding_total - padding_right
y = unpad1d(y, (padding_left, padding_right))
return y</code></pre>
</details>
<div class="desc"><p>ConvTranspose1d with some builtin handling of asymmetric or causal padding
and normalization.</p>
<p>Initializes internal Module state, shared by both nn.Module and ScriptModule.</p></div>
<h3>Ancestors</h3>
<ul class="hlist">
<li>torch.nn.modules.module.Module</li>
</ul>
<h3>Class variables</h3>
<dl>
<dt id="audiocraft.modules.conv.StreamableConvTranspose1d.call_super_init"><code class="name">var <span class="ident">call_super_init</span> : bool</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="audiocraft.modules.conv.StreamableConvTranspose1d.dump_patches"><code class="name">var <span class="ident">dump_patches</span> : bool</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="audiocraft.modules.conv.StreamableConvTranspose1d.training"><code class="name">var <span class="ident">training</span> : bool</code></dt>
<dd>
<div class="desc"></div>
</dd>
</dl>
<h3>Methods</h3>
<dl>
<dt id="audiocraft.modules.conv.StreamableConvTranspose1d.forward"><code class="name flex">
<span>def <span class="ident">forward</span></span>(<span>self, x) > Callable[..., Any]</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def forward(self, x):
kernel_size = self.convtr.convtr.kernel_size[0]
stride = self.convtr.convtr.stride[0]
padding_total = kernel_size - stride
y = self.convtr(x)
# We will only trim fixed padding. Extra padding from `pad_for_conv1d` would be
# removed at the very end, when keeping only the right length for the output,
# as removing it here would require also passing the length at the matching layer
# in the encoder.
if self.causal:
# Trim the padding on the right according to the specified ratio
# if trim_right_ratio = 1.0, trim everything from right
padding_right = math.ceil(padding_total * self.trim_right_ratio)
padding_left = padding_total - padding_right
y = unpad1d(y, (padding_left, padding_right))
else:
# Asymmetric padding required for odd strides
padding_right = padding_total // 2
padding_left = padding_total - padding_right
y = unpad1d(y, (padding_left, padding_right))
return y</code></pre>
</details>
<div class="desc"><p>Defines the computation performed at every call.</p>
<p>Should be overridden by all subclasses.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Although the recipe for forward pass needs to be defined within
this function, one should call the :class:<code>Module</code> instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.</p>
</div></div>
</dd>
</dl>
</dd>
</dl>
</section>
</article>
<nav id="sidebar">
<div class="toc">
<ul></ul>
</div>
<ul id="index">
<li><h3>Super-module</h3>
<ul>
<li><code><a title="audiocraft.modules" href="index.html">audiocraft.modules</a></code></li>
</ul>
</li>
<li><h3><a href="#header-functions">Functions</a></h3>
<ul class="">
<li><code><a title="audiocraft.modules.conv.apply_parametrization_norm" href="#audiocraft.modules.conv.apply_parametrization_norm">apply_parametrization_norm</a></code></li>
<li><code><a title="audiocraft.modules.conv.get_extra_padding_for_conv1d" href="#audiocraft.modules.conv.get_extra_padding_for_conv1d">get_extra_padding_for_conv1d</a></code></li>
<li><code><a title="audiocraft.modules.conv.get_norm_module" href="#audiocraft.modules.conv.get_norm_module">get_norm_module</a></code></li>
<li><code><a title="audiocraft.modules.conv.pad1d" href="#audiocraft.modules.conv.pad1d">pad1d</a></code></li>
<li><code><a title="audiocraft.modules.conv.pad_for_conv1d" href="#audiocraft.modules.conv.pad_for_conv1d">pad_for_conv1d</a></code></li>
<li><code><a title="audiocraft.modules.conv.unpad1d" href="#audiocraft.modules.conv.unpad1d">unpad1d</a></code></li>
</ul>
</li>
<li><h3><a href="#header-classes">Classes</a></h3>
<ul>
<li>
<h4><code><a title="audiocraft.modules.conv.NormConv1d" href="#audiocraft.modules.conv.NormConv1d">NormConv1d</a></code></h4>
<ul class="">
<li><code><a title="audiocraft.modules.conv.NormConv1d.call_super_init" href="#audiocraft.modules.conv.NormConv1d.call_super_init">call_super_init</a></code></li>
<li><code><a title="audiocraft.modules.conv.NormConv1d.dump_patches" href="#audiocraft.modules.conv.NormConv1d.dump_patches">dump_patches</a></code></li>
<li><code><a title="audiocraft.modules.conv.NormConv1d.forward" href="#audiocraft.modules.conv.NormConv1d.forward">forward</a></code></li>
<li><code><a title="audiocraft.modules.conv.NormConv1d.training" href="#audiocraft.modules.conv.NormConv1d.training">training</a></code></li>
</ul>
</li>
<li>
<h4><code><a title="audiocraft.modules.conv.NormConv2d" href="#audiocraft.modules.conv.NormConv2d">NormConv2d</a></code></h4>
<ul class="">
<li><code><a title="audiocraft.modules.conv.NormConv2d.call_super_init" href="#audiocraft.modules.conv.NormConv2d.call_super_init">call_super_init</a></code></li>
<li><code><a title="audiocraft.modules.conv.NormConv2d.dump_patches" href="#audiocraft.modules.conv.NormConv2d.dump_patches">dump_patches</a></code></li>
<li><code><a title="audiocraft.modules.conv.NormConv2d.forward" href="#audiocraft.modules.conv.NormConv2d.forward">forward</a></code></li>
<li><code><a title="audiocraft.modules.conv.NormConv2d.training" href="#audiocraft.modules.conv.NormConv2d.training">training</a></code></li>
</ul>
</li>
<li>
<h4><code><a title="audiocraft.modules.conv.NormConvTranspose1d" href="#audiocraft.modules.conv.NormConvTranspose1d">NormConvTranspose1d</a></code></h4>
<ul class="">
<li><code><a title="audiocraft.modules.conv.NormConvTranspose1d.call_super_init" href="#audiocraft.modules.conv.NormConvTranspose1d.call_super_init">call_super_init</a></code></li>
<li><code><a title="audiocraft.modules.conv.NormConvTranspose1d.dump_patches" href="#audiocraft.modules.conv.NormConvTranspose1d.dump_patches">dump_patches</a></code></li>
<li><code><a title="audiocraft.modules.conv.NormConvTranspose1d.forward" href="#audiocraft.modules.conv.NormConvTranspose1d.forward">forward</a></code></li>
<li><code><a title="audiocraft.modules.conv.NormConvTranspose1d.training" href="#audiocraft.modules.conv.NormConvTranspose1d.training">training</a></code></li>
</ul>
</li>
<li>
<h4><code><a title="audiocraft.modules.conv.NormConvTranspose2d" href="#audiocraft.modules.conv.NormConvTranspose2d">NormConvTranspose2d</a></code></h4>
<ul class="">
<li><code><a title="audiocraft.modules.conv.NormConvTranspose2d.call_super_init" href="#audiocraft.modules.conv.NormConvTranspose2d.call_super_init">call_super_init</a></code></li>
<li><code><a title="audiocraft.modules.conv.NormConvTranspose2d.dump_patches" href="#audiocraft.modules.conv.NormConvTranspose2d.dump_patches">dump_patches</a></code></li>
<li><code><a title="audiocraft.modules.conv.NormConvTranspose2d.forward" href="#audiocraft.modules.conv.NormConvTranspose2d.forward">forward</a></code></li>
<li><code><a title="audiocraft.modules.conv.NormConvTranspose2d.training" href="#audiocraft.modules.conv.NormConvTranspose2d.training">training</a></code></li>
</ul>
</li>
<li>
<h4><code><a title="audiocraft.modules.conv.StreamableConv1d" href="#audiocraft.modules.conv.StreamableConv1d">StreamableConv1d</a></code></h4>
<ul class="">
<li><code><a title="audiocraft.modules.conv.StreamableConv1d.call_super_init" href="#audiocraft.modules.conv.StreamableConv1d.call_super_init">call_super_init</a></code></li>
<li><code><a title="audiocraft.modules.conv.StreamableConv1d.dump_patches" href="#audiocraft.modules.conv.StreamableConv1d.dump_patches">dump_patches</a></code></li>
<li><code><a title="audiocraft.modules.conv.StreamableConv1d.forward" href="#audiocraft.modules.conv.StreamableConv1d.forward">forward</a></code></li>
<li><code><a title="audiocraft.modules.conv.StreamableConv1d.training" href="#audiocraft.modules.conv.StreamableConv1d.training">training</a></code></li>
</ul>
</li>
<li>
<h4><code><a title="audiocraft.modules.conv.StreamableConvTranspose1d" href="#audiocraft.modules.conv.StreamableConvTranspose1d">StreamableConvTranspose1d</a></code></h4>
<ul class="">
<li><code><a title="audiocraft.modules.conv.StreamableConvTranspose1d.call_super_init" href="#audiocraft.modules.conv.StreamableConvTranspose1d.call_super_init">call_super_init</a></code></li>
<li><code><a title="audiocraft.modules.conv.StreamableConvTranspose1d.dump_patches" href="#audiocraft.modules.conv.StreamableConvTranspose1d.dump_patches">dump_patches</a></code></li>
<li><code><a title="audiocraft.modules.conv.StreamableConvTranspose1d.forward" href="#audiocraft.modules.conv.StreamableConvTranspose1d.forward">forward</a></code></li>
<li><code><a title="audiocraft.modules.conv.StreamableConvTranspose1d.training" href="#audiocraft.modules.conv.StreamableConvTranspose1d.training">training</a></code></li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
</main>
<footer id="footer">
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.11.5</a>.</p>
</footer>
</body>
</html>