LeelaChessZero / lc0

The rewritten engine, originally for tensorflow. Now all other backends have been ported here.
GNU General Public License v3.0
2.47k stars 534 forks source link

brainstorming lc0 support for training from predefined positions / book #541

Closed borg323 closed 4 years ago

borg323 commented 6 years ago

There was some discussion of discord starting here. The main options are:

1. Accept fen and moves from the command line (or a uci position command).

  1. Read a file with various position and select from them 3. Use lc0 selfplay --interactive

Option 1 is simple to implement in lc0, and client has most of the code needed (e.g. https://github.com/borg323/lczero-client/commit/38db0018b203f068ecfb14e5b93444e0284439e3 adds client support for using a book in test matches). The main drawback is that the client will need to stop and restart lc0 periodically to change start position, adding complexity and overhead.

Option 2 adds more complexity to lc0 (reading the file, selecting position) but the client needs only to download the file.

Option 3 needs no work in lc0, but adds a lot of complexity to the client. In particular, handling of parallelism is a big change: currently test match play (which is similar) does not supporting parallelism.

Comments? If there are any other options suggested, I'll update the above list.

Update: given the latest client changes to always use selfplay, only option 2 is still viable.

DanielUranga commented 5 years ago

Reading from a PGN database might be another not-so-hard way of doing it. Pgnlib works ok for small databases: https://github.com/DanielUranga/trainingdata-tool/tree/pgnlib/pgnlib and https://sourceforge.net/projects/pgnlib/ We could make a git submodule for it.

mooskagh commented 5 years ago

pgnlib is not compatible with our licence. (pgnlib is GPL, we are "GPL with exception")

To PGN parsing, I'd prefer a text file with one position per line, in formats like:

startpost moves e2e4 e7e5
fen rnbqnrk1/pp2ppbp/6p1/4P3/3P1N2/5NP1/PP3PBP/R1BQK2R b KQ - 4 11

It may be e.g. two params, --position="startpos moves e2e4" (to pass it as a string) and --position-file=filename

borg323 commented 5 years ago

I don't see anything wrong with --position=file:filename or --position=file=filename. We can reuse the uci position parsing for this (with the file extension) so that --position="fen rnbqnrk1/pp2ppbp/6p1/4P3/3P1N2/5NP1/PP3PBP/R1BQK2R b KQ - 4 11 moves a2a4 will also work.

We also need a mechanism to specify how to select a line from the file. We certainly don't want each user to train on one opening only.

mooskagh commented 5 years ago

The "canonical" way to pass parameters as file is to prefix them with @. E.g. --position=@filename.txt. But I didn't like it (a bit) because corresponding Uci parameter then wouldn't have file in the name, and chess GUI won't show file selection dialog.

But we don't use chess GUI with selfplay mode anyway.

mooskagh commented 5 years ago

For "how to select line", I think shuffling it in the beginning, and then doing round-robin in shuffled array would be fine.

Naphthalin commented 4 years ago

I'm pretty sure that this is implemented now for the FRC run and @Ttl experiments, but I can't find the merged PR. Would be nice if someone could link the relevant PR(s) and close this issue.

borg323 commented 4 years ago

There are several rellated PRs #1060 #1135 #1142 #1178 #1227, https://github.com/LeelaChessZero/lczero-client/pull/79 https://github.com/LeelaChessZero/lczero-client/pull/113 and https://github.com/Tilps/chess/pull/3