-
Notifications
You must be signed in to change notification settings - Fork 726
Open
Milestone
Description
This issue collects tasks that block porting forced_align/cpu/compute.cpp and forced_align/gpu/compute.cu to use torch stable ABI.
- expose
AT_DISPATCH_FLOATING_TYPES_AND_HALF
to stable ABI, currently one need to implement the dispatch logic using switch block. Not a blocker but would be nice to have.
For a workaround example, see
audio/src/libtorchaudio/forced_align/cpu/compute.cpp
Lines 184 to 221 in b3a5a0e
switch (logProbs.scalar_type()) { case ScalarType::Double: { if (targets.scalar_type() == ScalarType::Long) { forced_align_impl<double, ScalarType::Long>(logProbs, targets, blank, paths); } else if (targets.scalar_type() == ScalarType::Int) { forced_align_impl<double, ScalarType::Int>(logProbs, targets, blank, paths); } else { STD_TORCH_CHECK(false, "unreachable"); } break; } case ScalarType::Float: { if (targets.scalar_type() == ScalarType::Long) { forced_align_impl<float, ScalarType::Long>(logProbs, targets, blank, paths); } else if (targets.scalar_type() == ScalarType::Int) { forced_align_impl<float, ScalarType::Int>(logProbs, targets, blank, paths); } else { STD_TORCH_CHECK(false, "unreachable"); } break; } case ScalarType::Half: { if (targets.scalar_type() == ScalarType::Long) { forced_align_impl<c10::Half, ScalarType::Long>(logProbs, targets, blank, paths); } else if (targets.scalar_type() == ScalarType::Int) { forced_align_impl<c10::Half, ScalarType::Int>(logProbs, targets, blank, paths); } else { STD_TORCH_CHECK(false, "unreachable"); } break; } default: { STD_TORCH_CHECK(false, "unreachable"); } }; return std::make_tuple(paths, logProbs); }
- implement
item<T>()
as atorch::stable::Tensor
template method. A workaround is implemented in
audio/src/libtorchaudio/utils.h
Lines 19 to 33 in b3a5a0e
template <typename T> T item(const torch::stable::Tensor& t) { STD_TORCH_CHECK(t.numel() == 1, "item requires single element tensor input"); if (t.is_cpu()) { return t.const_data_ptr<T>()[0]; #ifdef USE_CUDA } else if (t.is_cuda()) { T value; C10_CUDA_CHECK(cudaMemcpyAsync(&value, t.data_ptr(), sizeof(T), cudaMemcpyDeviceToHost)); return value; #endif } else { STD_TORCH_CHECK(false, "unreachable"); } }
- implement
accessor
template as atorch::stable::Tensor
template method or replace its usage. Fix available: [STABLE ABI] Add accessor template method to torch::stable::Tensor pytorch#161967 - expose
PackedTensorAccessor32
to stable ABI or replace its usage
Fix available: [STABLE ABI] Add packed_accessor32 and generic_packed_accessor template methods to torch::stable::Tensor pytorch#161897 - implement
to
as atorch::stable::Tensor
method
Workarounds: usecpu()
op from [STABLE ABI] Add cpu operation. pytorch#161911 ornew_empty
/copy_
approach as in
audio/src/libtorchaudio/forced_align/gpu/compute.cu
Lines 335 to 340 in b3a5a0e
Tensor pathsCuda = torch::stable::new_empty(paths, torchaudio::util::sizes(paths), std::nullopt, aoti_torch_device_type_cuda(), logProbs.get_device_index()); torch::stable::copy_(pathsCuda, paths);
Metadata
Metadata
Assignees
Labels
No labels