Lobsters - 02 Dec 2026

Page 2 of 3

- buying Prismatic Shard is banned (I did not implement the other card colours, with my apologies to the Shard fans).

There are different options for what algorithm to use when performing the search. They all use the network's outputs to guide the search, but differ in how they use the outputs to decide what move to explore next. AlphaZero uses PUCT, but Amber Eye uses Gumbel AlphaZero. The implementation details of the algorithms are not very important to describe here; the main benefits of using Gumbel search are that it empirically performs better than PUCT at playing Slay the Spire at equal search budgets, and that Gumbel search makes a much more favourable tradeoff between exploration and playing strength.

For PUCT to work well in AlphaZero, a significant amount of exploration noise has to be added to the network predictions, in addition to randomly sampling some moves from the policy instead of taking the top choice. With Gumbel search, I found it was sufficient to only apply the more modest Gumbel noise to the search and no sampling was needed.

Gumbel search also scales down to much lower search budgets than PUCT. To generate policy targets, AlphaZero used the distribution of visit counts from search, which is very noisy for low visit counts. Gumbel search also uses the value network's output to construct the policy target, reducing its variance.

To accurately model ideal Spire, the search must also not reveal or exploit hidden information, e.g. draw pile order, future enemy intents, or relic queue order. However, the search must still be able to progress past actions with random outcomes, or else it would barely be able to look ahead.

A simple way to address this is to sample random outcomes. When stepping the simulator, it flags if any hidden information was revealed by this step, which can be done by checking if any of the RNGs were used. Some hidden information, like draw order or intent under Runic Dome, is randomized at an earlier step (e.g. when reshuffling the deck), so these cases are also detected and resampled. When a step reveals hidden information, its RNG is rerolled to sample a different random outcome consistent with the prior game state.

If we performed a fresh reroll every time a step was visited, the search would never be able to progress past that step. Instead, the search adopts double progressive widening for random outcomes: it puts a limit on the number of resamples per move which slowly grows as the move gets revisited. If the move is visited when the random sample count is already at the limit, the search proceeds deeper into one of the existing random outcomes rather than generating a new one.

Playing Defend \(\rightarrow\) Strike or Strike \(\rightarrow\) Defend results in the same position2, but a regular tree search would treat these lines as completely distinct, wasting computation searching the same position in two different branches and adding noise from the two branches' differing random outcomes. Monte-Carlo Graph Search addresses this by merging the identical positions and searching a DAG instead of a tree. In the case of Spire, cycles are possible in the position graph (e.g. playing a "useless" infinite), so we must additionally detect and cut these cycles when implementing the graph search.

Because of the complexity of its implementation, MCGS was not used in self-play games. However, the benefit of MCGS grows as the search budget increases, so it was implemented to play the sample games. Empirically, applying MCGS to Spire effectively cuts the average branching factor by about 1.2\(\times\). This has a modest benefit at the search budget used in self-play, but compounds to about a 15\(\times\) effective compute advantage versus tree search at the 262k-position search budget used in the sample.

Spire positions can roughly be divided into combat and non-combat states (commonly referred to as "micro" and "macro", respectively). The consequences of in-combat decisions are mostly local to that combat, in that playing better lines saves HP for that fight and leads to a better post-fight position. It is tempting, then, to also perform this division on the model side, and have separate networks handle combat and non-combat positions. However, micro and macro are more intertwined than they look at first glance. Resource use (potions), meta-scaling items (Feed), and relic setup (Incense Burner) obviously carry over to future combats, but other combat decisions can depend more subtly on the overall game state. For example, one might choose to play a higher-variance line which loses more HP on average if it opens a chance of highrolling and being able to path to an extra elite. Because of this, optimally playing combats requires planning beyond just the combat.

For this reason, I consider it very important that a single network evaluates all game states. A single network better applies the bitter lesson; it can learn for itself how micro interacts with macro, avoiding the need to figure out how to stitch the networks together.

Amber Eye's network primarily consists of a transformer which processes the game state. Most people's experience with transformers is with large language models, and so they are commonly associated with next-token prediction, but this is a bit of an oversimplification. At a high level, a transformer is a type of neural network which can process variable-size sets of features and which is very effective at learning interactions between them. To enable this, the features are represented by points in an abstract high-dimensional embedding space.

More specifically, the data follows this computation path:

- The game state is encoded into tokens, which are points in the high-dimensional latent space. For example, unique cards, event choices, relics, and enemies are encoded into one token each in the same embedding space. Roughly speaking, the tokens can be thought of as the model's scratch space, and part of its job is to learn how to organize the scratch space well so that similar concepts are close together. For example, the model may learn to place "good earlygame damage card" along one of the dimensions, or whatever other concept that helps it predict.

- The set of tokens passes through a sequence of transformer blocks, each consisting of an attention and feed-forward layer.

Each transformer block modifies the token sequence.

- The attention operator is the famous one. It allows tokens to exchange information with each other (for example, comparing offered cards with the cards in your deck in a card reward screen, or your block cards in hand versus incoming damage).

