Skip to content

GPU backend: failure-path hardening + tests (sticky-error fix, cached-tensor contract, fault-injection hook)#338

Open
noobdev-ph wants to merge 1 commit into
JustVugg:devfrom
noobdev-ph:feat/gpu-backend-hardening
Open

GPU backend: failure-path hardening + tests (sticky-error fix, cached-tensor contract, fault-injection hook)#338
noobdev-ph wants to merge 1 commit into
JustVugg:devfrom
noobdev-ph:feat/gpu-backend-hardening

Conversation

@noobdev-ph

Copy link
Copy Markdown

Summary

The vendor-neutral half of #112, rebuilt against dev as requested β€” the smallest version that does one thing: failure-path hardening for backend_cuda.cu, with tests your CI compiles and your hardware can execute.

Three changes (2 files, +87/βˆ’4):

  1. Sticky runtime error β€” a real bug, found by the new tests: a failed allocation leaves the last-error state set, so the next healthy launch's cudaGetLastError() check reports out of memory and permanently disables a good tensor. One failed upload could cascade into disabling valid GPU tensors. cuda_ok() now consumes the error on its failure path; regression-covered.
  2. Upload check-order: cached device tensors are now callable when the caller's host pointers are stale/NULL (the CUDA_RELEASE_HOST slot lifecycle). API-contract hardening, pinned by a 64Γ— sustained-reuse test β€” stated plainly: the current engine reaches released tensors via direct handles, so this is defensive, not a measured regression fix.
  3. COLI_GPU_FAIL_AFTER=N fault hook: all 19 compute entry points report failure after N successes (unset = zero effect, uploads/queries never gated). This is what lets the repair machinery be tested: with N=0 on GLM-5.2, every GPU call fails, every released expert rematerializes via expert_host_ensure, and generation completes coherently. It also surfaced two behaviors worth knowing: MTP speculation disengages entirely under total GPU failure (graceful but silent β€” maybe worth a log line), and outputs are deterministic given a frozen .coli_usage (pin membership feeds grouped-path selection, so runs diverge as the learning cache evolves β€” expected, but subtle when comparing runs).

Validation

  • make -C c check (CPU untouched)
  • Tests executed on AMD RX 9070 XT via the companion HIP PR's compat header (identical vendor-neutral test source) β€” all pass, 5/5 repeat runs
  • Your engine-cuda-syntax CI job compiles both files
  • make cuda-test on NVIDIA hardware β€” this is the run only you can do, and it completes the verification matrix

Compatibility

  • Default CPU build dependency-free, no engine (glm.c) changes at all
  • No model files, binaries, or artifacts

Companion PR (independent, either merges first): the HIP single-source port.

Three vendor-neutral fixes to backend_cuda.cu, each with test coverage:

1. Upload check-order: a cached device tensor is now usable when the
   caller's host pointers are stale or NULL. CUDA_RELEASE_HOST slots
   null their host pointers after upload; the current engine reaches
   those tensors through direct handles (coli_cuda_expert_mlp etc.), but
   any caller going through coli_cuda_matmul/tensor_upload with a cached
   tensor β€” as matmul_qt does for QT tensors β€” hits the !weights check
   before the cached-tensor branch and fails spuriously. This hardens
   the API contract rather than fixing a measured regression; the
   contract is pinned by a 64x sustained-reuse test.

2. Sticky runtime error (real bug, test-caught): a failed allocation
   left the last-error state set, so the NEXT healthy launch's
   cudaGetLastError() check reported 'out of memory' and disabled a
   perfectly good tensor. cuda_ok() now consumes the error on the
   failure path; regression-covered.

3. COLI_GPU_FAIL_AFTER=N test hook: every GPU compute entry point (19
   total: matmul, expert mlp/group, shared mlp, attention ops, pipe ops)
   reports failure after N successful calls, so the engine's CPU
   fallbacks and expert_host_ensure rematerialization can be exercised
   end-to-end without real hardware faults. Unset = zero effect;
   uploads/queries are never gated. Validated on GLM-5.2: total failure
   (N=0) completes coherently with every released expert rematerialized.

Tests (run via make cuda-test on any CUDA GPU; vendor-neutral source):
64x sustained matmul reuse after host pointers are freed; upload from a
scribbled-and-freed temporary; five graceful upload-failure cases with
stats-integrity assertions; healthy-launch-after-failed-alloc (the
sticky-error regression); fault-hook on/off restore.

Verified on AMD RX 9070 XT via the companion HIP PR's compat header
(same test source); a make cuda-test run on NVIDIA hardware would
complete the matrix.
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.

1 participant