Analyze A Chess Position On An Expensive Computer For Less Than $1

 

If you've ever wanted to analyze a chess position on a computer that's much stronger than yours, I'll show you how to do it inexpensively. Be warned, however, it's quite likely that your own home computer -- given enough time -- will find the same "best move." 

Vast AI

VastAI is an awesome website that I hope lasts forever. It's a marketplace where individuals/businesses will rent you a machine in the cloud. It is clearly designed for serious AI training and development. Some pretty incredible machines are available for around $7/hour with 256 threads and 14 Nvidia 4090 GPUs. An AMD EPYC 7742 CPU costs about $7,800 and each RTX 4090 has a MSRP of approximately $1,600. With RAM and other components, the top machine circled in red probably costs about $35,000!

For our purposes, however, you can also rent powerful machines for roughly $1/hour or less (when choosing a machine, their Filter Options are useful to specify minimum number of threads, minimum internet connection speeds, etc.). Since you will be downloading some files to set up Stockfish and/or Lc0, it is useful to choose an instance with high download internet speeds.
Before you rent your machine, you will need to set up a ssh key and store it under the Account tab on your VastAI account. VastAI provides good instructions in the FAQ on how to do that:

Once you hit "rent" and go over to the "Instances" tab, you will see your machine being set up. Once it is ready, hit the "Connect" button and it will give you the direct ssh connection command to use in your terminal. Copy that and paste it in your terminal and login.

At this point you are on the computer you rented, but you now need to set up your chess engine in order to do your analysis.

Set up Stockfish and Analyze a Position

Once you log in to your ssh instance, you will install the tools you need to compile Stockfish, clone and compile Stockfish, and then run Stockfish in a terminal.  The steps are illustrated below divided by the '==========' sections:

You will adjust the threads and hash according to how many threads and RAM the machine you are renting has. Also you need to provide your position as a FEN. You can easily get your FEN from Scid (using the "Edit"/"Copy Position" options), or, from sites like Lichess.  When your analysis completes, just copy and paste the last evaluation line to your local machine's text editor.
When you're done, type "quit" to exit Stockfish and then type "exit" to close the ssh instance. However, this does not shut down your rental instance! You must go back to the VastAI site and hit the trash can icon to terminate your rental (and fees).

You will notice that the best moves calculated by Stockfish are expressed in a different notation than you may be used to (e.g. c7c6). c7c6 simply means move whatever piece is on the c7 square to the c6 square. If you copied the best line to your local machine's text editor, you can convert it to traditional notation using the Python chess library and your starting FEN position.
I wasn't rushing, but the Stockfish set up and 6 minutes of analysis took about 10 minutes (or about 11 cents!).

Set Up Lc0 and Analyze a Position

The procedure is quite similar for using a VastAI instance to run Lc0. It's critical to select the correct instance configuration: you want to select an instance that is Ubuntu 20.04 "development" version with CUDA 12.2.0

Then simply run the following to analyze the same FEN position we analyzed above:

More Powerful Computers Still Require You To Analyze, Compare And Think!

More powerful computers should provide better analyses because the breadth of their search is broader (more nodes are explored). However, often you will find more powerful computers will give you the same answers you get on weaker hardware. The FEN given in the examples above is an interesting cautionary example.
After White's move of Be3, Stockfish running on ordinary hardware thinks Black has a significant advantage of approximately +1.0 (pawns) and Black's best next move should be Qc6.  When I ran it on a VastAI instance with more than 120 threads for 6 minutes (as shown above ), Stockfish still thinks Black should move Qc6 and assesses its advantage is even greater at 1.4 pawns. In reality, after White follows up Qc6 with Rbd1, Stockfish realizes it's a draw. It's blindness on the prior move illustrates that more powerful hardware often doesn't lead to a different and/or better answer.

Lc0 more quickly realizes Black's advantage isn't as great, but it still overestimates it. And even running it on a machine with 2 Nvidia 4090s (~30 million nodes/second) for 6 minutes, Lc0 still thinks Black has a 32% chance of winning.

In this particular case, your time would have been better spent actually playing out your own engine's suggested moves to see if the solution was stable (called "backwards analysis"), instead of running the same analysis on more powerful computers.

Finally...

In addition to using a Vast AI instance to analyze a position, you could also use one to do your own engine testing and/or neural net training.

Comments

Popular Posts