Skip to content

neural: shared CPU training substrate + NeuralFunctionApproximator#498

Merged
Krilliac merged 1 commit into
Workingfrom
claude/evaluate-gpu-acceleration-hlh2X
Apr 18, 2026
Merged

neural: shared CPU training substrate + NeuralFunctionApproximator#498
Krilliac merged 1 commit into
Workingfrom
claude/evaluate-gpu-acceleration-hlh2X

Conversation

@Krilliac

Copy link
Copy Markdown
Owner

Adds CpuNeuralTraining (backward pass + Adam/SGD + MSE/L1/Huber) and the NeuralFunctionApproximator facade so any CPU-heavy subsystem can opt in to a learned approximation. Refactors NeuralTextureCompressor off its inline SGD/backprop loop and replaces NeuralRadianceCache::Update's finite-diff MLP search with real analytical backprop + hash-grid input-gradient flow.

  • CpuNeuralTraining.{h,cpp}: Trainer class, gradient check, losses
  • NeuralFunctionApproximator.{h,cpp}: Configure/TrainOffline/TrainIncremental
  • NeuralWeights: .nnw bumped to v2 with optional Adam/SGD-momentum trailer (v1 files still load as optimizer.kind == None)
  • NRC: persistent Adam state across frames, one upload per batch instead of one per weight perturbation; ~100x faster training loop
  • NTC: TrainBlock reduced from ~130 LOC of inline backprop to ~40 LOC using the shared core + Adam
  • 13 new tests covering analytical-vs-numerical gradient check, Adam + SGD+momentum convergence on XOR, sine fit, NFA save/load round-trip, .nnw v1/v2 compat, NRC loss decreases

Adds CpuNeuralTraining (backward pass + Adam/SGD + MSE/L1/Huber) and the
NeuralFunctionApproximator facade so any CPU-heavy subsystem can opt in to
a learned approximation. Refactors NeuralTextureCompressor off its inline
SGD/backprop loop and replaces NeuralRadianceCache::Update's finite-diff
MLP search with real analytical backprop + hash-grid input-gradient flow.

- CpuNeuralTraining.{h,cpp}: Trainer class, gradient check, losses
- NeuralFunctionApproximator.{h,cpp}: Configure/TrainOffline/TrainIncremental
- NeuralWeights: .nnw bumped to v2 with optional Adam/SGD-momentum trailer
  (v1 files still load as optimizer.kind == None)
- NRC: persistent Adam state across frames, one upload per batch instead
  of one per weight perturbation; ~100x faster training loop
- NTC: TrainBlock reduced from ~130 LOC of inline backprop to ~40 LOC
  using the shared core + Adam
- 13 new tests covering analytical-vs-numerical gradient check, Adam +
  SGD+momentum convergence on XOR, sine fit, NFA save/load round-trip,
  .nnw v1/v2 compat, NRC loss decreases
@Krilliac
Krilliac merged commit 85cdb8a into Working Apr 18, 2026
37 of 42 checks passed
@Krilliac
Krilliac deleted the claude/evaluate-gpu-acceleration-hlh2X branch April 18, 2026 16:51
@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage (GCC + lcov)

Utils/StringUtils.h                            |18.1%   116| 0.0%  21|    -    0
Utils/Telemetry.h                              |20.6%   136| 0.0%  23|    -    0
Utils/ThreadDebugger.h                         |11.6%   199| 0.0%  23|    -    0
Utils/ThreadSafeQueue.h                        |27.5%    40| 0.0%  11|    -    0
Utils/Timer.cpp                                |19.4%    36| 0.0%   7|    -    0
Utils/Timer.h                                  | 100%     2| 0.0%   2|    -    0
Utils/TimerManager.h                           |18.6%   102| 0.0%  19|    -    0
Utils/Tween.h                                  |26.3%    38| 0.0%   6|    -    0
Utils/UUID.h                                   |43.2%    37| 0.0%  16|    -    0
Utils/Validate.h                               |    -     0|    -   0|    -    0
Utils/WineDetection.cpp                        |23.1%    39| 0.0%   9|    -    0

[/home/runner/work/SparkEngine/SparkEngine/SparkSDK/Include/Spark/]
IEngineContext.h                               |7300%     1| 0.0%   1|    -    0
IModule.h                                      | 800%     1| 0.0%   1|    -    0
ServiceInterfaces.h                            | 200%     3| 0.0%   3|    -    0
Version.h                                      |    -     0|    -   0|    -    0

[/home/runner/work/SparkEngine/SparkEngine/Templates/EmptyProject/Source/]
GameModule.h                                   |38.9%    18| 0.0%   6|    -    0

[/home/runner/work/SparkEngine/SparkEngine/Templates/FPSStarter/Source/]
GameModule.h                                   |36.0%    25| 0.0%   7|    -    0

[/home/runner/work/SparkEngine/SparkEngine/Templates/MultiplayerArena/Source/]
GameModule.h                                   |34.6%    26| 0.0%   7|    -    0