- The feed-forward operator has been studied since before machine learning existed. Its role in the transformer is roughly to remember relevant facts (for example, retrieving what cards synergize well, or recalling Defend blocks 5). It projects each token into a higher-dimensional space, applies a nonlinear activation function, then projects it back to the token space.

- After passing through the transformer layers, the tokens capture high-level interactions between the features. The information from the tokens is then extracted by the heads, where the tokens are projected to produce the final predictions for value and policy.

To process the game state in the transformer, its information must first be preprocessed into tokens. Each token's inputs consist of three parts:

- the token type (run metrics, player metrics, player status effects, monster, card, relic, potion, option, map);

- categorical features, up to 4 different IDs associated with the token e.g. card, relic, monster type, monster intent, card zone;

- numerical features, up to 64 floats for other numerical information (mostly for run and player tokens).

The token then passed into the transformer is the sum of its type embedding, its categorical embeddings, and a type-specific projection of its features, all LayerNormed. A game state has an average of about 40 tokens, mostly from cards and relics.

A game like chess easily admits a fixed-size action space (source square \(\times\) target square). In Spire, many types of action are possible, and are contextual on the game state. Thus, we also prepare a list of legal actions as an input, and the policy is directly computed over this list. An action can be represented by the following:

- the action type (play card, use potion, end turn, take reward, buy shop item, visit map node, etc.);

- the source token (card being played, potion used, reward taken, item bought, etc.);

- the target token (targeted monster, potion offered to Ranwid, etc.); and

- up to 8 contextual features (e.g. if an attack is lethal, HP from event option). These were probably not necessary as the information is already encoded in the source and target tokens.

The action list is used by the model to directly fetch the source and target tokens from the transformer's output and compute the hidden state for the policy. More precisely, for each action \(a\) we compute

\[e_a = \text{emb}(k_a) + W_s\, h_{s_a} + W_t\, h_{t_a} + W_f\, f_a + W_c\, c\]

where \(\text{emb}(k_a)\) is the action kind embedding, \(h_{s_a}, h_{t_a}\) are the source and target output tokens respectively, \(f_a\) is the vector of action features, \(c\) is a pooled summary of other tokens, and the \(W\)s are learned weight matrices. If there is no source or target for an action, a "none" embedding is used instead. The vector \(e_a\) is then projected by a MLP to a logit, and the policy is obtained by taking the softmax of these logits over the action list.

This setup has the advantages of only needing to compute the policy over legal actions, and automatically fetching the relevant tokens in the policy computation.

The heads convert the processed token stream into the value and policy predictions. Apart from the policy heads, each head consumes a summary consisting of the encoded Run token plus the average of other tokens processed by a shared summary MLP. Each head is a two-layer MLP processing this summary to produce its prediction. The prediction task and role of each head is discussed in the following section.

In a pure AlphaZero setup, only the recorded outcome of the game and search policy would be used to train the network, meaning we would only extract 1 bit of information for the value head to train on per game, a terrible ratio given the tens of thousands of network evaluations spent to play the game. However, we can make use of more information from the game to better train the network's internal representation.

The network has the following heads:

- The policy head, as described above.

- A soft policy head, which is trained to predict a flattened version of the search target. This technique is adapted from KataGo. For the policy target distribution \(\mathbf p\), the soft policy head predicts \(\mathbf p^{1/4}\). The policy target tends to be very spiky, putting almost all its weight on the top move. By predicting the flattened policy target the model is forced to learn more about the relative ranking of the non-top moves. The soft policy is only used in training.

- The outcome head, predicting the run outcome. Instead of just predicting win/loss, the outcome head also predicts the floor on which the run loses. By training this classification task, more signal from the game is able to be used.

- The current-floor HP head, predicting the HP at the end of this floor, as a classification task over each HP value capped at 255.

- The per-floor HP head, predicting the HP for each floor from the current floor until the end of the run. Unlike the current-floor HP head, the per-floor HP head predicts the HP value as a scalar, as using the same classification task would make the head too large.

At the start of training, playing games to purely maximize the network's predicted win chance quickly collapses into a state of learned helplessness. The network is weak to start and cannot win any games, so it quickly learns to predict that all states are completely lost and never improves. Instead, we can make use of the other prediction heads to nudge the engine in a direction that makes progress until it is able to win. Formally, we define a utility function for the position based on the heads' predictions and ask the engine to maximize the utility instead of the win chance.

In the beginning, the utility was defined in the following way. Define the floor progress reward for a position \(s\) as

\[F(s) = \frac1{57} \left(\sum_{f=1}^{56} f \cdot P(\text{die on floor } f \mid s)\right) + P(\text{win} \mid s).\]

Effectively, \(F(s)\) gives the self-play agent a reward of \(1/57\) when it advances a floor or wins. The probabilities are estimated from the model's outcome head. Similarly, we can define the HP reward as

