Skip to content

Commit 3042d5f

Browse files
committed
fix
1 parent 5be4440 commit 3042d5f

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

RELEASENOTES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@ __Breaking Changes__:
88

99
__API Changes__:
1010

11+
- A new option `autoDispose` has been added into `DataLoader`s, which indicates whether to dispose the collated tensors before the next iteration.
12+
- The default collate functions will now always dispose the intermediate tensors, rather than wait for the next iteration.
13+
- A new abstract method `DisposeTensor` has been added to `Dataset<>`s.
14+
- This method will be used by `DataLoader`, to dispose the values provided by `GetTensor`.
15+
- `Dataset` and `IterableDataset` has implemented this method, so if your dataset is inherited from them, please check whether the disposal should be avoided in your case.
16+
1117
__Bug Fixes__:
1218

19+
- `TensorDataset` will now keep the aliases, detached from dispose scopes, to avoid the unexpected disposal.
1320

1421
# NuGet Version 0.102.4
1522

src/TorchAudio/Datasets/SpeechCommandsDataset.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ internal SpeechCommandsDataset(string path, string subset)
4848

4949
public override long Count => _walker.LongLength;
5050

51+
public override void DisposeTensor(SpeechCommandsDatasetItem tensor)
52+
{
53+
tensor.waveform.Dispose();
54+
}
55+
5156
public override SpeechCommandsDatasetItem GetTensor(long index)
5257
{
5358
var audioPath = _walker[index];

src/TorchAudio/Datasets/YesnoDataset.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public YesnoDataset(string directoryPathInArchive)
2222

2323
public override long Count => audioPathList.LongLength;
2424

25+
public override void DisposeTensor(YesnoDatasetItem tensor)
26+
{
27+
tensor.waveform.Dispose();
28+
}
29+
2530
public override YesnoDatasetItem GetTensor(long index)
2631
{
2732
var (waveform, sample_rate) = torchaudio.load(audioPathList[index]);

src/TorchSharp/Utils/TensorDataset.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ internal TensorDataset(torch.Tensor[] tensors)
3737
long size1 = tensors[0].shape[0];
3838
if (!tensors.All(t => t.shape[0] == size1)) throw new ArgumentException("All tensors must have the same first dimension size.", nameof(tensors));
3939

40-
_tensors = tensors.Select(x => x.alias()).ToArray();
40+
_tensors = tensors.Select(x => x.alias().DetachFromDisposeScope()).ToArray();
4141
}
4242

4343
/// <summary>

0 commit comments

Comments
 (0)