forked from OpenNMT/CTranslate2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move some tokenization utilities out of TranslatorPool implementation * Move get_gpu_count to devices.h * Move random utilities to separate file * Move get_preferred_size_multiple to types utils * Move mayiuse_* functions to types utils * Move env reading utilities to separate file * Move thread affinity function to thread pool implementation * Cleanup include * Fix include
- Loading branch information
1 parent
9039af9
commit c84a826
Showing
25 changed files
with
231 additions
and
183 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
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 @@ | ||
#pragma once | ||
|
||
#include <random> | ||
|
||
namespace ctranslate2 { | ||
|
||
void set_random_seed(const unsigned int seed); | ||
unsigned int get_random_seed(); | ||
std::mt19937& get_random_generator(); | ||
|
||
} |
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
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 |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
|
||
#include <spdlog/spdlog.h> | ||
|
||
#include "ctranslate2/utils.h" | ||
#include "env.h" | ||
|
||
namespace ctranslate2 { | ||
|
||
|
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,27 @@ | ||
#include "env.h" | ||
|
||
#include <cstdlib> | ||
|
||
#include "ctranslate2/utils.h" | ||
|
||
namespace ctranslate2 { | ||
|
||
std::string read_string_from_env(const char* var, const std::string& default_value) { | ||
const char* value = std::getenv(var); | ||
if (!value) | ||
return default_value; | ||
return value; | ||
} | ||
|
||
bool read_bool_from_env(const char* var, const bool default_value) { | ||
return string_to_bool(read_string_from_env(var, default_value ? "1" : "0")); | ||
} | ||
|
||
int read_int_from_env(const char* var, const int default_value) { | ||
const std::string value = read_string_from_env(var); | ||
if (value.empty()) | ||
return default_value; | ||
return std::stoi(value); | ||
} | ||
|
||
} |
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 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
namespace ctranslate2 { | ||
|
||
std::string read_string_from_env(const char* var, const std::string& default_value = ""); | ||
bool read_bool_from_env(const char* var, const bool default_value = false); | ||
int read_int_from_env(const char* var, const int default_value = 0); | ||
|
||
} |
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,5 +1,7 @@ | ||
#include "ctranslate2/layers/transformer.h" | ||
|
||
#include <cmath> | ||
|
||
namespace ctranslate2 { | ||
namespace layers { | ||
|
||
|
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
#include "ctranslate2/ops/quantize.h" | ||
|
||
#include <cmath> | ||
|
||
#include "cpu/kernels.h" | ||
#include "cpu/parallel.h" | ||
|
||
|
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,23 @@ | ||
#include "ctranslate2/random.h" | ||
|
||
#include <atomic> | ||
|
||
namespace ctranslate2 { | ||
|
||
constexpr unsigned int default_seed = static_cast<unsigned int>(-1); | ||
static std::atomic<unsigned int> g_seed(default_seed); | ||
|
||
void set_random_seed(const unsigned int seed) { | ||
g_seed = seed; | ||
} | ||
|
||
unsigned int get_random_seed() { | ||
return g_seed == default_seed ? std::random_device{}() : g_seed.load(); | ||
} | ||
|
||
std::mt19937& get_random_generator() { | ||
static thread_local std::mt19937 generator(get_random_seed()); | ||
return generator; | ||
} | ||
|
||
} |
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
Oops, something went wrong.