Skip to content

Commit

Permalink
15 + 1 -> 16
Browse files Browse the repository at this point in the history
  • Loading branch information
PikaCat-OuO committed Oct 6, 2024
1 parent baec5cd commit ceb7139
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/nnue/nnue_architecture.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ constexpr IndexType PSQTBuckets = 16;
constexpr IndexType LayerStacks = 16;

struct NetworkArchitecture {
static constexpr int FC_0_OUTPUTS = 15;
static constexpr int FC_0_OUTPUTS = 16;
static constexpr int FC_1_OUTPUTS = 32;

Layers::AffineTransformSparseInput<TransformedFeatureDimensions, FC_0_OUTPUTS + 1> fc_0;
Layers::SqrClippedReLU<FC_0_OUTPUTS + 1> ac_sqr_0;
Layers::ClippedReLU<FC_0_OUTPUTS + 1> ac_0;
Layers::AffineTransform<FC_0_OUTPUTS * 2, FC_1_OUTPUTS> fc_1;
Layers::ClippedReLU<FC_1_OUTPUTS> ac_1;
Layers::AffineTransform<FC_1_OUTPUTS, 1> fc_2;
Layers::AffineTransformSparseInput<TransformedFeatureDimensions, FC_0_OUTPUTS> fc_0;
Layers::SqrClippedReLU<FC_0_OUTPUTS> ac_sqr_0;
Layers::ClippedReLU<FC_0_OUTPUTS> ac_0;
Layers::AffineTransform<FC_0_OUTPUTS * 2, FC_1_OUTPUTS> fc_1;
Layers::ClippedReLU<FC_1_OUTPUTS> ac_1;
Layers::AffineTransform<FC_1_OUTPUTS, 1> fc_2;

// Hash value embedded in the evaluation file
static constexpr std::uint32_t get_hash_value() {
Expand Down Expand Up @@ -106,17 +106,15 @@ struct NetworkArchitecture {

fc_0.propagate(transformedFeatures, buffer.fc_0_out);
ac_sqr_0.propagate(buffer.fc_0_out, buffer.ac_sqr_0_out);
ac_0.propagate(buffer.fc_0_out, buffer.ac_0_out);
std::memcpy(buffer.ac_sqr_0_out + FC_0_OUTPUTS, buffer.ac_0_out,
FC_0_OUTPUTS * sizeof(decltype(ac_0)::OutputType));
ac_0.propagate(buffer.fc_0_out, buffer.ac_sqr_0_out + FC_0_OUTPUTS);
fc_1.propagate(buffer.ac_sqr_0_out, buffer.fc_1_out);
ac_1.propagate(buffer.fc_1_out, buffer.ac_1_out);
fc_2.propagate(buffer.ac_1_out, buffer.fc_2_out);

// buffer.fc_0_out[FC_0_OUTPUTS] is such that 1.0 is equal to 127*(1<<WeightScaleBits) in
// quantized form but we want 1.0 to be equal to 600*OutputScale
std::int32_t fwdOut =
(buffer.fc_0_out[FC_0_OUTPUTS]) * (600 * OutputScale) / (127 * (1 << WeightScaleBits));
// buffer.fc_0_out[FC_0_OUTPUTS - 1] is such that 1.0 is equal to 127*(1<<WeightScaleBits)
// in quantized form but we want 1.0 to be equal to 600*OutputScale
std::int32_t fwdOut = (buffer.fc_0_out[FC_0_OUTPUTS - 1]) * (600 * OutputScale)
/ (127 * (1 << WeightScaleBits));
std::int32_t outputValue = buffer.fc_2_out[0] + fwdOut;

return outputValue;
Expand Down

0 comments on commit ceb7139

Please sign in to comment.