mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 06:17:49 +00:00
Merge pull request #143 from Sopel97/no_eval_learn
Remove EVAL_LEARN and *learn* targets.
This commit is contained in:
+4
-13
@@ -67,20 +67,11 @@ script:
|
||||
- make clean && make -j2 ARCH=x86-64 build && ../tests/signature.sh $benchref
|
||||
# TODO avoid _mm_malloc
|
||||
# - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean && make -j2 ARCH=general-64 build && ../tests/signature.sh $benchref; fi
|
||||
# - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean && make -j2 ARCH=x86-32 optimize=no debug=yes build && ../tests/signature.sh $benchref; fi
|
||||
- make clean && make -j2 ARCH=x86-32-sse41-popcnt build && ../tests/signature.sh $benchref
|
||||
- make clean && make -j2 ARCH=x86-32-sse2 build && ../tests/signature.sh $benchref
|
||||
# TODO avoid _mm_malloc
|
||||
# - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean && make -j2 ARCH=x86-32 build && ../tests/signature.sh $benchref; fi
|
||||
# - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean && make -j2 ARCH=general-32 build && ../tests/signature.sh $benchref; fi
|
||||
- make clean && make -j2 ARCH=x86-64-modern profile-build && ../tests/signature.sh $benchref
|
||||
|
||||
# start some basic learner CI
|
||||
- make clean && make -j2 ARCH=x86-64-modern learn
|
||||
- make clean && make -j2 ARCH=x86-64-modern profile-learn
|
||||
- make clean && make -j2 ARCH=x86-64-modern debug=yes optimize=no learn
|
||||
|
||||
# compile only for some more advanced architectures (might not run in travis)
|
||||
- make clean && make -j2 ARCH=x86-64-avx2 blas=yes build
|
||||
|
||||
- make clean && make -j2 ARCH=x86-64-avx2 build
|
||||
- make clean && make -j2 ARCH=x86-64-bmi2 build
|
||||
- make clean && make -j2 ARCH=x86-64-avx512 build
|
||||
@@ -108,5 +99,5 @@ script:
|
||||
|
||||
# NNUE testing
|
||||
- export CXXFLAGS="-O1 -fno-inline"
|
||||
- make clean && make -j2 ARCH=x86-64-modern debug=no optimize=no learn > /dev/null && ../tests/instrumented_learn.sh --valgrind
|
||||
- make clean && make -j2 ARCH=x86-64-modern sanitize=undefined optimize=no debug=yes learn > /dev/null && ../tests/instrumented_learn.sh --sanitizer-undefined
|
||||
- make clean && make -j2 ARCH=x86-64-modern debug=no optimize=no build > /dev/null && ../tests/instrumented_learn.sh --valgrind
|
||||
- make clean && make -j2 ARCH=x86-64-modern sanitize=undefined optimize=no debug=yes build > /dev/null && ../tests/instrumented_learn.sh --sanitizer-undefined
|
||||
|
||||
@@ -7,6 +7,31 @@
|
||||
## Overview
|
||||
Stockfish NNUE is a port of a shogi neural network named NNUE (efficiently updateable neural network backwards) to Stockfish 11. To learn more about the Stockfish chess engine, look [here](stockfish.md) for an overview and [here](https://github.com/official-stockfish/Stockfish) for the official repository.
|
||||
|
||||
## Building
|
||||
To compile:
|
||||
```
|
||||
make -jN ARCH=... build
|
||||
```
|
||||
|
||||
To compile with Profile Guided Optimizations. Requires that the computer that is used for compilation supports the selected `ARCH`.
|
||||
```
|
||||
make -jN ARCH=... profile-build
|
||||
```
|
||||
|
||||
`N` is the number of threads to use for compilation.
|
||||
|
||||
`ARCH` is one of:
|
||||
`x86-64-vnni512`, `x86-64-vnni256`, `x86-64-avx512`, `x86-64-bmi2`, `x86-64-avx2`,
|
||||
`x86-64-sse41-popcnt`, `x86-64-modern`, `x86-64-ssse3`, `x86-64-sse3-popcnt`,
|
||||
`x86-64`, `x86-32-sse41-popcnt`, `x86-32-sse2`, `x86-32`, `ppc-64`, `ppc-32,
|
||||
armv7`, `armv7-neon`, `armv8`, `apple-silicon`, `general-64`, `general-32`.
|
||||
|
||||
`ARCH` needs to be chosen based based on the instruction set of the CPU that will run stockfish. `x86-64-modern` will produce a binary that works on most common processors, but other options may increase performance for specific hardware.
|
||||
|
||||
Additional options:
|
||||
|
||||
- `blas=[yes/no]` - whether to use an external BLAS library. Default is `no`. Using an external BLAS library may have a significantly improve learning performance and by default expects openBLAS to be installed.
|
||||
|
||||
## Training Guide
|
||||
### Generating Training Data
|
||||
To generate training data from the classic eval, use the gensfen command with the setting "Use NNUE" set to "false". The given example is generation in its simplest form. There are more commands.
|
||||
|
||||
+28
-45
@@ -39,8 +39,9 @@ PREFIX = /usr/local
|
||||
BINDIR = $(PREFIX)/bin
|
||||
|
||||
### Built-in benchmark for pgo-builds
|
||||
PGO_TRAINING_DATA_FILE = pgo_training_data.bin
|
||||
PGOBENCH = ./$(EXE) bench
|
||||
PGOGENSFEN = ./$(EXE) gensfen depth 3 loop 1000
|
||||
PGOGENSFEN = ./$(EXE) gensfen depth 3 loop 1000 output_file_name $(PGO_TRAINING_DATA_FILE)
|
||||
|
||||
### Source and object files
|
||||
SRCS = benchmark.cpp bitbase.cpp bitboard.cpp endgame.cpp evaluate.cpp main.cpp \
|
||||
@@ -111,6 +112,7 @@ else
|
||||
SUPPORTED_ARCH=false
|
||||
endif
|
||||
|
||||
blas = no
|
||||
optimize = yes
|
||||
debug = no
|
||||
sanitize = no
|
||||
@@ -131,20 +133,6 @@ neon = no
|
||||
ARCH = x86-64-modern
|
||||
STRIP = strip
|
||||
|
||||
### BLAS libraries
|
||||
ifeq ($(KERNEL),Linux)
|
||||
BLASCXXFLAGS =
|
||||
BLASLDFLAGS = -lopenblas
|
||||
else
|
||||
BLASCXXFLAGS = -I/mingw64/include/OpenBLAS
|
||||
|
||||
ifeq ($(debug),yes)
|
||||
BLASLDFLAGS = -lopenblas -Wl,-static
|
||||
else
|
||||
BLASLDFLAGS = -lopenblas -Wl,-s -static
|
||||
endif
|
||||
endif
|
||||
|
||||
### 2.2 Architecture specific
|
||||
|
||||
ifeq ($(findstring x86,$(ARCH)),x86)
|
||||
@@ -321,9 +309,9 @@ endif
|
||||
### ==========================================================================
|
||||
|
||||
### 3.1 Selecting compiler (default = gcc)
|
||||
CXXFLAGS += -g -Wall -Wcast-qual -fno-exceptions -std=c++17 -I. $(EXTRACXXFLAGS) $(LEARNCXXFLAGS)
|
||||
CXXFLAGS += -g -Wall -Wcast-qual -fno-exceptions -std=c++17 -fopenmp -I. $(EXTRACXXFLAGS)
|
||||
LDFLAGS += -fopenmp $(EXTRALDFLAGS)
|
||||
DEPENDFLAGS += -std=c++17 -I.
|
||||
LDFLAGS += $(EXTRALDFLAGS) $(LEARNLDFLAGS)
|
||||
|
||||
ifeq ($(COMP),)
|
||||
COMP=gcc
|
||||
@@ -478,14 +466,33 @@ ifneq ($(comp),mingw)
|
||||
endif
|
||||
endif
|
||||
|
||||
### 3.2.1 Debugging
|
||||
### 3.2.1. BLAS libraries
|
||||
ifeq ($(blas), yes)
|
||||
LDFLAGS += -lopenblas
|
||||
|
||||
ifeq ($(KERNEL),Linux)
|
||||
LDFLAGS +=
|
||||
else
|
||||
CXXFLAGS += -I/mingw64/include/OpenBLAS
|
||||
|
||||
ifeq ($(debug),yes)
|
||||
LDFLAGS += -Wl,-static
|
||||
else
|
||||
LDFLAGS += -Wl,-s -static
|
||||
endif
|
||||
endif
|
||||
|
||||
CXXFLAGS += -DUSE_BLAS
|
||||
endif
|
||||
|
||||
### 3.2.2 Debugging
|
||||
ifeq ($(debug),no)
|
||||
CXXFLAGS += -DNDEBUG
|
||||
else
|
||||
CXXFLAGS += -g
|
||||
endif
|
||||
|
||||
### 3.2.2 Debugging with undefined behavior sanitizers
|
||||
### 3.2.3 Debugging with undefined behavior sanitizers
|
||||
ifneq ($(sanitize),no)
|
||||
CXXFLAGS += -g3 -fsanitize=$(sanitize)
|
||||
LDFLAGS += -fsanitize=$(sanitize)
|
||||
@@ -744,6 +751,7 @@ profile-build: net config-sanity objclean profileclean
|
||||
@echo ""
|
||||
@echo "Step 2/4. Running benchmark for pgo-build ..."
|
||||
$(PGOBENCH) > /dev/null
|
||||
$(PGOGENSFEN) > /dev/null
|
||||
@echo ""
|
||||
@echo "Step 3/4. Building optimized executable ..."
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) objclean
|
||||
@@ -797,6 +805,7 @@ profileclean:
|
||||
@rm -rf profdir
|
||||
@rm -f bench.txt *.gcda *.gcno ./syzygy/*.gcda ./nnue/*.gcda ./nnue/features/*.gcda *.s ./learn/*.gcda ./extra/*.gcda ./eval/*.gcda
|
||||
@rm -f stockfish.profdata *.profraw
|
||||
@rm -f $(PGO_TRAINING_DATA_FILE)
|
||||
|
||||
default:
|
||||
help
|
||||
@@ -901,32 +910,6 @@ icc-profile-use:
|
||||
EXTRACXXFLAGS='-prof_use -prof_dir ./profdir' \
|
||||
all
|
||||
|
||||
learn: config-sanity
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||
EXTRACXXFLAGS=' -DEVAL_LEARN -DUSE_BLAS $(BLASCXXFLAGS) -fopenmp ' \
|
||||
EXTRALDFLAGS=' $(BLASLDFLAGS) -fopenmp ' \
|
||||
all
|
||||
|
||||
profile-learn: net config-sanity objclean profileclean
|
||||
@echo ""
|
||||
@echo "Step 1/4. Building instrumented executable ..."
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_make) \
|
||||
LEARNCXXFLAGS=' -DEVAL_LEARN -DUSE_BLAS $(BLASCXXFLAGS) -fopenmp ' \
|
||||
LEARNLDFLAGS=' $(BLASLDFLAGS) -fopenmp '
|
||||
@echo ""
|
||||
@echo "Step 2/4. Running benchmark for pgo-build ..."
|
||||
$(PGOGENSFEN)
|
||||
@echo ""
|
||||
@echo "Step 3/4. Building optimized executable ..."
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) objclean
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) $(profile_use) \
|
||||
LEARNCXXFLAGS=' -DEVAL_LEARN -DUSE_BLAS $(BLASCXXFLAGS) -fopenmp ' \
|
||||
LEARNLDFLAGS=' $(BLASLDFLAGS) -fopenmp '
|
||||
@echo ""
|
||||
@echo "Step 4/4. Deleting profile data ..."
|
||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) profileclean
|
||||
rm generated_kifu.bin
|
||||
|
||||
.depend:
|
||||
-@$(CXX) $(DEPENDFLAGS) -MM $(SRCS) > $@
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#ifndef _EVALUATE_COMMON_H_
|
||||
#define _EVALUATE_COMMON_H_
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
|
||||
// A common header-like function for modern evaluation functions.
|
||||
|
||||
#include <string>
|
||||
@@ -21,6 +19,4 @@ namespace Eval
|
||||
double get_eta();
|
||||
}
|
||||
|
||||
#endif // defined(EVAL_LEARN)
|
||||
|
||||
#endif // _EVALUATE_KPPT_COMMON_H_
|
||||
|
||||
@@ -43,11 +43,8 @@ namespace Eval {
|
||||
return UseNNUEMode::False;
|
||||
else if (mode == "true")
|
||||
return UseNNUEMode::True;
|
||||
|
||||
#ifdef EVAL_LEARN
|
||||
else if (mode == "pure")
|
||||
return UseNNUEMode::Pure;
|
||||
#endif
|
||||
|
||||
return UseNNUEMode::False;
|
||||
}
|
||||
@@ -955,11 +952,9 @@ make_v:
|
||||
/// evaluation of the position from the point of view of the side to move.
|
||||
|
||||
Value Eval::evaluate(const Position& pos) {
|
||||
#ifdef EVAL_LEARN
|
||||
if (useNNUE == UseNNUEMode::Pure) {
|
||||
return NNUE::evaluate(pos);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool classical = useNNUE == UseNNUEMode::False
|
||||
|| abs(eg_value(pos.psq_score())) * 16 > NNUEThreshold1 * (16 + pos.rule50_count());
|
||||
|
||||
+2
-5
@@ -29,11 +29,8 @@ namespace Eval {
|
||||
enum struct UseNNUEMode
|
||||
{
|
||||
False,
|
||||
True
|
||||
|
||||
#ifdef EVAL_LEARN
|
||||
,Pure
|
||||
#endif
|
||||
True,
|
||||
Pure
|
||||
};
|
||||
|
||||
std::string trace(const Position& pos);
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#if defined(EVAL_LEARN)
|
||||
|
||||
#include "convert.h"
|
||||
|
||||
#include "multi_think.h"
|
||||
@@ -606,4 +604,3 @@ namespace Learner
|
||||
convert(args);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
namespace Learner {
|
||||
void convert_bin_from_pgn_extract(
|
||||
const std::vector<std::string>& filenames,
|
||||
@@ -32,6 +31,5 @@ namespace Learner {
|
||||
|
||||
void convert(std::istringstream& is);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
#if defined(EVAL_LEARN)
|
||||
|
||||
#include "gensfen.h"
|
||||
#include "gensfen.h"
|
||||
|
||||
#include "packed_sfen.h"
|
||||
#include "multi_think.h"
|
||||
@@ -1207,4 +1205,3 @@ namespace Learner
|
||||
std::cout << "gensfen finished." << endl;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -5,12 +5,10 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
namespace Learner {
|
||||
|
||||
// Automatic generation of teacher position
|
||||
void gen_sfen(Position& pos, std::istringstream& is);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -17,8 +17,6 @@
|
||||
// → I will not be involved in the engine because it is a problem that the GUI should assist.
|
||||
// etc..
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
|
||||
#include "learn.h"
|
||||
|
||||
#include "convert.h"
|
||||
@@ -2054,5 +2052,3 @@ namespace Learner
|
||||
}
|
||||
|
||||
} // namespace Learner
|
||||
|
||||
#endif // EVAL_LEARN
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#ifndef _LEARN_H_
|
||||
#define _LEARN_H_
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
|
||||
// ----------------------
|
||||
// Floating point for learning
|
||||
// ----------------------
|
||||
@@ -78,6 +76,4 @@ namespace Learner
|
||||
void learn(Position& pos, std::istringstream& is);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // ifndef _LEARN_H_
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "learning_tools.h"
|
||||
|
||||
#if defined (EVAL_LEARN)
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
using namespace Eval;
|
||||
@@ -18,5 +16,3 @@ namespace EvalLearningTools
|
||||
uint64_t Weight::eta1_epoch;
|
||||
uint64_t Weight::eta2_epoch;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
|
||||
// A set of machine learning tools related to the weight array used for machine learning of evaluation functions
|
||||
|
||||
#if defined (EVAL_LEARN)
|
||||
|
||||
#include "learn.h"
|
||||
|
||||
#include "misc.h" // PRNG , my_insertion_sort
|
||||
@@ -98,5 +96,4 @@ namespace EvalLearningTools
|
||||
};
|
||||
}
|
||||
|
||||
#endif // defined (EVAL_LEARN)
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
#if defined(EVAL_LEARN)
|
||||
|
||||
#include "multi_think.h"
|
||||
#include "multi_think.h"
|
||||
|
||||
#include "tt.h"
|
||||
#include "uci.h"
|
||||
@@ -118,6 +116,3 @@ void MultiThink::go_think()
|
||||
Options[s.first] = std::string(s.second);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // defined(EVAL_LEARN)
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#ifndef _MULTI_THINK_
|
||||
#define _MULTI_THINK_
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
|
||||
#include "learn.h"
|
||||
|
||||
#include "misc.h"
|
||||
@@ -151,6 +149,4 @@ protected:
|
||||
std::mutex task_mutex;
|
||||
};
|
||||
|
||||
#endif // defined(EVAL_LEARN) && defined(YANEURAOU_2018_OTAFUKU_ENGINE)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
namespace Learner {
|
||||
|
||||
// packed sfen
|
||||
@@ -45,5 +44,3 @@ namespace Learner {
|
||||
using PSVector = std::vector<PackedSfenValue>;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
#if defined (EVAL_LEARN)
|
||||
|
||||
#include "sfen_packer.h"
|
||||
#include "sfen_packer.h"
|
||||
|
||||
#include "packed_sfen.h"
|
||||
|
||||
@@ -402,6 +400,3 @@ namespace Learner {
|
||||
return sfen;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // USE_SFEN_PACKER
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#ifndef _SFEN_PACKER_H_
|
||||
#define _SFEN_PACKER_H_
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#include "learn/packed_sfen.h"
|
||||
@@ -19,6 +17,4 @@ namespace Learner {
|
||||
PackedSfen sfen_pack(Position& pos);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code for learning NNUE evaluation function
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
|
||||
#include <random>
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
@@ -238,5 +236,3 @@ double get_eta() {
|
||||
}
|
||||
|
||||
} // namespace Eval
|
||||
|
||||
#endif // defined(EVAL_LEARN)
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
#ifndef _EVALUATE_NNUE_LEARNER_H_
|
||||
#define _EVALUATE_NNUE_LEARNER_H_
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
|
||||
#include "../learn/learn.h"
|
||||
|
||||
namespace Eval {
|
||||
@@ -41,6 +39,4 @@ void CheckHealth();
|
||||
|
||||
} // namespace Eval
|
||||
|
||||
#endif // defined(EVAL_LEARN)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
#ifndef _NNUE_TRAINER_H_
|
||||
#define _NNUE_TRAINER_H_
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
|
||||
#include "../nnue_common.h"
|
||||
#include "../features/index_list.h"
|
||||
|
||||
@@ -120,6 +118,4 @@ std::shared_ptr<T> MakeAlignedSharedPtr(ArgumentTypes&&... arguments) {
|
||||
|
||||
} // namespace Eval
|
||||
|
||||
#endif // defined(EVAL_LEARN)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
#ifndef _NNUE_TRAINER_AFFINE_TRANSFORM_H_
|
||||
#define _NNUE_TRAINER_AFFINE_TRANSFORM_H_
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
|
||||
#include "../../learn/learn.h"
|
||||
#include "../layers/affine_transform.h"
|
||||
#include "trainer.h"
|
||||
@@ -296,6 +294,4 @@ class Trainer<Layers::AffineTransform<PreviousLayer, OutputDimensions>> {
|
||||
|
||||
} // namespace Eval
|
||||
|
||||
#endif // defined(EVAL_LEARN)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
#ifndef _NNUE_TRAINER_CLIPPED_RELU_H_
|
||||
#define _NNUE_TRAINER_CLIPPED_RELU_H_
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
|
||||
#include "../../learn/learn.h"
|
||||
#include "../layers/clipped_relu.h"
|
||||
#include "trainer.h"
|
||||
@@ -137,6 +135,4 @@ class Trainer<Layers::ClippedReLU<PreviousLayer>> {
|
||||
|
||||
} // namespace Eval
|
||||
|
||||
#endif // defined(EVAL_LEARN)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
#ifndef _NNUE_TRAINER_FEATURE_TRANSFORMER_H_
|
||||
#define _NNUE_TRAINER_FEATURE_TRANSFORMER_H_
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
|
||||
#include "../../learn/learn.h"
|
||||
#include "../nnue_feature_transformer.h"
|
||||
#include "trainer.h"
|
||||
@@ -372,6 +370,4 @@ class Trainer<FeatureTransformer> {
|
||||
|
||||
} // namespace Eval
|
||||
|
||||
#endif // defined(EVAL_LEARN)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
#ifndef _NNUE_TRAINER_INPUT_SLICE_H_
|
||||
#define _NNUE_TRAINER_INPUT_SLICE_H_
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
|
||||
#include "../../learn/learn.h"
|
||||
#include "../layers/input_slice.h"
|
||||
#include "trainer.h"
|
||||
@@ -246,6 +244,4 @@ class Trainer<Layers::InputSlice<OutputDimensions, Offset>> {
|
||||
|
||||
} // namespace Eval
|
||||
|
||||
#endif // defined(EVAL_LEARN)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
#ifndef _NNUE_TRAINER_SUM_H_
|
||||
#define _NNUE_TRAINER_SUM_H_
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
|
||||
#include "../../learn/learn.h"
|
||||
#include "../layers/sum.h"
|
||||
#include "trainer.h"
|
||||
@@ -185,6 +183,4 @@ class Trainer<Layers::Sum<PreviousLayer>> {
|
||||
|
||||
} // namespace Eval
|
||||
|
||||
#endif // defined(EVAL_LEARN)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -32,10 +32,8 @@
|
||||
#include "uci.h"
|
||||
#include "syzygy/tbprobe.h"
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
#include "learn/packed_sfen.h"
|
||||
#include "learn/sfen_packer.h"
|
||||
#endif
|
||||
|
||||
using std::string;
|
||||
|
||||
@@ -1352,8 +1350,6 @@ bool Position::pos_is_ok() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
|
||||
// Add a function that directly unpacks for speed. It's pretty tough.
|
||||
// Write it by combining packer::unpack() and Position::set().
|
||||
// If there is a problem with the passed phase and there is an error, non-zero is returned.
|
||||
@@ -1385,5 +1381,3 @@ void Position::sfen_pack(Learner::PackedSfen& sfen)
|
||||
{
|
||||
sfen = Learner::sfen_pack(*this);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -30,10 +30,8 @@
|
||||
|
||||
#include "nnue/nnue_accumulator.h"
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
#include "learn/packed_sfen.h"
|
||||
#include "learn/sfen_packer.h"
|
||||
#endif
|
||||
|
||||
|
||||
/// StateInfo struct stores information needed to restore a Position object to
|
||||
@@ -177,7 +175,6 @@ public:
|
||||
// Used by NNUE
|
||||
StateInfo* state() const;
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
// --sfenization helper
|
||||
|
||||
friend int Learner::set_from_packed_sfen(Position& pos, const Learner::PackedSfen& sfen, StateInfo* si, Thread* th, bool mirror);
|
||||
@@ -199,7 +196,6 @@ public:
|
||||
|
||||
// Returns the position of the ball on the c side.
|
||||
Square king_square(Color c) const { return pieceList[make_piece(c, KING)][0]; }
|
||||
#endif // EVAL_LEARN
|
||||
|
||||
private:
|
||||
// Initialization helpers (used while setting up a position)
|
||||
|
||||
+1
-11
@@ -54,9 +54,7 @@ using std::string;
|
||||
using Eval::evaluate;
|
||||
using namespace Search;
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
bool Search::prune_at_shallow_depth_on_pv_node = false;
|
||||
#endif
|
||||
bool Search::prune_at_shallow_depth_on_pv_node = true;
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -991,9 +989,7 @@ moves_loop: // When in check, search starts from here
|
||||
ss->moveCount = ++moveCount;
|
||||
|
||||
if (rootNode && thisThread == Threads.main() && Time.elapsed() > 3000
|
||||
#if defined(EVAL_LEARN)
|
||||
&& !Limits.silent
|
||||
#endif
|
||||
)
|
||||
sync_cout << "info depth " << depth
|
||||
<< " currmove " << UCI::move(move, pos.is_chess960())
|
||||
@@ -1011,9 +1007,7 @@ moves_loop: // When in check, search starts from here
|
||||
|
||||
// Step 12. Pruning at shallow depth (~200 Elo)
|
||||
if ( !rootNode
|
||||
#ifdef EVAL_LEARN
|
||||
&& (PvNode ? prune_at_shallow_depth_on_pv_node : true)
|
||||
#endif
|
||||
&& pos.non_pawn_material(us)
|
||||
&& bestValue > VALUE_TB_LOSS_IN_MAX_PLY)
|
||||
{
|
||||
@@ -1564,10 +1558,8 @@ moves_loop: // When in check, search starts from here
|
||||
|
||||
// Check for legality just before making the move
|
||||
if (
|
||||
#if defined(EVAL_LEARN)
|
||||
// HACK: pos.piece_on(from_sq(m)) sometimes will be NO_PIECE during machine learning.
|
||||
!pos.pseudo_legal(move) ||
|
||||
#endif // EVAL_LEARN
|
||||
!pos.legal(move)
|
||||
)
|
||||
{
|
||||
@@ -1978,7 +1970,6 @@ void Tablebases::rank_root_moves(Position& pos, Search::RootMoves& rootMoves) {
|
||||
|
||||
// --- expose the functions such as fixed depth search used for learning to the outside
|
||||
|
||||
#if defined (EVAL_LEARN)
|
||||
|
||||
namespace Learner
|
||||
{
|
||||
@@ -2278,4 +2269,3 @@ namespace Learner
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -32,10 +32,7 @@ namespace Search {
|
||||
/// Threshold used for countermoves based pruning
|
||||
constexpr int CounterMovePruneThreshold = 0;
|
||||
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
extern bool prune_at_shallow_depth_on_pv_node;
|
||||
#endif
|
||||
|
||||
/// Stack struct keeps track of the information we need to remember from nodes
|
||||
/// shallower and deeper in the tree during the search. Each search thread has
|
||||
@@ -90,9 +87,7 @@ struct LimitsType {
|
||||
time[WHITE] = time[BLACK] = inc[WHITE] = inc[BLACK] = npmsec = movetime = TimePoint(0);
|
||||
movestogo = depth = mate = perft = infinite = 0;
|
||||
nodes = 0;
|
||||
#if defined (EVAL_LEARN)
|
||||
silent = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool use_time_management() const {
|
||||
@@ -103,11 +98,9 @@ struct LimitsType {
|
||||
TimePoint time[COLOR_NB], inc[COLOR_NB], npmsec, movetime, startTime;
|
||||
int movestogo, depth, mate, perft, infinite;
|
||||
int64_t nodes;
|
||||
#if defined (EVAL_LEARN)
|
||||
// Silent mode that does not output to the screen (for continuous self-play in process)
|
||||
// Do not output PV at this time.
|
||||
bool silent;
|
||||
#endif
|
||||
};
|
||||
|
||||
extern LimitsType Limits;
|
||||
@@ -117,7 +110,6 @@ void clear();
|
||||
|
||||
} // namespace Search
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
namespace Learner {
|
||||
|
||||
// A pair of reader and evaluation value. Returned by Learner::search(),Learner::qsearch().
|
||||
@@ -126,6 +118,5 @@ namespace Learner {
|
||||
ValueAndPV qsearch(Position& pos);
|
||||
ValueAndPV search(Position& pos, int depth_, size_t multiPV = 1, uint64_t nodesLimit = 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // #ifndef SEARCH_H_INCLUDED
|
||||
|
||||
@@ -28,9 +28,7 @@
|
||||
|
||||
TranspositionTable TT; // Our global transposition table
|
||||
|
||||
#ifdef EVAL_LEARN
|
||||
bool TranspositionTable::enable_transposition_table = true;
|
||||
#endif
|
||||
|
||||
/// TTEntry::save() populates the TTEntry with a new node's data, possibly
|
||||
/// overwriting an old position. Update is not atomic and can be racy.
|
||||
@@ -120,12 +118,10 @@ void TranspositionTable::clear() {
|
||||
|
||||
TTEntry* TranspositionTable::probe(const Key key, bool& found) const {
|
||||
|
||||
#ifdef EVAL_LEARN
|
||||
if (!enable_transposition_table) {
|
||||
found = false;
|
||||
return first_entry(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
TTEntry* const tte = first_entry(key);
|
||||
const uint16_t key16 = (uint16_t)key; // Use the low 16 bits as key inside the cluster
|
||||
|
||||
@@ -84,9 +84,7 @@ public:
|
||||
return &table[mul_hi64(key, clusterCount)].entry[0];
|
||||
}
|
||||
|
||||
#ifdef EVAL_LEARN
|
||||
static bool enable_transposition_table;
|
||||
#endif
|
||||
|
||||
private:
|
||||
friend struct TTEntry;
|
||||
|
||||
+1
-6
@@ -245,7 +245,6 @@ double UCI::win_rate_model_double(double v, int ply) {
|
||||
// Call qsearch(),search() directly for testing
|
||||
// --------------------
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
void qsearch_cmd(Position& pos)
|
||||
{
|
||||
cout << "qsearch : ";
|
||||
@@ -277,8 +276,6 @@ void search_cmd(Position& pos, istringstream& is)
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/// UCI::loop() waits for a command from stdin, parses it and calls the appropriate
|
||||
/// function. Also intercepts EOF from stdin to ensure gracefully exiting if the
|
||||
/// GUI dies unexpectedly. When called with some command line arguments, e.g. to
|
||||
@@ -334,7 +331,7 @@ void UCI::loop(int argc, char* argv[]) {
|
||||
else if (token == "d") sync_cout << pos << sync_endl;
|
||||
else if (token == "eval") trace_eval(pos);
|
||||
else if (token == "compiler") sync_cout << compiler_info() << sync_endl;
|
||||
#if defined (EVAL_LEARN)
|
||||
|
||||
else if (token == "gensfen") Learner::gen_sfen(pos, is);
|
||||
else if (token == "learn") Learner::learn(pos, is);
|
||||
else if (token == "convert") Learner::convert(is);
|
||||
@@ -343,8 +340,6 @@ void UCI::loop(int argc, char* argv[]) {
|
||||
else if (token == "qsearch") qsearch_cmd(pos);
|
||||
else if (token == "search") search_cmd(pos, is);
|
||||
|
||||
#endif
|
||||
|
||||
// test command
|
||||
else if (token == "test") test_cmd(pos, is);
|
||||
else
|
||||
|
||||
+1
-9
@@ -42,14 +42,12 @@ void on_threads(const Option& o) { Threads.set(size_t(o)); }
|
||||
void on_tb_path(const Option& o) { Tablebases::init(o); }
|
||||
void on_use_NNUE(const Option& ) { Eval::init_NNUE(); }
|
||||
void on_eval_file(const Option& ) { Eval::init_NNUE(); }
|
||||
#ifdef EVAL_LEARN
|
||||
void on_prune_at_shallow_depth_on_pv_node(const Option& o) {
|
||||
Search::prune_at_shallow_depth_on_pv_node = o;
|
||||
}
|
||||
void on_enable_transposition_table(const Option& o) {
|
||||
TranspositionTable::enable_transposition_table = o;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Our case insensitive less() function as required by UCI protocol
|
||||
bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {
|
||||
@@ -86,11 +84,7 @@ void init(OptionsMap& o) {
|
||||
o["SyzygyProbeDepth"] << Option(1, 1, 100);
|
||||
o["Syzygy50MoveRule"] << Option(true);
|
||||
o["SyzygyProbeLimit"] << Option(7, 0, 7);
|
||||
#if defined(EVAL_LEARN)
|
||||
o["Use NNUE"] << Option("true var true var false var pure", "true", on_use_NNUE);
|
||||
#else
|
||||
o["Use NNUE"] << Option("true var true var false", "true", on_use_NNUE);
|
||||
#endif
|
||||
// The default must follow the format nn-[SHA256 first 12 digits].nnue
|
||||
// for the build process (profile-build and fishtest) to work.
|
||||
o["EvalFile"] << Option("nn-82215d0fd0df.nnue", on_eval_file);
|
||||
@@ -102,16 +96,14 @@ void init(OptionsMap& o) {
|
||||
o["SkipLoadingEval"] << Option(false);
|
||||
// how many moves to use a fixed move
|
||||
// o["BookMoves"] << Option(16, 0, 10000);
|
||||
#if defined(EVAL_LEARN)
|
||||
// When learning the evaluation function, you can change the folder to save the evaluation function.
|
||||
// Evalsave by default. This folder shall be prepared in advance.
|
||||
// Automatically create a folder under this folder like "0/", "1/", ... and save the evaluation function file there.
|
||||
o["EvalSaveDir"] << Option("evalsave");
|
||||
// Prune at shallow depth on PV nodes. Setting this value to true gains elo in shallow search.
|
||||
o["PruneAtShallowDepthOnPvNode"] << Option(false, on_prune_at_shallow_depth_on_pv_node);
|
||||
o["PruneAtShallowDepthOnPvNode"] << Option(true, on_prune_at_shallow_depth_on_pv_node);
|
||||
// Enable transposition table.
|
||||
o["EnableTranspositionTable"] << Option(true, on_enable_transposition_table);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user