Skip to content

Commit 95d4347

Browse files
authored
Merge pull request #1 from NiklasGustafsson/unit
from NiklasGustafsson/Unit to yueyinqiu2/munit
2 parents b66289b + f231d0a commit 95d4347

22 files changed

+446
-151
lines changed

RELEASENOTES.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,36 @@
22

33
Releases, starting with 9/2/2021, are listed with the most recent release at the top.
44

5+
# NuGet Version 0.102.5
6+
7+
__Breaking Changes__:
8+
9+
__API Changes__:
10+
11+
__Bug Fixes__:
12+
13+
14+
# NuGet Version 0.102.4
15+
16+
__Breaking Changes__:
17+
18+
Correct `torch.finfo`. (`torch.set_default_dtype`, `Categorical.entropy`, `_CorrCholesky.check`, `Distribution.ClampProbs`, `FisherSnedecor.rsample`, `Gamma.rsample`, `Geometric.rsample`, `distributions.Gumbel`, `Laplace.rsample`, `SigmoidTransform._call` and `SigmoidTransform._inverse` are influenced.)<br/>
19+
20+
__API Changes__:
21+
22+
#1284 make `torch.unique` and `torch.unique_consecutive` public.<br/>
23+
524
# NuGet Version 0.102.3
625

26+
__Breaking Changes__:
27+
28+
The 'paddingMode' parameter of convolution has been changed to 'padding_mode', and the 'outputPadding' is now 'output_padding'.
29+
730
__API Changes__:
831

932
#1243 `fuse_conv_bn_weights` and `fuse_linear_bn_weights` are added.<br/>
33+
#1274 ConvTranspose3d does not accept non-uniform kernelSize/stride values<br/>
34+
1035

1136
# NuGet Version 0.102.2
1237

build/BranchInfo.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<MajorVersion>0</MajorVersion>
44
<MinorVersion>102</MinorVersion>
5-
<PatchVersion>3</PatchVersion>
5+
<PatchVersion>5</PatchVersion>
66
</PropertyGroup>
77

88
</Project>

src/Examples.Utils/Examples.Utils.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<ItemGroup>
1919
<PackageReference Include="SharpZipLib" Version="1.4.0" />
20-
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.3" />
20+
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.4" />
2121
</ItemGroup>
2222

2323
<ItemGroup>

src/Native/LibTorchSharp/THSConvolution.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,31 @@ NNModule THSNN_ConvTranspose2d_ctor(const int64_t inputChannel, const int64_t ou
278278
);
279279
}
280280

281+
NNModule THSNN_ConvTranspose2d_ctor_1(const int64_t inputChannel, const int64_t outputChannel,
282+
const int64_t kernelX, const int64_t kernelY,
283+
const int64_t strideX, const int64_t strideY,
284+
const int64_t paddingX, const int64_t paddingY,
285+
const int64_t output_paddingX, const int64_t output_paddingY,
286+
const int64_t dilationX, const int64_t dilationY,
287+
const int64_t paddingMode, const int64_t groups, const bool bias,
288+
NNAnyModule* outAsAnyModule)
289+
{
290+
auto padd = torch::ExpandingArray<2>({ paddingX, paddingY });
291+
292+
CATCH_RETURN_NNModule(
293+
auto opts = torch::nn::ConvTranspose2dOptions(inputChannel, outputChannel, { kernelX, kernelY })
294+
.stride({ strideX, strideY })
295+
.padding(padd)
296+
.dilation({ dilationX, dilationY })
297+
.groups(groups)
298+
.bias(bias)
299+
.output_padding({ output_paddingX, output_paddingY });
300+
ApplyPaddingMode(opts, paddingMode);
301+
302+
res = create_module<torch::nn::ConvTranspose2dImpl>(opts, outAsAnyModule);
303+
);
304+
}
305+
281306
Tensor THSNN_ConvTranspose2d_forward(const NNModule module, const Tensor tensor)
282307
{
283308
CATCH_TENSOR((*module)->as<torch::nn::ConvTranspose2d>()->forward(*tensor));
@@ -322,6 +347,31 @@ NNModule THSNN_ConvTranspose3d_ctor(const int64_t inputChannel, const int64_t ou
322347
);
323348
}
324349