[/home/runner/work/SparkEngine/SparkEngine/Templates/PlatformerKit/Source/]
GameModule.h                                   |25.0%    32| 0.0%   7|    -    0

[/home/runner/work/SparkEngine/SparkEngine/Templates/RPGStarter/Source/]
GameModule.h                                   |37.5%    24| 0.0%   8|    -    0
================================================================================
                                         Total:|30.5% 35191| 0.0%  6k|    -    0

Per-Subsystem Coverage

Subsystem Lines Hit Coverage Threshold Status
AI 3716 942 25.3% 35%
Animation 905 277 30.6% 35%
Audio 0 0 0% 30%
Camera 0 0 0% 40%
Core 4877 2920 59.9% 40%
ECS 426 213 50% 40%
Editor 7413 3046 41.1% 25%
GameModules 6621 3230 48.8% 30%
Graphics 17891 9063 50.7% 30%
Networking 3554 2351 66.2% 35%
Physics 0 0 0% 35%
Scripting 283 80 28.3% 30%
Utils 9780 6050 61.9% 60%

Total: 50.8% (28172/55466 lines)

@github-actions

Copy link
Copy Markdown
Contributor

❌ CI Error Report

Failed jobs: clang-tidy, macos-Debug-OpenGL, macos-Release-Metal, macos-Release-OpenGL, windows-vs2022-Release
Errors: 1 | Test failures: 4 | Test warnings: 15 | Compiler warnings: 0

Build Errors

Other errors (1)
clang++: error: linker command failed with exit code 1 (u e -v to  ee invocation) [macos-Debug-OpenGL, macos-Release-Metal, macos-Release-OpenGL]

Test Failures

Test Jobs
1/1 Test #1: SparkEngineTests .................***Failed 15.11 sec windows-vs2022-Release
::warning title=Flaky test: Integration_NetworkingECS_ReplicationLatencyJitterPredictionReconciliation::Integration_N... windows-vs2022-Release
[ FAILED ] Training_GradientCheckHuber (1.5ms, 1 assertions) windows-vs2022-Release
0% tests passed, 1 tests failed out of 1 windows-vs2022-Release

⚠️ Test Warnings (Known Flaky)

These tests are registered as known flaky and do not block the build:

Test Jobs
[17:33:26.008] [TID:3288] [WARN ] [Network ] RCON unknown command: nonexistent_cmd (DedicatedServer.cpp:573) windows-vs2022-Release
[17:33:26.023] [TID:3288] [WARN ] [Network ] NetBuffer::ReadUint8 — buffer overrun at pos 1 (size=1) (NetworkBuffer.c... windows-vs2022-Release
[17:33:26.043] [TID:3288] [WARN ] [AI ] BuildNavMeshWithRecast: empty geometry (RecastDetourBackend.cpp:35) windows-vs2022-Release
[17:33:26.043] [TID:3288] [WARN ] [AI ] NavMeshBuilder: Recast build failed, falling back to triangle-soup builder (N... windows-vs2022-Release
[17:33:26.043] [TID:3288] [WARN ] [Audio ] XAudio2 backend requested but no AudioEngine provided, falling back to Nul... windows-vs2022-Release
[ OK ] MaterialHandle_FindByN[17:33:26.061] [TID:3288] [WARN ] [Graphics ] No graphics backend available — falling ba... windows-vs2022-Release
[17:33:26.061] [TID:3288] [WARN ] [Graphics ] No graphics backend available — falling back to NullRHIDevice (headless... windows-vs2022-Release
[17:33:26.065] [TID:3288] [WARN ] [Editor ] Cannot host: userName is empty. (CollaborativeEditSession.cpp:454) windows-vs2022-Release
[17:33:26.065] [TID:3288] [WARN ] [Editor ] Already connected. (CollaborativeEditSession.cpp:459) windows-vs2022-Release
[17:33:26.068] [TID:3288] [WARN ] [Editor ] BroadcastEdit rejected: nodeId is empty. (CollaborativeEditSession.cpp:1108) windows-vs2022-Release
[17:33:26.068] [TID:3288] [WARN ] [Editor ] BroadcastEdit rejected: sourceEditor is not set. (CollaborativeEditSessio... windows-vs2022-Release
[17:33:26.069] [TID:3288] [WARN ] [Editor ] SetLocalSelection rejected: nodeId exceeds 255 chars (length=300). (Colla... windows-vs2022-Release
[17:33:31.637] [TID:3288] [WARN ] [Network ] Connection rejected for pending client 5: server full (4/4) (NetworkConn... windows-vs2022-Release
[17:33:31.638] [TID:3288] [WARN ] [Network ] Connection rejected for pending client 5: server full (4/4) (NetworkConn... windows-vs2022-Release
[17:33:31.639] [TID:3288] [WARN ] [Network ] Invalid packet magic 0x6A0E5CB3 (expected 0x5350524B) (NetworkManager.cp... windows-vs2022-Release

Updated: 2026-04-18T17:34:31Z — this comment is updated in-place, not duplicated.

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.

2 participants