[Bugfix] Fix auto dtype casting for BatchFeature (#19316)

Signed-off-by: Isotr0py <2037008807@qq.com>
Signed-off-by: Isotr0py <mozf@mail2.sysu.edu.cn>
This commit is contained in:
Isotr0py
2025-06-14 15:13:08 +00:00
committed by GitHub
parent 6fa718a460
commit 2db9044ab6
7 changed files with 85 additions and 57 deletions
+10
View File
@@ -190,6 +190,16 @@ TORCH_DTYPE_TO_NUMPY_DTYPE = {
torch.int64: np.int64,
}
@contextlib.contextmanager
def set_default_torch_num_threads(num_threads: int):
"""Sets the default number of threads for PyTorch to the given value."""
old_num_threads = torch.get_num_threads()
torch.set_num_threads(num_threads)
yield
torch.set_num_threads(old_num_threads)
P = ParamSpec('P')
T = TypeVar("T")
U = TypeVar("U")