\[H(s) = \frac{1}{56}\left((\text{floor}(s)-1) + \sum_{f=\text{floor}(s)}^{56} \frac{\mathbb E[\text{HP on floor } f \mid s]}{255}\right),\]

which rewards the model for preserving HP. The utility function initially used was \(U(s) = F(s) + H(s)\).

The model made consistent progress under this utility and won its first game after about 460 000 games played and 1.5 hours of training. I was quite surprised that only these terms were sufficient, as long fights still don't get any intermediate signal from the reward, and long-term objectives like keys are hard to learn about.

After a few more hours, the model reached significant winrate under this utility. I then updated the utility to \(P(\text{win} \mid s) + 0.25H(s)\) for out-of-combat states and \(F(s) + 0.5H(s)\) for in-combat states. Empirically, these improved the performance in self-play, and the changes can be interpreted as allowing focusing on building decks for the endgame in out-of-combat states. I expected to eventually be able to entirely remove the other shaping terms and purely optimize for \(P(\text{win} \mid s)\), but this utility form continued to perform better even at the end of training. One possible interpretation of this fact is that the model's estimation of \(P(\text{win} \mid s)\) has some model error associated with it, and the other shaping terms help mitigate the error, even though they introduce a bias which does not perfectly align with optimizing for winrate.

Because training data is generated via self-play, training samples originating from the same game are correlated with each other. This presents challenges for training the value network. Samples from the same game all have the same outcome, so the value network can quickly learn to memorize properties of the game (deck and relics) and use that to predict the game's result, overfitting instead of properly generalizing.

To address this, first we apply playout cap randomization as in KataGo. Moves are selected with probability \(p = 0.25\) to undergo a full search with a larger number of simulations, and the remainder of the moves are played using a fast search with much fewer simulations. Only the full moves are used in training. This increases the number of games that can be played per unit of compute, as we can spend less compute on the fast searches, thus increasing the diversity of value labels that can be generated in the same amount of time. While the overall production of training samples is reduced, the tradeoff is worth it to gain more value labels. The fast moves also cost self-play strength, but this is also partially mitigated by not applying exploration noise to them. Empirically, using a fast move budget \(1/8\) the size of the full move budget cost roughly 1 percentage point of winrate.

Playout cap randomization partially mitigates the memorization problem, but due to Spire's longer game length, significant memorization is still observed at \(p = 0.25\). \(p\) could be lowered even further to reduce it, but this increases the proportion of compute spent on fast moves which don't generate training data. This tradeoff becomes quite unfavourable for small \(p\). Thus, I altered the value label itself as further mitigation.

The value labels were redefined as a combination of the search result and an exponential weighted average of future moves' search outcomes. This injects diversity into the value labels to reduce overfitting, although the labels from positions close to each other in the sequence of moves are still correlated. It also corresponds well to the game itself, where the long-horizon outcome is noisy and dependent on future random rolls, so it makes sense to downweight learning from outcomes far in the future.

This label definition also has the downside of having a low weight on the real outcome, so the value estimate can remain persistently miscalibrated. Notably, the engine significantly underestimates its own winrate, and the underestimation increases in positions earlier in the game (where the end outcome is more distant). The gap is 10 percentage points or more at the start of the game. However, as long as the engine is able to score better positions as higher value, the actual numerical value of the predicted winrate is irrelevant.

If the network learns that certain choices are bad early on and starts never picking them, it will never get the signal it needs to correct misjudging these choices. For example, midway through the training run, I noticed that the network rated Apotheosis as the worst card in the game by far, because it never picked it and reconsidered. Typical exploration strategies like sampling from the policy or adding uniform random noise still barely make the choices that need to be sampled, and had a large cost to play strength. To address this, I created a domain-specific exploration scheme inspired by the Quantile Balancing technique used by Kimi K3.

For choices like card picks, event choices, Neow bonuses, and relics, we first set a target percentage of games that each choice should appear in (I used 1-3%). For items below the target, we can keep track in the gamelog of how far they are below the choice actually taken (in terms of policy logits). We can then determine the bias that needs to be added to each of the items below the target such that the target pick count is reached. In the search, the below-target items are forced to be kept as a final candidate, any search that includes a below-target item becomes a full search, and the bias is added after search completes to force the picking of unexplored items at roughly the target rate.

Instead of a hard threshold like in Quantile Balancing, the boosted item is picked with probability

\[\min(1,\,c\cdot\exp(-m/T)),\]

where \(c\) is a parameter computed per item by binary search to hit the target pick rate, \(m\) is the gap between the boosted item and the top pick after the bias is added, and \(T = 4\) is a temperature parameter. Effectively, situations where the item is closer to being the top pick are more likely to be picked under this scheme, but situations with larger gaps are also chosen occasionally to have more variety in the picks.

The forced picks successfully corrected the bias on items like Apotheosis, and only affected ~0.2% of moves with a modest play strength cost of ~3 percentage points.

Next page | Previous page | More Lobsters | Headlines

Original: https://8e9f.github.io/amber_eye/