Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement accumulator refresh table #5183

Closed
wants to merge 24 commits into from

Conversation

gab8192
Copy link
Contributor

@gab8192 gab8192 commented Apr 20, 2024

For each thread, keep a list of AccumulatorRefreshEntry, one for each possible king square.
An AccumulatorRefreshEntry contains the bitboards to represent the pieces of a position, and an accumulator.
When the accumulator needs to be refreshed, instead of filling it with biases and adding every piece from scratch, we...

  1. Take the AccumulatorRefreshEntry associated with the new king bucket
  2. Calculate the features to activate and deactivate
    (from differences between bitboards in the entry and bitboards of the actual position)
  3. Apply the updates on the refresh entry
  4. Copy the content of the refresh entry accumulator to the accumulator we were refreshing
  5. Copy the bitboards from the position to the refresh entry, to match the newly updated accumulator

I believe the structure of this new feature isn't implemented very well and needs a refactoring.

Credits to Luecx/Finny, who originally came up with this idea.

Results at STC:
https://tests.stockfishchess.org/tests/live_elo/662301573fe04ce4cefc1386

No functional change

@vondele vondele requested a review from Sopel97 April 20, 2024 20:03
@gab8192 gab8192 force-pushed the finny-tables branch 4 times, most recently from a02661a to 0712cab Compare April 20, 2024 20:32
@FauziAkram
Copy link
Contributor

For future reference.
LTC results: https://tests.stockfishchess.org/tests/view/66230f243fe04ce4cefc1490

src/nnue/nnue_accumulator.h Outdated Show resolved Hide resolved
src/nnue/nnue_feature_transformer.h Outdated Show resolved Hide resolved
src/nnue/nnue_feature_transformer.h Outdated Show resolved Hide resolved
src/nnue/nnue_accumulator.h Outdated Show resolved Hide resolved
src/nnue/nnue_accumulator.h Outdated Show resolved Hide resolved
src/nnue/nnue_feature_transformer.h Outdated Show resolved Hide resolved
src/nnue/nnue_feature_transformer.h Outdated Show resolved Hide resolved
src/search.cpp Outdated Show resolved Hide resolved
src/nnue/network.h Outdated Show resolved Hide resolved
// When we are refreshing the accumulator of the big net,
// redirect to the version of refresh that uses the refresh table.
// Using the cache for the small net is not beneficial.
if constexpr (HalfDimensions == Eval::NNUE::TransformedFeatureDimensionsBig)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking it might make more sense to decide whether to use the cache at the callsite, and here just check for nullptr. This part of the code shouldn't even know what a big net is

Copy link
Member

@Disservin Disservin Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I am not a fan of having different behaviour inside the feature transformer for different network sizes, but I'd keep that as is for now since we've been testing the current version on fishtest right now and I think it is somewhat time to get it into master. I can take a look at that later again.

@Disservin Disservin added the to be merged Will be merged shortly label Apr 24, 2024
@Disservin Disservin closed this in 49ef4c9 Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants