Skip to content

Add uncertainty weighting to dag-preview#2412

Open
Menkib64 wants to merge 17 commits into
LeelaChessZero:masterfrom
Menkib64:uncertainty_weighting
Open

Add uncertainty weighting to dag-preview#2412
Menkib64 wants to merge 17 commits into
LeelaChessZero:masterfrom
Menkib64:uncertainty_weighting

Conversation

@Menkib64
Copy link
Copy Markdown
Contributor

@Menkib64 Menkib64 commented May 5, 2026

No description provided.

Copilot AI review requested due to automatic review settings May 5, 2026 21:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the dag-preview (dag_classic) search to support uncertainty-weighted updates by introducing an additional NN output (e) and propagating it through neural backends, caching, ONNX conversion, and the DAG search’s backup/update logic (including replacing integer visit-count semantics with floating “weight” semantics in key places).

Changes:

  • Add a new e field to NN evaluation results and plumb it through backend interfaces, memcache, CUDA/ONNX backends, and ONNX conversion/proto metadata.
  • Introduce uncertainty-weighting search parameters for dag_classic and apply the weighting transform during NN result fetch.
  • Replace/augment visit-count logic in dag_classic nodes with a floating “weight” (weight_) and update selection/backup/bounds code to use weight-based values.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/search/dag_classic/search.h Update function signatures to use weight-based “fix” parameters instead of integer visit counts.
src/search/dag_classic/search.cc Apply uncertainty-weighting transform to NN e; switch several visit-count computations/prints to float weight semantics; propagate weight through backup/bounds logic.
src/search/dag_classic/params.h Replace alias with a dag_classic SearchParams subclass exposing uncertainty-weighting options.
src/search/dag_classic/params.cc Define UCI/CLI options and defaults for uncertainty weighting and implement SearchParams.
src/search/dag_classic/node.h Add Eval::e, introduce weight_ for Node/LowNode, and convert several N-related APIs to float/weight-based forms.
src/search/dag_classic/node.cc Implement weight-based score updates and adjust debug/dot output to display weight as N.
src/neural/wrapper.cc Copy e from NetworkComputation into EvalResultPtr during evaluation.
src/neural/onnx/converter.h Add ONNX output name for error head and a selectable error_head.
src/neural/onnx/converter.cc Refactor value-head building and optionally emit an error-head output (/output/error) with sigmoid.
src/neural/network.h Add virtual GetEVal() API (default 0) for network computations.
src/neural/memcache.cc Cache and restore the new e value alongside q/d/m/p.
src/neural/backends/onnx/network_onnx.cc Detect optional output_err, store its head index, and expose GetEVal() from ONNX outputs.
src/neural/backends/cuda/network_cudnn.cc Update InputsOutputs construction signature (currently hardcoded wdl_err=false).
src/neural/backends/cuda/network_cuda.cc Add CUDA support for optional value-error head, including allocation, eval, download, and GetEVal().
src/neural/backends/cuda/layers.h Extend ValueHead to optionally load/run error-head weights.
src/neural/backends/cuda/layers.cc Implement optional error-head dense path and sigmoid output for ValueHead.
src/neural/backends/cuda/inputs_outputs.h Allocate buffers/events for error-head output when enabled.
src/neural/backend.h Extend EvalResultPtr/EvalResult to include e.
src/neural/backend.cc Pass &result.e into computations in batch evaluation.
proto/net.proto Add output_err to OnnxModel metadata.
meson.build Ensure new dag_classic params.cc is compiled when dag_classic is enabled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/search/dag_classic/search.cc
Comment thread src/search/dag_classic/node.cc Outdated
Comment thread src/search/dag_classic/params.h Outdated
Comment thread src/search/dag_classic/node.h
Comment thread src/search/dag_classic/node.h Outdated
@Menkib64
Copy link
Copy Markdown
Contributor Author

Menkib64 commented May 6, 2026

This is @daniel-monroe's uncertainty weighting with a few changes.

The most important change is replacing visit count (N) with weight (W). I thought about this change to keep data structure within 64 byte limit. It allocates a few extra nodes towards uncertain branches. Visit counts are stored as a double precision float. It is used as a 32 bit float when calculating visit distribution.

The minor search focus change tested as a positive change using many different time controls and search parameters:
https://bench.lczero.org/test/901/
https://bench.lczero.org/test/902/
https://bench.lczero.org/test/903/
https://bench.lczero.org/test/907/

This branch backports changes from TCEC branch. I was trying to merge this for FRD event but there was issues getting it work before deadline. Validation test for this branch is scheduled after 907 completes:
https://bench.lczero.org/test/922/

I'm still going to run a test if logistic function would improve the error output conversion formula. Tune is scheduled after 907 completes:
https://bench.lczero.org/tune/923/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants