Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cpp/configs/gtp_example.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ searchFactorWhenWinningThreshold = 0.95
# ------------------------------
# These only apply when using the TENSORRT version of KataGo.

# Transformer trunks use NHWC by default. Set this to false only after benchmarking
# the particular GPU and TensorRT version.
# trtTransformerNHWC = true

# For one GPU: optionally uncomment this option and change if the GPU to
# use is not device 0.
# trtDeviceToUse = 0
Expand Down
4 changes: 2 additions & 2 deletions cpp/neuralnet/onnxmodelbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ using namespace std;
namespace {

// Builder that accumulates ONNX nodes and initializers into a single GraphProto, handing back
// tensor names as it goes. Tensors are float32; the trunk runs NCHW by
// default, or channel-last NHWC when transformerNHWC is set (see buildBlockStack / buildConv).
// tensor names as it goes. Tensors are float32; transformerNHWC selects a channel-last NHWC trunk
// instead of NCHW (see buildBlockStack / buildConv).
struct Builder {
onnx::GraphProto* graph;
int nnXLen;
Expand Down
12 changes: 6 additions & 6 deletions cpp/neuralnet/trtbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ ComputeContext* NeuralNet::createComputeContext(
ConfigParser& cfg) {
(void)gpuIdxs;
(void)logger;
(void)loadedModel;

ComputeContext* context = new ComputeContext();
context->nnXLen = nnXLen;
Expand All @@ -105,11 +104,12 @@ ComputeContext* NeuralNet::createComputeContext(
// nvonnxparser (the default). trtDisableOnnx=true falls back to the hand-built ModelParser, which
// supports convnets only (transformer models will error in createComputeHandle).
context->useOnnx = !(cfg.contains("trtDisableOnnx") ? cfg.getBool("trtDisableOnnx") : false);
// ONNX transformer emitter layout. Default is NCHW (genuine channel-major attention/FFN): benchmarks
// show it matches or slightly beats the NHWC bubble path at the saturated throughput operating point
// KataGo runs at, and it's the simpler graph. trtTransformerNHWC=true opts into the NHWC path (whole
// trunk channel-last with NCHW<->NHWC conversions around it), which wins on single-stream latency.
context->transformerNHWC = cfg.contains("trtTransformerNHWC") ? cfg.getBool("trtTransformerNHWC") : false;
// Transformer trunks default to NHWC, which benchmarks at least as fast as NCHW across tested GPUs
// and TensorRT versions. Explicit false remains available for hardware-specific tuning. Normalize
// convnets to false since the ONNX builder ignores this setting for models without transformers.
context->transformerNHWC =
(cfg.contains("trtTransformerNHWC") ? cfg.getBool("trtTransformerNHWC") : true) &&
NeuralNet::getModelDesc(loadedModel).hasAnyTransformerBlocks();
// Debugging: if set, the ONNX-emitter path dumps the emitted ONNX model and the built engine's
// per-layer info (precision/format/tactic, via a detailed-profiling build + IEngineInspector) into
// this directory. Files are disambiguated by board size, FP16/FP32, and exact/max NN-length so the
Expand Down