Skip to content

Commit 5047768

Browse files
NicolasHugpearu
andauthored
[Release 2.10] Cherry-picks (#4155)
Co-authored-by: Pearu Peterson <pearu.peterson@gmail.com>
1 parent a44357a commit 5047768

13 files changed

Lines changed: 51 additions & 31 deletions

File tree

.github/scripts/unittest-linux/run_test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ fi
2727
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MOD_unidecode=true
2828
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MOD_inflect=true
2929
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MOD_pytorch_lightning=true
30+
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MULTIGPU_CUDA=true
3031
cd test
3132
pytest torchaudio_unittest -k "not torchscript and not fairseq and not demucs ${PYTEST_K_EXTRA}"
3233
)

.github/workflows/unittest-linux-cpu.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,7 @@ jobs:
9292
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_DECODER=true
9393
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_ENCODER=true
9494
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_FFMPEG=true
95+
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MULTIGPU_CUDA=true
96+
9597
pytest test/torchaudio_unittest -k "not torchscript and not fairseq and not demucs" -x
9698
echo "::endgroup::"

.github/workflows/unittest-linux-gpu.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ jobs:
4444
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_ENCODER=true
4545
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_FFMPEG=true
4646
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MOD_demucs=true
47+
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MULTIGPU_CUDA=true
48+
4749
export CUBLAS_WORKSPACE_CONFIG=:16:8
4850
4951
# Set UPLOAD_CHANNEL

.github/workflows/unittest-macos-cpu.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ jobs:
8989
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MOD_unidecode=true
9090
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MOD_inflect=true
9191
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MOD_pytorch_lightning=true
92+
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MULTIGPU_CUDA=true
9293
9394
pytest test/torchaudio_unittest -k "not torchscript and not fairseq and not demucs and not librosa" -x
9495
echo "::endgroup::"

.github/workflows/unittest-windows-cpu.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ jobs:
5454
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MOD_inflect=true
5555
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MOD_pytorch_lightning=true
5656
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MOD_sentencepiece=true
57+
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MULTIGPU_CUDA=true
5758
5859
.github/scripts/unittest-windows/setup_env.sh
5960
.github/scripts/unittest-windows/install.sh

.github/workflows/unittest-windows-gpu.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ jobs:
5555
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MOD_inflect=true
5656
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MOD_pytorch_lightning=true
5757
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MOD_sentencepiece=true
58+
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MULTIGPU_CUDA=true
5859
5960
.github/scripts/unittest-windows/setup_env.sh
6061
.github/scripts/unittest-windows/install.sh

