Skip to content

Commit

Permalink
Stockfish17のAffineTransformとAffineTransformSparseInputを移植した (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
KazApps authored Oct 7, 2024
1 parent 434a339 commit 9c41f5b
Show file tree
Hide file tree
Showing 11 changed files with 756 additions and 619 deletions.
3 changes: 2 additions & 1 deletion source/eval/nnue/architectures/halfkp_1024x2-8-32.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "../layers/input_slice.h"
#include "../layers/affine_transform.h"
#include "../layers/affine_transform_sparse_input.h"
#include "../layers/clipped_relu.h"

namespace Eval::NNUE {
Expand All @@ -26,7 +27,7 @@ namespace Layers {
// Define network structure
// ネットワーク構造の定義
using InputLayer = InputSlice<kTransformedFeatureDimensions * 2>;
using HiddenLayer1 = ClippedReLU<AffineTransform<InputLayer, 8>>;
using HiddenLayer1 = ClippedReLU<AffineTransformSparseInput<InputLayer, 8>>;
using HiddenLayer2 = ClippedReLU<AffineTransform<HiddenLayer1, 32>>;
using OutputLayer = AffineTransform<HiddenLayer2, 1>;

Expand Down
3 changes: 2 additions & 1 deletion source/eval/nnue/architectures/halfkp_1024x2-8-64.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "../layers/input_slice.h"
#include "../layers/affine_transform.h"
#include "../layers/affine_transform_sparse_input.h"
#include "../layers/clipped_relu.h"

namespace Eval::NNUE {
Expand All @@ -26,7 +27,7 @@ namespace Eval::NNUE {
// Define network structure
// ネットワーク構造の定義
using InputLayer = InputSlice<kTransformedFeatureDimensions * 2>;
using HiddenLayer1 = ClippedReLU<AffineTransform<InputLayer, 8>>;
using HiddenLayer1 = ClippedReLU<AffineTransformSparseInput<InputLayer, 8>>;
using HiddenLayer2 = ClippedReLU<AffineTransform<HiddenLayer1, 64>>;
using OutputLayer = AffineTransform<HiddenLayer2, 1>;

Expand Down
3 changes: 2 additions & 1 deletion source/eval/nnue/architectures/halfkp_256x2-32-32.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "../layers/input_slice.h"
#include "../layers/affine_transform.h"
#include "../layers/affine_transform_sparse_input.h"
#include "../layers/clipped_relu.h"

namespace Eval::NNUE {
Expand All @@ -26,7 +27,7 @@ namespace Layers {
// Define network structure
// ネットワーク構造の定義
using InputLayer = InputSlice<kTransformedFeatureDimensions * 2>;
using HiddenLayer1 = ClippedReLU<AffineTransform<InputLayer, 32>>;
using HiddenLayer1 = ClippedReLU<AffineTransformSparseInput<InputLayer, 32>>;
using HiddenLayer2 = ClippedReLU<AffineTransform<HiddenLayer1, 32>>;
using OutputLayer = AffineTransform<HiddenLayer2, 1>;

Expand Down
3 changes: 2 additions & 1 deletion source/eval/nnue/architectures/halfkp_512x2-16-32.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "../layers/input_slice.h"
#include "../layers/affine_transform.h"
#include "../layers/affine_transform_sparse_input.h"
#include "../layers/clipped_relu.h"

namespace Eval::NNUE {
Expand All @@ -26,7 +27,7 @@ namespace Layers {
// Define network structure
// ネットワーク構造の定義
using InputLayer = InputSlice<kTransformedFeatureDimensions * 2>;
using HiddenLayer1 = ClippedReLU<AffineTransform<InputLayer, 16>>;
using HiddenLayer1 = ClippedReLU<AffineTransformSparseInput<InputLayer, 16>>;
using HiddenLayer2 = ClippedReLU<AffineTransform<HiddenLayer1, 32>>;
using OutputLayer = AffineTransform<HiddenLayer2, 1>;

Expand Down
3 changes: 2 additions & 1 deletion source/eval/nnue/architectures/halfkpe9_256x2-32-32.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "../layers/input_slice.h"
#include "../layers/affine_transform.h"
#include "../layers/affine_transform_sparse_input.h"
#include "../layers/clipped_relu.h"

namespace Eval {
Expand All @@ -25,7 +26,7 @@ namespace NNUE {

// ネットワーク構造の定義
using InputLayer = InputSlice<kTransformedFeatureDimensions * 2>;
using HiddenLayer1 = ClippedReLU<AffineTransform<InputLayer, 32>>;
using HiddenLayer1 = ClippedReLU<AffineTransformSparseInput<InputLayer, 32>>;
using HiddenLayer2 = ClippedReLU<AffineTransform<HiddenLayer1, 32>>;
using OutputLayer = AffineTransform<HiddenLayer2, 1>;

Expand Down
3 changes: 2 additions & 1 deletion source/eval/nnue/architectures/halfkpvm_256x2-32-32.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "../layers/input_slice.h"
#include "../layers/affine_transform.h"
#include "../layers/affine_transform_sparse_input.h"
#include "../layers/clipped_relu.h"

namespace Eval {
Expand All @@ -25,7 +26,7 @@ namespace Eval {

// ネットワーク構造の定義
using InputLayer = InputSlice<kTransformedFeatureDimensions * 2>;
using HiddenLayer1 = ClippedReLU<AffineTransform<InputLayer, 32>>;
using HiddenLayer1 = ClippedReLU<AffineTransformSparseInput<InputLayer, 32>>;
using HiddenLayer2 = ClippedReLU<AffineTransform<HiddenLayer1, 32>>;
using OutputLayer = AffineTransform<HiddenLayer2, 1>;

Expand Down
3 changes: 2 additions & 1 deletion source/eval/nnue/architectures/kp_256x2-32-32.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "../layers/input_slice.h"
#include "../layers/affine_transform.h"
#include "../layers/affine_transform_sparse_input.h"
#include "../layers/clipped_relu.h"

namespace Eval {
Expand All @@ -24,7 +25,7 @@ namespace Layers {

// ネットワーク構造の定義
using InputLayer = InputSlice<kTransformedFeatureDimensions * 2>;
using HiddenLayer1 = ClippedReLU<AffineTransform<InputLayer, 32>>;
using HiddenLayer1 = ClippedReLU<AffineTransformSparseInput<InputLayer, 32>>;
using HiddenLayer2 = ClippedReLU<AffineTransform<HiddenLayer1, 32>>;
using OutputLayer = AffineTransform<HiddenLayer2, 1>;

Expand Down
3 changes: 2 additions & 1 deletion source/eval/nnue/architectures/nnue_arch_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
header += f"""
#include "../layers/input_slice.h"
#include "../layers/affine_transform.h"
#include "../layers/affine_transform_sparse_input.h"
#include "../layers/clipped_relu.h"
namespace Eval::NNUE {{
Expand Down Expand Up @@ -164,7 +165,7 @@
// Define network structure
// ネットワーク構造の定義
using InputLayer = InputSlice<kTransformedFeatureDimensions * {first_layer[1]}>;
using HiddenLayer1 = ClippedReLU<AffineTransform<InputLayer, {layers[1]}>>;
using HiddenLayer1 = ClippedReLU<AffineTransformSparseInput<InputLayer, {layers[1]}>>;
using HiddenLayer2 = ClippedReLU<AffineTransform<HiddenLayer1, {layers[2]}>>;
using OutputLayer = AffineTransform<HiddenLayer2, 1>;
Expand Down
Loading

0 comments on commit 9c41f5b

Please sign in to comment.