Print layers and their indices during training initialization.

This commit is contained in:
Tomasz Sobczyk
2020-10-24 10:52:49 +02:00
committed by nodchip
parent 3bf397a569
commit be3937c37b
8 changed files with 152 additions and 51 deletions

View File

@@ -71,6 +71,12 @@ namespace Eval::NNUE {
",Network=" + Network::get_structure_string();
}
std::string get_layers_info() {
return
FeatureTransformer::get_layers_info()
+ '\n' + Network::get_layers_info();
}
UseNNUEMode useNNUE;
std::string eval_file_loaded = "None";

View File

@@ -81,6 +81,8 @@ namespace Eval::NNUE {
// Get a string that represents the structure of the evaluation function
std::string get_architecture_string();
std::string get_layers_info();
// read the header
bool read_header(std::istream& stream,
std::uint32_t* hash_value, std::string* architecture);

View File

@@ -58,6 +58,13 @@ namespace Eval::NNUE {
std::cout << "Initializing NN training for "
<< get_architecture_string() << std::endl;
std::cout << std::endl;
std::cout << "Layers:\n"
<< get_layers_info() << std::endl;
std::cout << std::endl;
assert(feature_transformer);
assert(network);
trainer = Trainer<Network>::create(network.get(), feature_transformer.get());

View File

@@ -57,6 +57,8 @@ namespace Eval::NNUE::Layers {
static constexpr std::size_t kBufferSize =
PreviousLayer::kBufferSize + kSelfBufferSize;
static constexpr int kLayerIndex = PreviousLayer::kLayerIndex + 1;
// Hash value embedded in the evaluation file
static constexpr std::uint32_t get_hash_value() {
std::uint32_t hash_value = 0xCC03DAE4u;
@@ -66,14 +68,27 @@ namespace Eval::NNUE::Layers {
return hash_value;
}
// A string that represents the structure from the input layer to this layer
static std::string get_structure_string() {
static std::string get_name() {
return "AffineTransform[" +
std::to_string(kOutputDimensions) + "<-" +
std::to_string(kInputDimensions) + "](" +
std::to_string(kInputDimensions) + "]";
}
// A string that represents the structure from the input layer to this layer
static std::string get_structure_string() {
return get_name() + "(" +
PreviousLayer::get_structure_string() + ")";
}
static std::string get_layers_info() {
std::string info = PreviousLayer::get_layers_info();
info += '\n';
info += std::to_string(kLayerIndex);
info += ": ";
info += get_name();
return info;
}
// Read network parameters
bool read_parameters(std::istream& stream) {
if (!previous_layer_.read_parameters(stream))

View File

@@ -54,6 +54,8 @@ namespace Eval::NNUE::Layers {
static constexpr std::size_t kBufferSize =
PreviousLayer::kBufferSize + kSelfBufferSize;
static constexpr int kLayerIndex = PreviousLayer::kLayerIndex + 1;
// Hash value embedded in the evaluation file
static constexpr std::uint32_t get_hash_value() {
std::uint32_t hash_value = 0x538D24C7u;
@@ -61,13 +63,26 @@ namespace Eval::NNUE::Layers {
return hash_value;
}
static std::string get_name() {
return "ClippedReLU[" +
std::to_string(kOutputDimensions) + "]";
}
// A string that represents the structure from the input layer to this layer
static std::string get_structure_string() {
return "ClippedReLU[" +
std::to_string(kOutputDimensions) + "](" +
return get_name() + "(" +
PreviousLayer::get_structure_string() + ")";
}
static std::string get_layers_info() {
std::string info = PreviousLayer::get_layers_info();
info += '\n';
info += std::to_string(kLayerIndex);
info += ": ";
info += get_name();
return info;
}
// Read network parameters
bool read_parameters(std::istream& stream) {
return previous_layer_.read_parameters(stream);

View File

@@ -28,56 +28,69 @@
namespace Eval::NNUE::Layers {
// Input layer
template <IndexType OutputDimensions, IndexType Offset = 0>
class InputSlice {
public:
// Need to maintain alignment
static_assert(Offset % kMaxSimdWidth == 0, "");
// Input layer
template <IndexType OutputDimensions, IndexType Offset = 0>
class InputSlice {
public:
// Need to maintain alignment
static_assert(Offset % kMaxSimdWidth == 0, "");
// Output type
using OutputType = TransformedFeatureType;
// Output type
using OutputType = TransformedFeatureType;
// Output dimensionality
static constexpr IndexType kOutputDimensions = OutputDimensions;
// Output dimensionality
static constexpr IndexType kOutputDimensions = OutputDimensions;
// Size of forward propagation buffer used from the input layer to this layer
static constexpr std::size_t kBufferSize = 0;
// Size of forward propagation buffer used from the input layer to this layer
static constexpr std::size_t kBufferSize = 0;
// Hash value embedded in the evaluation file
static constexpr std::uint32_t get_hash_value() {
std::uint32_t hash_value = 0xEC42E90Du;
hash_value ^= kOutputDimensions ^ (Offset << 10);
return hash_value;
}
static constexpr int kLayerIndex = 1;
// A string that represents the structure from the input layer to this layer
static std::string get_structure_string() {
return "InputSlice[" + std::to_string(kOutputDimensions) + "(" +
std::to_string(Offset) + ":" +
std::to_string(Offset + kOutputDimensions) + ")]";
}
// Hash value embedded in the evaluation file
static constexpr std::uint32_t get_hash_value() {
std::uint32_t hash_value = 0xEC42E90Du;
hash_value ^= kOutputDimensions ^ (Offset << 10);
return hash_value;
}
// Read network parameters
bool read_parameters(std::istream& /*stream*/) {
return true;
}
static std::string get_name() {
return "InputSlice[" + std::to_string(kOutputDimensions) + "(" +
std::to_string(Offset) + ":" +
std::to_string(Offset + kOutputDimensions) + ")]";
}
// write parameters
bool write_parameters(std::ostream& /*stream*/) const {
return true;
}
// A string that represents the structure from the input layer to this layer
static std::string get_structure_string() {
return get_name();
}
// Forward propagation
const OutputType* propagate(
const TransformedFeatureType* transformed_features,
char* /*buffer*/) const {
static std::string get_layers_info() {
std::string info = std::to_string(kLayerIndex);
info += ": ";
info += get_name();
return info;
}
return transformed_features + Offset;
}
// Read network parameters
bool read_parameters(std::istream& /*stream*/) {
return true;
}
private:
};
// write parameters
bool write_parameters(std::ostream& /*stream*/) const {
return true;
}
// Forward propagation
const OutputType* propagate(
const TransformedFeatureType* transformed_features,
char* /*buffer*/) const {
return transformed_features + Offset;
}
private:
};
} // namespace Layers

View File

@@ -36,6 +36,8 @@ namespace Eval::NNUE::Layers {
static constexpr std::size_t kBufferSize =
std::max(Head::kBufferSize + kSelfBufferSize, Tail::kBufferSize);
static constexpr int kLayerIndex = Tail::kLayerIndex + 1;
// Hash value embedded in the evaluation function file
static constexpr std::uint32_t get_hash_value() {
std::uint32_t hash_value = 0xBCE400B4u;
@@ -46,10 +48,23 @@ namespace Eval::NNUE::Layers {
return hash_value;
}
static std::string get_name() {
return "Sum[" +
std::to_string(kOutputDimensions) + "]";
}
// A string that represents the structure from the input layer to this layer
static std::string get_structure_string() {
return "Sum[" +
std::to_string(kOutputDimensions) + "](" + get_summands_string() + ")";
return get_name() + "(" + get_summands_string() + ")";
}
static std::string get_layers_info() {
std::string info = Tail::get_layers_info();
info += '\n';
info += std::to_string(kLayerIndex);
info += ": ";
info += get_name();
return info;
}
// read parameters
@@ -117,6 +132,8 @@ namespace Eval::NNUE::Layers {
// Size of the forward propagation buffer used from the input layer to this layer
static constexpr std::size_t kBufferSize = PreviousLayer::kBufferSize;
static constexpr int kLayerIndex = PreviousLayer::kLayerIndex + 1;
// Hash value embedded in the evaluation function file
static constexpr std::uint32_t get_hash_value() {
std::uint32_t hash_value = 0xBCE400B4u;
@@ -125,10 +142,23 @@ namespace Eval::NNUE::Layers {
return hash_value;
}
static std::string get_name() {
return "Sum[" +
std::to_string(kOutputDimensions) + "]";
}
// A string that represents the structure from the input layer to this layer
static std::string get_structure_string() {
return "Sum[" +
std::to_string(kOutputDimensions) + "](" + get_summands_string() + ")";
return get_name() + "(" + get_summands_string() + ")";
}
static std::string get_layers_info() {
std::string info = PreviousLayer::get_layers_info();
info += '\n';
info += std::to_string(kLayerIndex);
info += ": ";
info += get_name();
return info;
}
// read parameters

View File

@@ -110,19 +110,32 @@ namespace Eval::NNUE {
static constexpr std::size_t kBufferSize =
kOutputDimensions * sizeof(OutputType);
static constexpr int kLayerIndex = 0;
// Hash value embedded in the evaluation file
static constexpr std::uint32_t get_hash_value() {
return RawFeatures::kHashValue ^ kOutputDimensions;
}
// a string representing the structure
static std::string get_structure_string() {
static std::string get_name() {
return RawFeatures::get_name() + "[" +
std::to_string(kInputDimensions) + "->" +
std::to_string(kHalfDimensions) + "x2]";
}
// a string representing the structure
static std::string get_structure_string() {
return get_name();
}
static std::string get_layers_info() {
std::string info = std::to_string(kLayerIndex);
info += ": ";
info += get_name();
return info;
}
// Read network parameters
bool read_parameters(std::istream& stream) {