src/libtorchaudio/forced_align/gpu/compute.cu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ void forced_align_impl(
122122
const int64_t blank,
123123
Tensor& paths) {
124124
auto device_index = logProbs.get_device_index();
125+
const torch::stable::accelerator::DeviceGuard device_guard(device_index);
125126
auto defaultStream = libtorchaudio::cuda::getCurrentCUDAStream(device_index);
126127
auto cpuDataTranferStream = libtorchaudio::cuda::getStreamFromPool(false, device_index);
127128
const scalar_t kNegInfinity = -std::numeric_limits<scalar_t>::infinity();

src/libtorchaudio/lfilter.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ void host_lfilter_core_loop(
2424
int64_t n_samples_input = input_signal_windows.size(2);
2525
int64_t n_samples_output = padded_output_waveform.size(2);
2626
int64_t n_order = a_coeff_flipped.size(1);
27-
scalar_t* output_data =
28-
reinterpret_cast<scalar_t*>(padded_output_waveform.data_ptr());
29-
const scalar_t* input_data =
30-
reinterpret_cast<scalar_t*>(input_signal_windows.data_ptr());
27+
scalar_t* output_data = padded_output_waveform.mutable_data_ptr<scalar_t>();
28+
const scalar_t* input_data = input_signal_windows.const_data_ptr<scalar_t>();
3129
const scalar_t* a_coeff_flipped_data =
32-
reinterpret_cast<scalar_t*>(a_coeff_flipped.data_ptr());
30+
a_coeff_flipped.const_data_ptr<scalar_t>();
3331

3432
torch::stable::parallel_for(
3533
0, n_channel * n_batch, 1, [&](int64_t begin, int64_t end) {

src/libtorchaudio/rnnt/cpu/compute.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include <libtorchaudio/rnnt/cpu/cpu_transducer.h>
2+
#include <libtorchaudio/utils.h>
3+
24
#include <torch/csrc/stable/library.h>
35
#include <torch/csrc/stable/ops.h>
46
#include <torch/csrc/stable/tensor.h>
@@ -73,15 +75,11 @@ std::tuple<Tensor, Tensor> compute(
7375
STD_TORCH_CHECK(
7476
blank >= 0 && blank < logits.size(-1),
7577
"blank must be within [0, logits.shape[-1])");
76-
77-
auto max_ivalue = [](const Tensor& t) {
78-
return reinterpret_cast<int32_t*>(torch::stable::amax(t, {}).data_ptr())[0];
79-
};
80-
8178
STD_TORCH_CHECK(
82-
logits.size(1) == max_ivalue(logit_lengths), "input length mismatch");
79+
logits.size(1) == torchaudio::util::max<int64_t>(logit_lengths),
80+
"input length mismatch");
8381
STD_TORCH_CHECK(
84-
logits.size(2) == max_ivalue(target_lengths) + 1,
82+
logits.size(2) == torchaudio::util::max<int64_t>(target_lengths) + 1,
8583
"output length mismatch");
8684
STD_TORCH_CHECK(
8785
targets.size(1) + 1 == logits.size(2), "target length mismatch");
@@ -110,14 +108,12 @@ std::tuple<Tensor, Tensor> compute(
110108
{DtypeWorkspace<float>::ComputeSizeFromOptions(options)},
111109
ScalarType::Float);
112110

113-
// TODO: use t.mutable_data_ptr<..>() instead of reinterpret_cast
114-
// when stable ABI Tensor supports mutable_data_ptr templates.
115111
Workspace<float> workspace(
116112
/*options=*/options,
117113
/*dtype_data=*/
118-
reinterpret_cast<float*>(float_workspace.mutable_data_ptr()),
114+
float_workspace.mutable_data_ptr<float>(),
119115
/*dtype_size=*/float_workspace.numel(),
120-
/*int_data=*/reinterpret_cast<int*>(int_workspace.mutable_data_ptr()),
116+
/*int_data=*/int_workspace.mutable_data_ptr<int>(),
121117
/*int_size=*/int_workspace.numel());
122118

123119
THO_DISPATCH_V2(
@@ -126,12 +122,12 @@ std::tuple<Tensor, Tensor> compute(
126122
AT_WRAP([&] {
127123
(Compute</*DTYPE=*/scalar_t, /*CAST_DTYPE=*/float>(
128124
/*workspace=*/workspace,
129-
/*logits=*/reinterpret_cast<scalar_t*>(logits.data_ptr()),
130-
/*targets=*/reinterpret_cast<int*>(targets.data_ptr()),
131-
/*srcLengths=*/reinterpret_cast<int*>(logit_lengths.data_ptr()),
132-
/*tgtLengths=*/reinterpret_cast<int*>(target_lengths.data_ptr()),
133-
/*costs=*/reinterpret_cast<scalar_t*>(costs.data_ptr()),
134-
/*gradients=*/reinterpret_cast<scalar_t*>(gradients.data_ptr())));
125+
/*logits=*/logits.const_data_ptr<scalar_t>(),
126+
/*targets=*/targets.const_data_ptr<int>(),
127+
/*srcLengths=*/logit_lengths.const_data_ptr<int>(),
128+
/*tgtLengths=*/target_lengths.const_data_ptr<int>(),
129+
/*costs=*/costs.mutable_data_ptr<scalar_t>(),
130+
/*gradients=*/gradients.mutable_data_ptr<scalar_t>()));
135131
}),
136132
ScalarType::Float,
137133
ScalarType::Half);

src/libtorchaudio/rnnt/gpu/compute.cu

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ std::tuple<Tensor, Tensor> compute(
106106

107107
Workspace<float> workspace(
108108
/*options=*/options,
109-
/*dtype_data=*/reinterpret_cast<float*>(float_workspace.data_ptr()),
109+
/*dtype_data=*/float_workspace.mutable_data_ptr<float>(),
110110
/*dtype_size=*/float_workspace.numel(),
111-
/*int_data=*/reinterpret_cast<int*>(int_workspace.data_ptr()),
111+
/*int_data=*/int_workspace.mutable_data_ptr<int>(),
112112
/*int_size=*/int_workspace.numel());
113113

114114
THO_DISPATCH_V2(
@@ -117,12 +117,12 @@ std::tuple<Tensor, Tensor> compute(
117117
AT_WRAP([&] {
118118
(Compute</*DTYPE=*/scalar_t, /*CAST_DTYPE=*/float>(
119119
/*workspace=*/workspace,
120-
/*logits=*/reinterpret_cast<scalar_t*>(logits.data_ptr()),
121-
/*targets=*/reinterpret_cast<int*>(targets.data_ptr()),
122-
/*srcLengths=*/reinterpret_cast<int*>(logit_lengths.data_ptr()),
123-
/*tgtLengths=*/reinterpret_cast<int*>(target_lengths.data_ptr()),
124-
/*costs=*/reinterpret_cast<scalar_t*>(costs.data_ptr()),
125-
/*gradients=*/reinterpret_cast<scalar_t*>(gradients.data_ptr())));
120+
/*logits=*/logits.const_data_ptr<scalar_t>(),
121+
/*targets=*/targets.const_data_ptr<int>(),
122+
/*srcLengths=*/logit_lengths.const_data_ptr<int>(),
123+
/*tgtLengths=*/target_lengths.const_data_ptr<int>(),
124+
/*costs=*/costs.mutable_data_ptr<scalar_t>(),
125+
/*gradients=*/gradients.mutable_data_ptr<scalar_t>()));
126126
}),
127127
ScalarType::Float,
128128
ScalarType::Half);

0 commit comments

Comments
 (0)