-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'smalton/DOR-535-compat-lib' into 'master'
DOR-535: Compatibility lib Closes DOR-535 See merge request machine-learning/dorado!818
- Loading branch information
Showing
13 changed files
with
84 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
add_library(dorado_compat | ||
compat_utils.cpp | ||
compat_utils.h | ||
) | ||
|
||
target_include_directories(dorado_compat | ||
INTERFACE | ||
${CMAKE_CURRENT_SOURCE_DIR}/.. | ||
) | ||
|
||
enable_warnings_as_errors(dorado_compat) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "torch_utils.h" | ||
|
||
#include "compat/compat_utils.h" | ||
|
||
#if DORADO_CUDA_BUILD | ||
#include <c10/cuda/CUDACachingAllocator.h> | ||
#endif | ||
#include <torch/torch.h> | ||
|
||
namespace dorado::utils { | ||
|
||
void make_torch_deterministic() { | ||
#if DORADO_CUDA_BUILD | ||
setenv("CUBLAS_WORKSPACE_CONFIG", ":4096:8", true); | ||
torch::globalContext().setDeterministicCuDNN(true); | ||
torch::globalContext().setBenchmarkCuDNN(false); | ||
#endif | ||
|
||
#if TORCH_VERSION_MAJOR > 1 || TORCH_VERSION_MINOR >= 11 | ||
torch::globalContext().setDeterministicAlgorithms(true, false); | ||
#else | ||
torch::globalContext().setDeterministicAlgorithms(true); | ||
#endif | ||
} | ||
|
||
void set_torch_allocator_max_split_size() { | ||
#if DORADO_CUDA_BUILD && TORCH_VERSION_MAJOR >= 2 | ||
|
||
// Do not re-use smaller chunks of large buffers | ||
// This prevents small allocations from reusing large sections of cached allocated memory | ||
// which can lead to OoM errors when the original large allocation is needed again | ||
auto max_split_size_mb = 25; | ||
std::string settings = "max_split_size_mb:" + std::to_string(max_split_size_mb); | ||
|
||
const char *pytorch_cuda_alloc_conf = std::getenv("PYTORCH_CUDA_ALLOC_CONF"); | ||
if (pytorch_cuda_alloc_conf != nullptr) { | ||
std::string_view str(pytorch_cuda_alloc_conf); | ||
if (str.find("max_split_size_mb") != std::string::npos) { | ||
// user has set this via env_var - let torch parse and use their value | ||
return; | ||
} | ||
settings += std::string(",") + pytorch_cuda_alloc_conf; | ||
} | ||
|
||
c10::cuda::CUDACachingAllocator::setAllocatorSettings(settings); | ||
#endif | ||
} | ||
|
||
} // namespace dorado::utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,8 @@ | ||
#pragma once | ||
|
||
#include "compat_utils.h" | ||
|
||
#if DORADO_CUDA_BUILD | ||
#include <c10/cuda/CUDACachingAllocator.h> | ||
#endif | ||
#include <torch/torch.h> | ||
|
||
namespace dorado::utils { | ||
|
||
inline void make_torch_deterministic() { | ||
#if DORADO_CUDA_BUILD | ||
setenv("CUBLAS_WORKSPACE_CONFIG", ":4096:8", true); | ||
torch::globalContext().setDeterministicCuDNN(true); | ||
torch::globalContext().setBenchmarkCuDNN(false); | ||
#endif | ||
|
||
#if TORCH_VERSION_MAJOR > 1 || TORCH_VERSION_MINOR >= 11 | ||
torch::globalContext().setDeterministicAlgorithms(true, false); | ||
#else | ||
torch::globalContext().setDeterministicAlgorithms(true); | ||
#endif | ||
} | ||
|
||
inline void set_torch_allocator_max_split_size() { | ||
#if DORADO_CUDA_BUILD && TORCH_VERSION_MAJOR >= 2 | ||
|
||
// Do not re-use smaller chunks of large buffers | ||
// This prevents small allocations from reusing large sections of cached allocated memory | ||
// which can lead to OoM errors when the original large allocation is needed again | ||
auto max_split_size_mb = 25; | ||
std::string settings = "max_split_size_mb:" + std::to_string(max_split_size_mb); | ||
|
||
const char *pytorch_cuda_alloc_conf = std::getenv("PYTORCH_CUDA_ALLOC_CONF"); | ||
if (pytorch_cuda_alloc_conf != nullptr) { | ||
std::string_view str(pytorch_cuda_alloc_conf); | ||
if (str.find("max_split_size_mb") != std::string::npos) { | ||
// user has set this via env_var - let torch parse and use their value | ||
return; | ||
} | ||
settings += std::string(",") + pytorch_cuda_alloc_conf; | ||
} | ||
|
||
c10::cuda::CUDACachingAllocator::setAllocatorSettings(settings); | ||
#endif | ||
} | ||
void make_torch_deterministic(); | ||
void set_torch_allocator_max_split_size(); | ||
|
||
} // namespace dorado::utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters