NashGPT: Training a Transformer Model on Poker Solver Output A developer built NashGPT, a roughly 26-million-parameter transformer model trained on the strategy output of TurboFire, a game-theory-optimal poker solver written in C++. The project logs the solver's Nash-equilibrium strategies to a large file and trains the transformer on those patterns, with the author framing the work as research done "for fun and (no) profit. Training a Transformer Model on Poker Solver Output for Fun and No Profit Is bluffing aligned behavior? Introduction Poker play is considered game theory optimal when the players converge to a strategy which is not exploitable, meaning no deviation in strategy will provide an advantage to any player. An algorithm was discovered many years ago which pits two players against each other, starting with an equal strategy for every action, and adjusting the chances of taking certain actions until reaching a state of non-exploitability known as nash equilibrium . Commercial solvers hide the math and logic behind their products, which makes their services appear as black boxes which provide you with a perfect strategy. Once we learn how the algorithm works and create our own solver, we can take the patterns in the output and create a transformer model out of them. TurboFire and NashGPT TurboFire is a game theory optimal poker solver written in C++. It has none of the creature comforts of a traditional poker solver, such as memory saving techniques or abilities to load custom ranges of hands for you or your opponent. The base project serves as a great foundation for research, and can be adapted for many different purposes, such as a transformer model. With a bit of work, the output of the poker solver’s strategy could be stored as a large log file, and used to train a transformer model. NashGPT is the ~26M parameter model which was trained on the output of the solver, learning the concepts behind game theory optimal strategy in training. If you haven't played poker, the article will go through the basics of the game, the concepts and algorithms behind game theory optimal poker, and the concepts that can be taken from it. Feel free to skip around the article to your level of interest and expertise - this post's content is entirely human written, with some formatting help : Poker Prologue Setting: A poker room in Las Vegas, Nevada - February 1982 You and your opponent, the villain , arrive at the poker table. On the unsturdy poker table there’s a low-grade stench of Rolling Rock, and as you shuffle through the $100 in slightly discolored casino chips sitting in front of you, a few of the $1 chips stick together. The dealer sits down and you’re both dealt two cards. You have two Aces - an Ace of Spades and an Ace of Diamonds . The best hand in poker. Your opponent stares down at their cards, and their eyes dash over to their pile of chips, and they flick $2 in the middle. You match their bet. There’s $4 in the pot , or the collective amount you’ve both committed. The dealer places three cards on the table, one at a time: 9 of Diamonds, 5 of Clubs, King of Diamonds . You bet $3 into the pot. Your opponent freezes and quickly adds $9 into the pot, a raise. You think for a few seconds - and announce you’re calling , and slide $6 into the pot in the middle. The dealer announces “flip ‘em” . You’re playing a modified version of poker which stops at the flop the first set of cards revealed by the dealer to save time. Normally, there would be 2 more betting rounds, with 2 more cards revealed, known as the turn and river . Example: Flop: 9 Diamonds, 5 Clubs, King Diamonds , Turn: 2 Hearts , River: 3 Hearts Your opponent slams their cards down: King Hearts, 10 Diamonds. You smile, and reveal your aces - your opponent made a pair, two Kings. Your two Aces, however, slightly outclass their pair of kings. There’s some slight mumbling on the other side of the table involving expletives, ranges, fish. You’re unsure what free-range aquatic life has to do with poker, but there’s $22 sliding your way, and $11 of it is your opponent's money. ... Perfect Poker As a human, it takes an incrediblle amount of time and dedication to learn proper poker strategy. For computers, there are algorithms which will automate this learning process. The algorithm only knows the rules of the game, and through a method known as Regret Minimization , strategies that reach equilibrium can be found for both players. In the solver discussed in this post, the full algorithm is known as Discounted Counterfactual Regret Minimization, or DCFR \ 1\ reference-dcfr . Regret within the algorithm is used slightly differently than in common vernacular. Regret should be read in this post as “fear of missing out” FOMO instead of a decision with negative consequences. Think along the lines of “I regret not asking the professor for extra credit” , where you look counterfactually to the path you didn't take with regret FOMO for not choosing it. It's called regret minimization , because you're trying to minimize your FOMO. You'll also be looking counterfactually across hands and actions you did not choose to see how those situations would have played out, counter to the fact that you did not choose them. Discounting requires a bit more context first. DCFR In poker solvers, a game is defined as a game tree, where each action check, bet, raise creates a new branch from the root that grows outward. These are defined as action nodes. The game tree begins to explode as chance nodes are hit, which is when the environment affects the game state. In poker, the environment is a card being drawn from the deck at random. In order to accurately simulate a poker game, we must account for each card drawn from the deck, at both the turn and river, which is 49 choose 2 possible branches. The terminal node occurs when one player folds, or all possible actions end. Every action is equally weighted, for both the hero and the villain, at the start of the hand. If your possible options are fold , call , raise to $3 , or raise to $6 , the default strategy requires each one to be taken ¼ of the time. At the terminal node, you calculate your counterfactual value CFV for each possible hand in your range all hands you could be holding against your opponent's range. Meaning, you see how well your two aces would hold up against all of the possible hands your opponent could be holding, alongside a given board state. Once your CFV for the terminal node is calculated, you return the vector of values to the previous node. The goal is to see how choosing a specific action such as fold or raise holds up against the strategy weighted CFV of the node. Your strategy is how likely you were to take an action ¼ to start over 4 actions, in the previous example and the CFV for each action is weighted against the strategy for that subsequent node. Regret is calculated as an individual action’s CFV - the weighted average CFV of the node. The node’s CFV is passed up the tree, and then the regret calculation repeats until reaching the game root. The same process occurs for the villain. On the next iteration, instead of the next strategy being equally weighted, it is calculated based on the regret. Imagine you accumulated -2 regret from folding, 3 regret from calling, 2 from raising to $3, and -1 from raising to $6. You can throw out the regrets that are negative, as those are actions you wish you didn’t take remember that regret is more like FOMO and the positive regret is summed. 3 regret from calling + 2 regret from raising to $3, equals 5 total. Then, the strategy is calculated for each action, taking the individual action’s regret and dividing it against the total regret. We would be met with a strategy profile of 0% fold, 60% call, 40% raise to $3, and 0% raise to $6 . Naturally, good actions are rewarded and poor decisions are punished. Some structure will begin to rise in the results, with obvious results such as aces or kings being played aggressively. From this article by GTO Wizard \ 2\ reference-range-morphology there is a picture full credit to them of some peculiar hands being played aggressively alongside our typical ‘top tier’ hands. The algorithm will find weird pockets of hands that have properties that make them good enough to play aggressively as bluffs. As a human, you may say things such as “well… if I hold a jack the opponent is less likely to have one, so we can play aggressively ” to make sense of the algorithm. You can apply these concepts in game, but the solver finds them mathematically. Discounting The last part of the algorithm is the D in DCFR, which refers to discount . The algorithm can learn incorrect biases very early on in the training cycle, which can take a very long time to train out. By discounting earlier runs, it can help mitigate a scenario with a large regret dominating future strategies, such as an initial 500,000 regret accumulation for a check and 1 regret for raising $3. The discounting is applied after each iteration, with multiple variables for calculating decay. The paper describing the algorithm \ 1\ reference-dcfr is linked at the bottom of the page. Transformer Models Author’s note: I am not an AI researcher, and taught myself the concepts listed below using the internet and AI. If anything is incorrect or misstated - feedback is appreciated Think back earlier to the description of the hand in the Las Vegas casino. Over time, you realize there are patterns in optimal strategy, and there are certain opportunities where bluffing your hand and playing aggressively tends to pay off. These patterns emerged inside of DCFR, and can be learned to obtain a personal GTO-like strategy. If a human is able to learn these strategies, so can a transformer model. Although this may not be the most optimal way to build an AI to play poker, it’s fun and an excellent educational experience. One of the most common phrases heard in AI-related debates is that an LLM is a next token predictor. While that’s technically true, it’s an incredibly reductive take that is often used in the context of downplaying the power of transformers. It’s meant to diminish the technology into a fancy version of autocomplete on the iPhone, with no real reasoning abilities. A token the tip of an iceberg, a symbol mapped to a vector called an embedding . As it flows through the layers of the model, it becomes a contextual hidden state, and certain neurons light up based on the context provided by the other tokens. NashGPT Implementation For NashGPT, a small token set was defined alongside a distribution of the probability of actions represented as tokens used for the model’s training. We start with defined