350+
NNModule THSNN_ConvTranspose3d_ctor_1(const int64_t inputChannel, const int64_t outputChannel,
351+
const int64_t kernelX, const int64_t kernelY, const int64_t kernelZ,
352+
const int64_t strideX, const int64_t strideY, const int64_t strideZ,
353+
const int64_t paddingX, const int64_t paddingY, const int64_t paddingZ,
354+
const int64_t output_paddingX, const int64_t output_paddingY, const int64_t output_paddingZ,
355+
const int64_t dilationX, const int64_t dilationY, const int64_t dilationZ,
356+
const int64_t paddingMode, const int64_t groups, const bool bias,
357+
NNAnyModule* outAsAnyModule)
358+
{
359+
auto padd = torch::ExpandingArray<3>({ paddingX, paddingY, paddingZ });
360+
361+
CATCH_RETURN_NNModule(
362+
auto opts = torch::nn::ConvTranspose3dOptions(inputChannel, outputChannel, { kernelX, kernelY, kernelZ })
363+
.stride({ strideX, strideY, strideZ })
364+
.padding(padd)
365+
.dilation({ dilationX, dilationY, dilationZ })
366+
.groups(groups)
367+
.bias(bias)
368+
.output_padding({output_paddingX, output_paddingY, output_paddingZ});
369+
ApplyPaddingMode(opts, paddingMode);
370+
371+
res = create_module<torch::nn::ConvTranspose3dImpl>(opts, outAsAnyModule);
372+
);
373+
}
374+
325375
Tensor THSNN_ConvTranspose3d_bias(const NNModule module)
326376
{
327377
return get_bias<torch::nn::ConvTranspose3d>(module);

src/Native/LibTorchSharp/THSNN.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ EXPORT_API(void) THSNN_ConvTranspose1d_set_bias(const NNModule module, const
6767
EXPORT_API(Tensor) THSNN_ConvTranspose1d_weight(const NNModule module);
6868
EXPORT_API(void) THSNN_ConvTranspose1d_set_weight(const NNModule module, const Tensor weight);
6969
EXPORT_API(NNModule) THSNN_ConvTranspose2d_ctor(const int64_t inputChannel, const int64_t outputChannel, const int64_t kernelSize, const int64_t stride, const int64_t padding, const int64_t output_padding, const int64_t dilation, const int64_t paddingMode, const int64_t groups, const bool bias, NNAnyModule* outAsAnyModule);
70+
EXPORT_API(NNModule) THSNN_ConvTranspose2d_ctor_1(const int64_t inputChannel, const int64_t outputChannel, const int64_t kernelX, const int64_t kernelY, const int64_t strideX, const int64_t strideY, const int64_t paddingX, const int64_t paddingY, const int64_t output_paddingX, const int64_t output_paddingY, const int64_t dilationX, const int64_t dilationY, const int64_t paddingMode, const int64_t groups, const bool bias, NNAnyModule* outAsAnyModule);
7071
EXPORT_API(Tensor) THSNN_ConvTranspose2d_forward(const NNModule module, const Tensor tensor);
7172
EXPORT_API(Tensor) THSNN_ConvTranspose2d_weight(const NNModule module);
7273
EXPORT_API(void) THSNN_ConvTranspose2d_set_weight(const NNModule module, const Tensor weight);
7374
EXPORT_API(Tensor) THSNN_ConvTranspose2d_bias(const NNModule module);
7475
EXPORT_API(void) THSNN_ConvTranspose2d_set_bias(const NNModule module, const Tensor bias);
7576
EXPORT_API(NNModule) THSNN_ConvTranspose3d_ctor(const int64_t inputChannel, const int64_t outputChannel, const int64_t kernelSize, const int64_t stride, const int64_t padding, const int64_t output_padding, const int64_t dilation, const int64_t paddingMode, const int64_t groups, const bool bias, NNAnyModule* outAsAnyModule);
77+
EXPORT_API(NNModule) THSNN_ConvTranspose3d_ctor_1(const int64_t inputChannel, const int64_t outputChannel, const int64_t kernelX, const int64_t kernelY, const int64_t kernelZ, const int64_t strideX, const int64_t strideY, const int64_t strideZ, const int64_t paddingX, const int64_t paddingY, const int64_t paddingZ, const int64_t output_paddingX, const int64_t output_paddingY, const int64_t output_paddingZ, const int64_t dilationX, const int64_t dilationY, const int64_t dilationZ, const int64_t paddingMode, const int64_t groups, const bool bias, NNAnyModule* outAsAnyModule);
7678
EXPORT_API(Tensor) THSNN_ConvTranspose3d_forward(const NNModule module, const Tensor tensor);
7779
EXPORT_API(Tensor) THSNN_ConvTranspose3d_weight(const NNModule module);
7880
EXPORT_API(void) THSNN_ConvTranspose3d_set_weight(const NNModule module, const Tensor weight);

src/Python/exportsd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _write_tensor(t, stream):
3737
stream.write(leb128.u.encode(len(t.shape)))
3838
for s in t.shape:
3939
stream.write(leb128.u.encode(s))
40-
stream.write(t.numpy().tobytes())
40+
stream.write(t.detach().cpu().numpy().tobytes())
4141

4242
def write_tensor(t, file_name):
4343
f = open(file_name, "wb")

src/TorchAudio/Modules/Wav2Vec2Components.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ public ConvLayerBlock(
9696
this.stride = stride;
9797
this.layer_norm = layer_norm;
9898
this.conv = nn.Conv1d(
99-
inputChannel: in_channels,
100-
outputChannel: out_channels,
99+
in_channels: in_channels,
100+
out_channels: out_channels,
101101
kernelSize: kernel_size,
102102
stride: stride,
103103
bias: bias);

src/TorchAudio/Modules/WaveRNN.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ protected override void Dispose(bool disposing)
248248
public ResBlock(string name, int n_freq = 128) : base(name)
249249
{
250250
this.resblock_model = nn.Sequential(
251-
nn.Conv1d(inputChannel: n_freq, outputChannel: n_freq, kernelSize: 1, bias: false),
251+
nn.Conv1d(in_channels: n_freq, out_channels: n_freq, kernelSize: 1, bias: false),
252252
nn.BatchNorm1d(n_freq),
253253
nn.ReLU(inplace: true),
254-
nn.Conv1d(inputChannel: n_freq, outputChannel: n_freq, kernelSize: 1, bias: false),
254+
nn.Conv1d(in_channels: n_freq, out_channels: n_freq, kernelSize: 1, bias: false),
255255
nn.BatchNorm1d(n_freq));
256256
RegisterComponents();
257257
}
@@ -283,13 +283,13 @@ public MelResNet(
283283
int kernel_size = 5) : base(name)
284284
{
285285
var modules = new List<nn.Module<Tensor, Tensor>>();
286-
modules.Add(nn.Conv1d(inputChannel: n_freq, outputChannel: n_hidden, kernelSize: kernel_size, bias: false));
286+
modules.Add(nn.Conv1d(in_channels: n_freq, out_channels: n_hidden, kernelSize: kernel_size, bias: false));
287287
modules.Add(nn.BatchNorm1d(n_hidden));
288288
modules.Add(nn.ReLU(inplace: true));
289289
for (int i = 0; i < n_res_block; i++) {
290290
modules.Add(new ResBlock("resblock", n_hidden));
291291
}
292-
modules.Add(nn.Conv1d(inputChannel: n_hidden, outputChannel: n_output, kernelSize: 1));
292+
modules.Add(nn.Conv1d(in_channels: n_hidden, out_channels: n_output, kernelSize: 1));
293293
this.melresnet_model = nn.Sequential(modules);
294294
RegisterComponents();
295295
}
@@ -358,7 +358,7 @@ public UpsampleNetwork(
358358
var up_layers = new List<nn.Module<Tensor, Tensor>>();
359359
foreach (var scale in upsample_scales) {
360360
var stretch = new Stretch2d("stretch2d", scale, 1);
361-
var conv = nn.Conv2d(inputChannel: 1, outputChannel: 1, kernelSize: (1, scale * 2 + 1), padding: (0, scale), bias: false);
361+
var conv = nn.Conv2d(in_channels: 1, out_channels: 1, kernelSize: (1, scale * 2 + 1), padding: (0, scale), bias: false);
362362
torch.nn.init.constant_(conv.weight, 1.0 / (scale * 2 + 1));
363363
up_layers.Add(stretch);
364364
up_layers.Add(conv);

src/TorchSharp/NN/Convolution/Conv1D.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,45 +97,45 @@ public static partial class nn
9797
/// <summary>
9898
/// Applies a 1D convolution over an input signal composed of several input planes.
9999
/// </summary>
100-
/// <param name="inputChannel">Number of channels in the input image</param>
101-
/// <param name="outputChannel">Number of channels produced by the convolution</param>
100+
/// <param name="in_channels">Number of channels in the input image</param>
101+
/// <param name="out_channels">Number of channels produced by the convolution</param>
102102
/// <param name="kernelSize">Size of the convolving kernel</param>
103103
/// <param name="stride">Stride of the convolution. Default: 1</param>
104104
/// <param name="padding">Zero-padding added to both sides of the input. Default: 0</param>
105105
/// <param name="dilation">Spacing between kernel elements. Default: 1</param>
106-
/// <param name="paddingMode">'zeros', 'reflect', 'replicate' or 'circular'. Default: 'zeros'</param>
106+
/// <param name="padding_mode">'zeros', 'reflect', 'replicate' or 'circular'. Default: 'zeros'</param>
107107
/// <param name="groups">Number of blocked connections from input channels to output channels. Default: 1</param>
108108
/// <param name="bias">If true, adds a learnable bias to the output. Default: true</param>
109109
/// <param name="device">The desired device of the parameters and buffers in this module</param>
110110
/// <param name="dtype">The desired floating point or complex dtype of the parameters and buffers in this module</param>
111111
/// <returns>Tensor of shape (N,C_out,L_out)</returns>
112-
public static Conv1d Conv1d(long inputChannel, long outputChannel, long kernelSize, long stride = 1, long padding = 0, long dilation = 1, PaddingModes paddingMode = PaddingModes.Zeros, long groups = 1, bool bias = true, Device? device = null, ScalarType? dtype = null)
112+
public static Conv1d Conv1d(long in_channels, long out_channels, long kernelSize, long stride = 1, long padding = 0, long dilation = 1, PaddingModes padding_mode = PaddingModes.Zeros, long groups = 1, bool bias = true, Device? device = null, ScalarType? dtype = null)
113113
{
114-
var res = THSNN_Conv1d_ctor(inputChannel, outputChannel, kernelSize, stride, padding, dilation, (long)paddingMode, groups, bias, out var boxedHandle);
114+
var res = THSNN_Conv1d_ctor(in_channels, out_channels, kernelSize, stride, padding, dilation, (long)padding_mode, groups, bias, out var boxedHandle);
115115
if (res == IntPtr.Zero) { torch.CheckForErrors(); }
116-
return new Conv1d(res, boxedHandle, inputChannel).MoveModule<Conv1d>(device, dtype);
116+
return new Conv1d(res, boxedHandle, in_channels).MoveModule<Conv1d>(device, dtype);
117117
}
118118

119119
/// <summary>
120120
/// Applies a 1D convolution over an input signal composed of several input planes.
121121
/// </summary>
122-
/// <param name="inputChannel">Number of channels in the input image</param>
123-
/// <param name="outputChannel">Number of channels produced by the convolution</param>
122+
/// <param name="in_channels">Number of channels in the input image</param>
123+
/// <param name="out_channels">Number of channels produced by the convolution</param>
124124
/// <param name="kernelSize">Size of the convolving kernel</param>
125125
/// <param name="stride">Stride of the convolution. Default: 1</param>
126126
/// <param name="padding">Zero-padding added to both sides of the input. padding=Valid is the same as no padding. padding=Same pads the input so the output has the shape as the input. </param>
127127
/// <param name="dilation">Spacing between kernel elements. Default: 1</param>
128-
/// <param name="paddingMode">'zeros', 'reflect', 'replicate' or 'circular'. Default: 'zeros'</param>
128+
/// <param name="padding_mode">'zeros', 'reflect', 'replicate' or 'circular'. Default: 'zeros'</param>
129129
/// <param name="groups">Number of blocked connections from input channels to output channels. Default: 1</param>
130130
/// <param name="bias">If true, adds a learnable bias to the output. Default: true</param>
131131
/// <param name="device">The desired device of the parameters and buffers in this module</param>
132132
/// <param name="dtype">The desired floating point or complex dtype of the parameters and buffers in this module</param>
133133
/// <returns>Tensor of shape (N,C_out,L_out)</returns>
134-
public static Conv1d Conv1d(long inputChannel, long outputChannel, long kernelSize, Padding padding, long stride = 1, long dilation = 1, PaddingModes paddingMode = PaddingModes.Zeros, long groups = 1, bool bias = true, Device? device = null, ScalarType? dtype = null)
134+
public static Conv1d Conv1d(long in_channels, long out_channels, long kernelSize, Padding padding, long stride = 1, long dilation = 1, PaddingModes padding_mode = PaddingModes.Zeros, long groups = 1, bool bias = true, Device? device = null, ScalarType? dtype = null)
135135
{
136-
var res = THSNN_Conv1d_ctor(inputChannel, outputChannel, kernelSize, stride, padding == Padding.Valid ? 0 : -1, dilation, (long)paddingMode, groups, bias, out var boxedHandle);
136+
var res = THSNN_Conv1d_ctor(in_channels, out_channels, kernelSize, stride, padding == Padding.Valid ? 0 : -1, dilation, (long)padding_mode, groups, bias, out var boxedHandle);
137137
if (res == IntPtr.Zero) { torch.CheckForErrors(); }
138-
return new Conv1d(res, boxedHandle, inputChannel).MoveModule<Conv1d>(device, dtype);
138+
return new Conv1d(res, boxedHandle, in_channels).MoveModule<Conv1d>(device, dtype);
139139
}
140140

141141
public static partial class functional

0 commit comments

Comments
 (0)