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
+6
View File
@@ -71,6 +71,12 @@ namespace Eval::NNUE {
",Network=" + Network::get_structure_string(); ",Network=" + Network::get_structure_string();
} }
std::string get_layers_info() {
return
FeatureTransformer::get_layers_info()
+ '\n' + Network::get_layers_info();
}
UseNNUEMode useNNUE; UseNNUEMode useNNUE;
std::string eval_file_loaded = "None"; std::string eval_file_loaded = "None";
+2
View File
@@ -81,6 +81,8 @@ namespace Eval::NNUE {
// Get a string that represents the structure of the evaluation function // Get a string that represents the structure of the evaluation function
std::string get_architecture_string(); std::string get_architecture_string();
std::string get_layers_info();
// read the header // read the header
bool read_header(std::istream& stream, bool read_header(std::istream& stream,
std::uint32_t* hash_value, std::string* architecture); std::uint32_t* hash_value, std::string* architecture);
+7
View File
@@ -58,6 +58,13 @@ namespace Eval::NNUE {
std::cout << "Initializing NN training for " std::cout << "Initializing NN training for "
<< get_architecture_string() << std::endl; << 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(feature_transformer);
assert(network); assert(network);
trainer = Trainer<Network>::create(network.get(), feature_transformer.get()); trainer = Trainer<Network>::create(network.get(), feature_transformer.get());
+18 -3
View File
@@ -57,6 +57,8 @@ namespace Eval::NNUE::Layers {
static constexpr std::size_t kBufferSize = static constexpr std::size_t kBufferSize =
PreviousLayer::kBufferSize + kSelfBufferSize; PreviousLayer::kBufferSize + kSelfBufferSize;
static constexpr int kLayerIndex = PreviousLayer::kLayerIndex + 1;
// Hash value embedded in the evaluation file // Hash value embedded in the evaluation file
static constexpr std::uint32_t get_hash_value() { static constexpr std::uint32_t get_hash_value() {
std::uint32_t hash_value = 0xCC03DAE4u; std::uint32_t hash_value = 0xCC03DAE4u;
@@ -66,14 +68,27 @@ namespace Eval::NNUE::Layers {
return hash_value; return hash_value;
} }
// A string that represents the structure from the input layer to this layer static std::string get_name() {
static std::string get_structure_string() {
return "AffineTransform[" + return "AffineTransform[" +
std::to_string(kOutputDimensions) + "<-" + 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() + ")"; 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 // Read network parameters
bool read_parameters(std::istream& stream) { bool read_parameters(std::istream& stream) {
if (!previous_layer_.read_parameters(stream)) if (!previous_layer_.read_parameters(stream))
+17 -2
View File
@@ -54,6 +54,8 @@ namespace Eval::NNUE::Layers {
static constexpr std::size_t kBufferSize = static constexpr std::size_t kBufferSize =
PreviousLayer::kBufferSize + kSelfBufferSize; PreviousLayer::kBufferSize + kSelfBufferSize;
static constexpr int kLayerIndex = PreviousLayer::kLayerIndex + 1;
// Hash value embedded in the evaluation file // Hash value embedded in the evaluation file
static constexpr std::uint32_t get_hash_value() { static constexpr std::uint32_t get_hash_value() {
std::uint32_t hash_value = 0x538D24C7u; std::uint32_t hash_value = 0x538D24C7u;
@@ -61,13 +63,26 @@ namespace Eval::NNUE::Layers {
return hash_value; 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 // A string that represents the structure from the input layer to this layer
static std::string get_structure_string() { static std::string get_structure_string() {
return "ClippedReLU[" + return get_name() + "(" +
std::to_string(kOutputDimensions) + "](" +
PreviousLayer::get_structure_string() + ")"; 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 // Read network parameters
bool read_parameters(std::istream& stream) { bool read_parameters(std::istream& stream) {
return previous_layer_.read_parameters(stream); return previous_layer_.read_parameters(stream);
+53 -40
View File
@@ -28,56 +28,69 @@
namespace Eval::NNUE::Layers { namespace Eval::NNUE::Layers {
// Input layer // Input layer
template <IndexType OutputDimensions, IndexType Offset = 0> template <IndexType OutputDimensions, IndexType Offset = 0>
class InputSlice { class InputSlice {
public: public:
// Need to maintain alignment // Need to maintain alignment
static_assert(Offset % kMaxSimdWidth == 0, ""); static_assert(Offset % kMaxSimdWidth == 0, "");
// Output type // Output type
using OutputType = TransformedFeatureType; using OutputType = TransformedFeatureType;
// Output dimensionality // Output dimensionality
static constexpr IndexType kOutputDimensions = OutputDimensions; static constexpr IndexType kOutputDimensions = OutputDimensions;
// Size of forward propagation buffer used from the input layer to this layer // Size of forward propagation buffer used from the input layer to this layer
static constexpr std::size_t kBufferSize = 0; static constexpr std::size_t kBufferSize = 0;
// Hash value embedded in the evaluation file static constexpr int kLayerIndex = 1;
static constexpr std::uint32_t get_hash_value() {
std::uint32_t hash_value = 0xEC42E90Du;
hash_value ^= kOutputDimensions ^ (Offset << 10);
return hash_value;
}
// A string that represents the structure from the input layer to this layer // Hash value embedded in the evaluation file
static std::string get_structure_string() { static constexpr std::uint32_t get_hash_value() {
return "InputSlice[" + std::to_string(kOutputDimensions) + "(" + std::uint32_t hash_value = 0xEC42E90Du;
std::to_string(Offset) + ":" + hash_value ^= kOutputDimensions ^ (Offset << 10);
std::to_string(Offset + kOutputDimensions) + ")]"; return hash_value;
} }
// Read network parameters static std::string get_name() {
bool read_parameters(std::istream& /*stream*/) { return "InputSlice[" + std::to_string(kOutputDimensions) + "(" +
return true; std::to_string(Offset) + ":" +
} std::to_string(Offset + kOutputDimensions) + ")]";
}
// write parameters // A string that represents the structure from the input layer to this layer
bool write_parameters(std::ostream& /*stream*/) const { static std::string get_structure_string() {
return true; return get_name();
} }
// Forward propagation static std::string get_layers_info() {
const OutputType* propagate( std::string info = std::to_string(kLayerIndex);
const TransformedFeatureType* transformed_features, info += ": ";
char* /*buffer*/) const { 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 } // namespace Layers
+34 -4
View File
@@ -36,6 +36,8 @@ namespace Eval::NNUE::Layers {
static constexpr std::size_t kBufferSize = static constexpr std::size_t kBufferSize =
std::max(Head::kBufferSize + kSelfBufferSize, Tail::kBufferSize); std::max(Head::kBufferSize + kSelfBufferSize, Tail::kBufferSize);
static constexpr int kLayerIndex = Tail::kLayerIndex + 1;
// Hash value embedded in the evaluation function file // Hash value embedded in the evaluation function file
static constexpr std::uint32_t get_hash_value() { static constexpr std::uint32_t get_hash_value() {
std::uint32_t hash_value = 0xBCE400B4u; std::uint32_t hash_value = 0xBCE400B4u;
@@ -46,10 +48,23 @@ namespace Eval::NNUE::Layers {
return hash_value; 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 // A string that represents the structure from the input layer to this layer
static std::string get_structure_string() { static std::string get_structure_string() {
return "Sum[" + return get_name() + "(" + get_summands_string() + ")";
std::to_string(kOutputDimensions) + "](" + 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 // read parameters
@@ -117,6 +132,8 @@ namespace Eval::NNUE::Layers {
// Size of the forward propagation buffer used from the input layer to this layer // Size of the forward propagation buffer used from the input layer to this layer
static constexpr std::size_t kBufferSize = PreviousLayer::kBufferSize; static constexpr std::size_t kBufferSize = PreviousLayer::kBufferSize;
static constexpr int kLayerIndex = PreviousLayer::kLayerIndex + 1;
// Hash value embedded in the evaluation function file // Hash value embedded in the evaluation function file
static constexpr std::uint32_t get_hash_value() { static constexpr std::uint32_t get_hash_value() {
std::uint32_t hash_value = 0xBCE400B4u; std::uint32_t hash_value = 0xBCE400B4u;
@@ -125,10 +142,23 @@ namespace Eval::NNUE::Layers {
return hash_value; 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 // A string that represents the structure from the input layer to this layer
static std::string get_structure_string() { static std::string get_structure_string() {
return "Sum[" + return get_name() + "(" + get_summands_string() + ")";
std::to_string(kOutputDimensions) + "](" + 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 // read parameters
+15 -2
View File
@@ -110,19 +110,32 @@ namespace Eval::NNUE {
static constexpr std::size_t kBufferSize = static constexpr std::size_t kBufferSize =
kOutputDimensions * sizeof(OutputType); kOutputDimensions * sizeof(OutputType);
static constexpr int kLayerIndex = 0;
// Hash value embedded in the evaluation file // Hash value embedded in the evaluation file
static constexpr std::uint32_t get_hash_value() { static constexpr std::uint32_t get_hash_value() {
return RawFeatures::kHashValue ^ kOutputDimensions; return RawFeatures::kHashValue ^ kOutputDimensions;
} }
// a string representing the structure static std::string get_name() {
static std::string get_structure_string() {
return RawFeatures::get_name() + "[" + return RawFeatures::get_name() + "[" +
std::to_string(kInputDimensions) + "->" + std::to_string(kInputDimensions) + "->" +
std::to_string(kHalfDimensions) + "x2]"; 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 // Read network parameters
bool read_parameters(std::istream& stream) { bool read_parameters(std::istream& stream) {