项目文件夹

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

630 行
37 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.seanet 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.seanet</code></h1>
</header>
<section id="section-intro">
</section>
<section>
</section>
<section>
</section>
<section>
</section>
<section>
<h2 class="section-title" id="header-classes">Classes</h2>
<dl>
<dt id="audiocraft.modules.seanet.SEANetDecoder"><code class="flex name class">
<span>class <span class="ident">SEANetDecoder</span></span>
<span>(</span><span>channels: int = 1,<br>dimension: int = 128,<br>n_filters: int = 32,<br>n_residual_layers: int = 3,<br>ratios: List[int] = [8, 5, 4, 2],<br>activation: str = 'ELU',<br>activation_params: dict = {'alpha': 1.0},<br>final_activation: str | None = None,<br>final_activation_params: dict | None = None,<br>norm: str = 'none',<br>norm_params: Dict[str, Any] = {},<br>kernel_size: int = 7,<br>last_kernel_size: int = 7,<br>residual_kernel_size: int = 3,<br>dilation_base: int = 2,<br>causal: bool = False,<br>pad_mode: str = 'reflect',<br>true_skip: bool = True,<br>compress: int = 2,<br>lstm: int = 0,<br>disable_norm_outer_blocks: int = 0,<br>trim_right_ratio: float = 1.0)</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class SEANetDecoder(nn.Module):
&#34;&#34;&#34;SEANet decoder.
Args:
channels (int): Audio channels.
dimension (int): Intermediate representation dimension.
n_filters (int): Base width for the model.
n_residual_layers (int): nb of residual layers.
ratios (Sequence[int]): kernel size and stride ratios.
activation (str): Activation function.
activation_params (dict): Parameters to provide to the activation function.
final_activation (str): Final activation function after all convolutions.
final_activation_params (dict): Parameters to provide to the activation function.
norm (str): Normalization method.
norm_params (dict): Parameters to provide to the underlying normalization used along with the convolution.
kernel_size (int): Kernel size for the initial convolution.
last_kernel_size (int): Kernel size for the initial convolution.
residual_kernel_size (int): Kernel size for the residual layers.
dilation_base (int): How much to increase the dilation with each layer.
causal (bool): Whether to use fully causal convolution.
pad_mode (str): Padding mode for the convolutions.
true_skip (bool): Whether to use true skip connection or a simple.
(streamable) convolution as the skip connection in the residual network blocks.
compress (int): Reduced dimensionality in residual branches (from Demucs v3).
lstm (int): Number of LSTM layers at the end of the encoder.
disable_norm_outer_blocks (int): Number of blocks for which we don&#39;t apply norm.
For the decoder, it corresponds to the N last blocks.
trim_right_ratio (float): Ratio for trimming at the right of the transposed convolution under the causal setup.
If equal to 1.0, it means that all the trimming is done at the right.
&#34;&#34;&#34;
def __init__(self, channels: int = 1, dimension: int = 128, n_filters: int = 32, n_residual_layers: int = 3,
ratios: tp.List[int] = [8, 5, 4, 2], activation: str = &#39;ELU&#39;, activation_params: dict = {&#39;alpha&#39;: 1.0},
final_activation: tp.Optional[str] = None, final_activation_params: tp.Optional[dict] = None,
norm: str = &#39;none&#39;, norm_params: tp.Dict[str, tp.Any] = {}, kernel_size: int = 7,
last_kernel_size: int = 7, residual_kernel_size: int = 3, dilation_base: int = 2, causal: bool = False,
pad_mode: str = &#39;reflect&#39;, true_skip: bool = True, compress: int = 2, lstm: int = 0,
disable_norm_outer_blocks: int = 0, trim_right_ratio: float = 1.0):
super().__init__()
self.dimension = dimension
self.channels = channels
self.n_filters = n_filters
self.ratios = ratios
del ratios
self.n_residual_layers = n_residual_layers
self.hop_length = np.prod(self.ratios)
self.n_blocks = len(self.ratios) + 2 # first and last conv + residual blocks
self.disable_norm_outer_blocks = disable_norm_outer_blocks
assert self.disable_norm_outer_blocks &gt;= 0 and self.disable_norm_outer_blocks &lt;= self.n_blocks, \
&#34;Number of blocks for which to disable norm is invalid.&#34; \
&#34;It should be lower or equal to the actual number of blocks in the network and greater or equal to 0.&#34;
act = getattr(nn, activation)
mult = int(2 ** len(self.ratios))
model: tp.List[nn.Module] = [
StreamableConv1d(dimension, mult * n_filters, kernel_size,
norm=&#39;none&#39; if self.disable_norm_outer_blocks == self.n_blocks else norm,
norm_kwargs=norm_params, causal=causal, pad_mode=pad_mode)
]
if lstm:
model += [StreamableLSTM(mult * n_filters, num_layers=lstm)]
# Upsample to raw audio scale
for i, ratio in enumerate(self.ratios):
block_norm = &#39;none&#39; if self.disable_norm_outer_blocks &gt;= self.n_blocks - (i + 1) else norm
# Add upsampling layers
model += [
act(**activation_params),
StreamableConvTranspose1d(mult * n_filters, mult * n_filters // 2,
kernel_size=ratio * 2, stride=ratio,
norm=block_norm, norm_kwargs=norm_params,
causal=causal, trim_right_ratio=trim_right_ratio),
]
# Add residual layers
for j in range(n_residual_layers):
model += [
SEANetResnetBlock(mult * n_filters // 2, kernel_sizes=[residual_kernel_size, 1],
dilations=[dilation_base ** j, 1],
activation=activation, activation_params=activation_params,
norm=block_norm, norm_params=norm_params, causal=causal,
pad_mode=pad_mode, compress=compress, true_skip=true_skip)]
mult //= 2
# Add final layers
model += [
act(**activation_params),
StreamableConv1d(n_filters, channels, last_kernel_size,
norm=&#39;none&#39; if self.disable_norm_outer_blocks &gt;= 1 else norm,
norm_kwargs=norm_params, causal=causal, pad_mode=pad_mode)
]
# Add optional final activation to decoder (eg. tanh)
if final_activation is not None:
final_act = getattr(nn, final_activation)
final_activation_params = final_activation_params or {}
model += [
final_act(**final_activation_params)
]
self.model = nn.Sequential(*model)
def forward(self, z):
y = self.model(z)
return y</code></pre>
</details>
<div class="desc"><p>SEANet decoder.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>channels</code></strong> :&ensp;<code>int</code></dt>
<dd>Audio channels.</dd>
<dt><strong><code>dimension</code></strong> :&ensp;<code>int</code></dt>
<dd>Intermediate representation dimension.</dd>
<dt><strong><code>n_filters</code></strong> :&ensp;<code>int</code></dt>
<dd>Base width for the model.</dd>
<dt><strong><code>n_residual_layers</code></strong> :&ensp;<code>int</code></dt>
<dd>nb of residual layers.</dd>
<dt><strong><code>ratios</code></strong> :&ensp;<code>Sequence[int]</code></dt>
<dd>kernel size and stride ratios.</dd>
<dt><strong><code>activation</code></strong> :&ensp;<code>str</code></dt>
<dd>Activation function.</dd>
<dt><strong><code>activation_params</code></strong> :&ensp;<code>dict</code></dt>
<dd>Parameters to provide to the activation function.</dd>
<dt><strong><code>final_activation</code></strong> :&ensp;<code>str</code></dt>
<dd>Final activation function after all convolutions.</dd>
<dt><strong><code>final_activation_params</code></strong> :&ensp;<code>dict</code></dt>
<dd>Parameters to provide to the activation function.</dd>
<dt><strong><code>norm</code></strong> :&ensp;<code>str</code></dt>
<dd>Normalization method.</dd>
<dt><strong><code>norm_params</code></strong> :&ensp;<code>dict</code></dt>
<dd>Parameters to provide to the underlying normalization used along with the convolution.</dd>
<dt><strong><code>kernel_size</code></strong> :&ensp;<code>int</code></dt>
<dd>Kernel size for the initial convolution.</dd>
<dt><strong><code>last_kernel_size</code></strong> :&ensp;<code>int</code></dt>
<dd>Kernel size for the initial convolution.</dd>
<dt><strong><code>residual_kernel_size</code></strong> :&ensp;<code>int</code></dt>
<dd>Kernel size for the residual layers.</dd>
<dt><strong><code>dilation_base</code></strong> :&ensp;<code>int</code></dt>
<dd>How much to increase the dilation with each layer.</dd>
<dt><strong><code>causal</code></strong> :&ensp;<code>bool</code></dt>
<dd>Whether to use fully causal convolution.</dd>
<dt><strong><code>pad_mode</code></strong> :&ensp;<code>str</code></dt>
<dd>Padding mode for the convolutions.</dd>
<dt><strong><code>true_skip</code></strong> :&ensp;<code>bool</code></dt>
<dd>Whether to use true skip connection or a simple.
(streamable) convolution as the skip connection in the residual network blocks.</dd>
<dt><strong><code>compress</code></strong> :&ensp;<code>int</code></dt>
<dd>Reduced dimensionality in residual branches (from Demucs v3).</dd>
<dt><strong><code>lstm</code></strong> :&ensp;<code>int</code></dt>
<dd>Number of LSTM layers at the end of the encoder.</dd>
<dt><strong><code>disable_norm_outer_blocks</code></strong> :&ensp;<code>int</code></dt>
<dd>Number of blocks for which we don't apply norm.
For the decoder, it corresponds to the N last blocks.</dd>
<dt><strong><code>trim_right_ratio</code></strong> :&ensp;<code>float</code></dt>
<dd>Ratio for trimming at the right of the transposed convolution under the causal setup.
If equal to 1.0, it means that all the trimming is done at the right.</dd>
</dl>
<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.seanet.SEANetDecoder.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.seanet.SEANetDecoder.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.seanet.SEANetDecoder.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.seanet.SEANetDecoder.forward"><code class="name flex">
<span>def <span class="ident">forward</span></span>(<span>self, z) > Callable[..., Any]</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def forward(self, z):
y = self.model(z)
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>
<dt id="audiocraft.modules.seanet.SEANetEncoder"><code class="flex name class">
<span>class <span class="ident">SEANetEncoder</span></span>
<span>(</span><span>channels: int = 1,<br>dimension: int = 128,<br>n_filters: int = 32,<br>n_residual_layers: int = 3,<br>ratios: List[int] = [8, 5, 4, 2],<br>activation: str = 'ELU',<br>activation_params: dict = {'alpha': 1.0},<br>norm: str = 'none',<br>norm_params: Dict[str, Any] = {},<br>kernel_size: int = 7,<br>last_kernel_size: int = 7,<br>residual_kernel_size: int = 3,<br>dilation_base: int = 2,<br>causal: bool = False,<br>pad_mode: str = 'reflect',<br>true_skip: bool = True,<br>compress: int = 2,<br>lstm: int = 0,<br>disable_norm_outer_blocks: int = 0)</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class SEANetEncoder(nn.Module):
&#34;&#34;&#34;SEANet encoder.
Args:
channels (int): Audio channels.
dimension (int): Intermediate representation dimension.
n_filters (int): Base width for the model.
n_residual_layers (int): nb of residual layers.
ratios (Sequence[int]): kernel size and stride ratios. The encoder uses downsampling ratios instead of
upsampling ratios, hence it will use the ratios in the reverse order to the ones specified here
that must match the decoder order. We use the decoder order as some models may only employ the decoder.
activation (str): Activation function.
activation_params (dict): Parameters to provide to the activation function.
norm (str): Normalization method.
norm_params (dict): Parameters to provide to the underlying normalization used along with the convolution.
kernel_size (int): Kernel size for the initial convolution.
last_kernel_size (int): Kernel size for the initial convolution.
residual_kernel_size (int): Kernel size for the residual layers.
dilation_base (int): How much to increase the dilation with each layer.
causal (bool): Whether to use fully causal convolution.
pad_mode (str): Padding mode for the convolutions.
true_skip (bool): Whether to use true skip connection or a simple
(streamable) convolution as the skip connection in the residual network blocks.
compress (int): Reduced dimensionality in residual branches (from Demucs v3).
lstm (int): Number of LSTM layers at the end of the encoder.
disable_norm_outer_blocks (int): Number of blocks for which we don&#39;t apply norm.
For the encoder, it corresponds to the N first blocks.
&#34;&#34;&#34;
def __init__(self, channels: int = 1, dimension: int = 128, n_filters: int = 32, n_residual_layers: int = 3,
ratios: tp.List[int] = [8, 5, 4, 2], activation: str = &#39;ELU&#39;, activation_params: dict = {&#39;alpha&#39;: 1.0},
norm: str = &#39;none&#39;, norm_params: tp.Dict[str, tp.Any] = {}, kernel_size: int = 7,
last_kernel_size: int = 7, residual_kernel_size: int = 3, dilation_base: int = 2, causal: bool = False,
pad_mode: str = &#39;reflect&#39;, true_skip: bool = True, compress: int = 2, lstm: int = 0,
disable_norm_outer_blocks: int = 0):
super().__init__()
self.channels = channels
self.dimension = dimension
self.n_filters = n_filters
self.ratios = list(reversed(ratios))
del ratios
self.n_residual_layers = n_residual_layers
self.hop_length = np.prod(self.ratios)
self.n_blocks = len(self.ratios) + 2 # first and last conv + residual blocks
self.disable_norm_outer_blocks = disable_norm_outer_blocks
assert self.disable_norm_outer_blocks &gt;= 0 and self.disable_norm_outer_blocks &lt;= self.n_blocks, \
&#34;Number of blocks for which to disable norm is invalid.&#34; \
&#34;It should be lower or equal to the actual number of blocks in the network and greater or equal to 0.&#34;
act = getattr(nn, activation)
mult = 1
model: tp.List[nn.Module] = [
StreamableConv1d(channels, mult * n_filters, kernel_size,
norm=&#39;none&#39; if self.disable_norm_outer_blocks &gt;= 1 else norm,
norm_kwargs=norm_params, causal=causal, pad_mode=pad_mode)
]
# Downsample to raw audio scale
for i, ratio in enumerate(self.ratios):
block_norm = &#39;none&#39; if self.disable_norm_outer_blocks &gt;= i + 2 else norm
# Add residual layers
for j in range(n_residual_layers):
model += [
SEANetResnetBlock(mult * n_filters, kernel_sizes=[residual_kernel_size, 1],
dilations=[dilation_base ** j, 1],
norm=block_norm, norm_params=norm_params,
activation=activation, activation_params=activation_params,
causal=causal, pad_mode=pad_mode, compress=compress, true_skip=true_skip)]
# Add downsampling layers
model += [
act(**activation_params),
StreamableConv1d(mult * n_filters, mult * n_filters * 2,
kernel_size=ratio * 2, stride=ratio,
norm=block_norm, norm_kwargs=norm_params,
causal=causal, pad_mode=pad_mode),
]
mult *= 2
if lstm:
model += [StreamableLSTM(mult * n_filters, num_layers=lstm)]
model += [
act(**activation_params),
StreamableConv1d(mult * n_filters, dimension, last_kernel_size,
norm=&#39;none&#39; if self.disable_norm_outer_blocks == self.n_blocks else norm,
norm_kwargs=norm_params, causal=causal, pad_mode=pad_mode)
]
self.model = nn.Sequential(*model)
def forward(self, x):
return self.model(x)</code></pre>
</details>
<div class="desc"><p>SEANet encoder.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>channels</code></strong> :&ensp;<code>int</code></dt>
<dd>Audio channels.</dd>
<dt><strong><code>dimension</code></strong> :&ensp;<code>int</code></dt>
<dd>Intermediate representation dimension.</dd>
<dt><strong><code>n_filters</code></strong> :&ensp;<code>int</code></dt>
<dd>Base width for the model.</dd>
<dt><strong><code>n_residual_layers</code></strong> :&ensp;<code>int</code></dt>
<dd>nb of residual layers.</dd>
<dt><strong><code>ratios</code></strong> :&ensp;<code>Sequence[int]</code></dt>
<dd>kernel size and stride ratios. The encoder uses downsampling ratios instead of
upsampling ratios, hence it will use the ratios in the reverse order to the ones specified here
that must match the decoder order. We use the decoder order as some models may only employ the decoder.</dd>
<dt><strong><code>activation</code></strong> :&ensp;<code>str</code></dt>
<dd>Activation function.</dd>
<dt><strong><code>activation_params</code></strong> :&ensp;<code>dict</code></dt>
<dd>Parameters to provide to the activation function.</dd>
<dt><strong><code>norm</code></strong> :&ensp;<code>str</code></dt>
<dd>Normalization method.</dd>
<dt><strong><code>norm_params</code></strong> :&ensp;<code>dict</code></dt>
<dd>Parameters to provide to the underlying normalization used along with the convolution.</dd>
<dt><strong><code>kernel_size</code></strong> :&ensp;<code>int</code></dt>
<dd>Kernel size for the initial convolution.</dd>
<dt><strong><code>last_kernel_size</code></strong> :&ensp;<code>int</code></dt>
<dd>Kernel size for the initial convolution.</dd>
<dt><strong><code>residual_kernel_size</code></strong> :&ensp;<code>int</code></dt>
<dd>Kernel size for the residual layers.</dd>
<dt><strong><code>dilation_base</code></strong> :&ensp;<code>int</code></dt>
<dd>How much to increase the dilation with each layer.</dd>
<dt><strong><code>causal</code></strong> :&ensp;<code>bool</code></dt>
<dd>Whether to use fully causal convolution.</dd>
<dt><strong><code>pad_mode</code></strong> :&ensp;<code>str</code></dt>
<dd>Padding mode for the convolutions.</dd>
<dt><strong><code>true_skip</code></strong> :&ensp;<code>bool</code></dt>
<dd>Whether to use true skip connection or a simple
(streamable) convolution as the skip connection in the residual network blocks.</dd>
<dt><strong><code>compress</code></strong> :&ensp;<code>int</code></dt>
<dd>Reduced dimensionality in residual branches (from Demucs v3).</dd>
<dt><strong><code>lstm</code></strong> :&ensp;<code>int</code></dt>
<dd>Number of LSTM layers at the end of the encoder.</dd>
<dt><strong><code>disable_norm_outer_blocks</code></strong> :&ensp;<code>int</code></dt>
<dd>Number of blocks for which we don't apply norm.
For the encoder, it corresponds to the N first blocks.</dd>
</dl>
<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.seanet.SEANetEncoder.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.seanet.SEANetEncoder.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.seanet.SEANetEncoder.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.seanet.SEANetEncoder.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):
return self.model(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.seanet.SEANetResnetBlock"><code class="flex name class">
<span>class <span class="ident">SEANetResnetBlock</span></span>
<span>(</span><span>dim: int,<br>kernel_sizes: List[int] = [3, 1],<br>dilations: List[int] = [1, 1],<br>activation: str = 'ELU',<br>activation_params: dict = {'alpha': 1.0},<br>norm: str = 'none',<br>norm_params: Dict[str, Any] = {},<br>causal: bool = False,<br>pad_mode: str = 'reflect',<br>compress: int = 2,<br>true_skip: bool = True)</span>
</code></dt>
<dd>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class SEANetResnetBlock(nn.Module):
&#34;&#34;&#34;Residual block from SEANet model.
Args:
dim (int): Dimension of the input/output.
kernel_sizes (list): List of kernel sizes for the convolutions.
dilations (list): List of dilations for the convolutions.
activation (str): Activation function.
activation_params (dict): Parameters to provide to the activation function.
norm (str): Normalization method.
norm_params (dict): Parameters to provide to the underlying normalization used along with the convolution.
causal (bool): Whether to use fully causal convolution.
pad_mode (str): Padding mode for the convolutions.
compress (int): Reduced dimensionality in residual branches (from Demucs v3).
true_skip (bool): Whether to use true skip connection or a simple
(streamable) convolution as the skip connection.
&#34;&#34;&#34;
def __init__(self, dim: int, kernel_sizes: tp.List[int] = [3, 1], dilations: tp.List[int] = [1, 1],
activation: str = &#39;ELU&#39;, activation_params: dict = {&#39;alpha&#39;: 1.0},
norm: str = &#39;none&#39;, norm_params: tp.Dict[str, tp.Any] = {}, causal: bool = False,
pad_mode: str = &#39;reflect&#39;, compress: int = 2, true_skip: bool = True):
super().__init__()
assert len(kernel_sizes) == len(dilations), &#39;Number of kernel sizes should match number of dilations&#39;
act = getattr(nn, activation)
hidden = dim // compress
block = []
for i, (kernel_size, dilation) in enumerate(zip(kernel_sizes, dilations)):
in_chs = dim if i == 0 else hidden
out_chs = dim if i == len(kernel_sizes) - 1 else hidden
block += [
act(**activation_params),
StreamableConv1d(in_chs, out_chs, kernel_size=kernel_size, dilation=dilation,
norm=norm, norm_kwargs=norm_params,
causal=causal, pad_mode=pad_mode),
]
self.block = nn.Sequential(*block)
self.shortcut: nn.Module
if true_skip:
self.shortcut = nn.Identity()
else:
self.shortcut = StreamableConv1d(dim, dim, kernel_size=1, norm=norm, norm_kwargs=norm_params,
causal=causal, pad_mode=pad_mode)
def forward(self, x):
return self.shortcut(x) + self.block(x)</code></pre>
</details>
<div class="desc"><p>Residual block from SEANet model.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>dim</code></strong> :&ensp;<code>int</code></dt>
<dd>Dimension of the input/output.</dd>
<dt><strong><code>kernel_sizes</code></strong> :&ensp;<code>list</code></dt>
<dd>List of kernel sizes for the convolutions.</dd>
<dt><strong><code>dilations</code></strong> :&ensp;<code>list</code></dt>
<dd>List of dilations for the convolutions.</dd>
<dt><strong><code>activation</code></strong> :&ensp;<code>str</code></dt>
<dd>Activation function.</dd>
<dt><strong><code>activation_params</code></strong> :&ensp;<code>dict</code></dt>
<dd>Parameters to provide to the activation function.</dd>
<dt><strong><code>norm</code></strong> :&ensp;<code>str</code></dt>
<dd>Normalization method.</dd>
<dt><strong><code>norm_params</code></strong> :&ensp;<code>dict</code></dt>
<dd>Parameters to provide to the underlying normalization used along with the convolution.</dd>
<dt><strong><code>causal</code></strong> :&ensp;<code>bool</code></dt>
<dd>Whether to use fully causal convolution.</dd>
<dt><strong><code>pad_mode</code></strong> :&ensp;<code>str</code></dt>
<dd>Padding mode for the convolutions.</dd>
<dt><strong><code>compress</code></strong> :&ensp;<code>int</code></dt>
<dd>Reduced dimensionality in residual branches (from Demucs v3).</dd>
<dt><strong><code>true_skip</code></strong> :&ensp;<code>bool</code></dt>
<dd>Whether to use true skip connection or a simple
(streamable) convolution as the skip connection.</dd>
</dl>
<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.seanet.SEANetResnetBlock.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.seanet.SEANetResnetBlock.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.seanet.SEANetResnetBlock.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.seanet.SEANetResnetBlock.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):
return self.shortcut(x) + self.block(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>
</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-classes">Classes</a></h3>
<ul>
<li>
<h4><code><a title="audiocraft.modules.seanet.SEANetDecoder" href="#audiocraft.modules.seanet.SEANetDecoder">SEANetDecoder</a></code></h4>
<ul class="">
<li><code><a title="audiocraft.modules.seanet.SEANetDecoder.call_super_init" href="#audiocraft.modules.seanet.SEANetDecoder.call_super_init">call_super_init</a></code></li>
<li><code><a title="audiocraft.modules.seanet.SEANetDecoder.dump_patches" href="#audiocraft.modules.seanet.SEANetDecoder.dump_patches">dump_patches</a></code></li>
<li><code><a title="audiocraft.modules.seanet.SEANetDecoder.forward" href="#audiocraft.modules.seanet.SEANetDecoder.forward">forward</a></code></li>
<li><code><a title="audiocraft.modules.seanet.SEANetDecoder.training" href="#audiocraft.modules.seanet.SEANetDecoder.training">training</a></code></li>
</ul>
</li>
<li>
<h4><code><a title="audiocraft.modules.seanet.SEANetEncoder" href="#audiocraft.modules.seanet.SEANetEncoder">SEANetEncoder</a></code></h4>
<ul class="">
<li><code><a title="audiocraft.modules.seanet.SEANetEncoder.call_super_init" href="#audiocraft.modules.seanet.SEANetEncoder.call_super_init">call_super_init</a></code></li>
<li><code><a title="audiocraft.modules.seanet.SEANetEncoder.dump_patches" href="#audiocraft.modules.seanet.SEANetEncoder.dump_patches">dump_patches</a></code></li>
<li><code><a title="audiocraft.modules.seanet.SEANetEncoder.forward" href="#audiocraft.modules.seanet.SEANetEncoder.forward">forward</a></code></li>
<li><code><a title="audiocraft.modules.seanet.SEANetEncoder.training" href="#audiocraft.modules.seanet.SEANetEncoder.training">training</a></code></li>
</ul>
</li>
<li>
<h4><code><a title="audiocraft.modules.seanet.SEANetResnetBlock" href="#audiocraft.modules.seanet.SEANetResnetBlock">SEANetResnetBlock</a></code></h4>
<ul class="">
<li><code><a title="audiocraft.modules.seanet.SEANetResnetBlock.call_super_init" href="#audiocraft.modules.seanet.SEANetResnetBlock.call_super_init">call_super_init</a></code></li>
<li><code><a title="audiocraft.modules.seanet.SEANetResnetBlock.dump_patches" href="#audiocraft.modules.seanet.SEANetResnetBlock.dump_patches">dump_patches</a></code></li>
<li><code><a title="audiocraft.modules.seanet.SEANetResnetBlock.forward" href="#audiocraft.modules.seanet.SEANetResnetBlock.forward">forward</a></code></li>
<li><code><a title="audiocraft.modules.seanet.SEANetResnetBlock.training" href="#audiocraft.modules.seanet.SEANetResnetBlock.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>