GPU autoencoder ignores target_true_p#85
Open
drmckay wants to merge 2 commits into
Open
Conversation
added 2 commits
July 1, 2026 15:49
The CUDA method and dispatcher lacked the target_true_p parameter that TMAutoEncoder.fit() passes, so GPU fit() raised TypeError; the body also called a non-existent .choice on the pycuda RNG. Draw target_value host-side biased by target_true_p, matching the CPU path.
prepare_X_autoencoder left the host active_output array in the tuple that produce_autoencoder_example splats into the launch, giving 14 args for a 13-arg kernel. Only active_output_gpu is a kernel argument; drop the host copy.
target_true_p
target_true_ptarget_true_p and CUDA kernel leaves padding bits uninitialised
target_true_p and CUDA kernel leaves padding bits uninitialisedtarget_true_p
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix GPU autoencoder: honor
target_true_p; drop strayencoded_XargSymptom
TMAutoEncoder(platform='GPU').fit(...)raises:The GPU autoencoder cannot run at all.
Root cause
TMAutoEncoder.fit()(andclause_precision/clause_recall) call:ClauseBank.produce_autoencoder_example(self, encoded_X, target, target_true_p, accumulation)draws
target_value = self.rng.random() <= target_true_p(biased by the feature's trueprobability) and passes it to the C kernel.
ClauseBankCudaDevice.produce_autoencoder_example(self, encoded_X, target, accumulation)has no
target_true_pparameter, so the call fails. Even the body was wrong:target_value = self.rng_gen.choice(2)— an unbiased 50/50 that ignorestarget_true_p, and.choicedoes not exist on pycuda'sXORWOWRandomNumberGenerator(it appears nowhere incurandom.py); that line never executed only because the TypeError fired first.So the GPU path was both call-incompatible and semantically different from the CPU path.
Fix (commit 1)
Mirror the CPU path. Add
target_true_pto the GPU method (and theClauseBankCudadispatcher),and draw the polarity host-side with the clause bank's seeded RNG:
The kernel already takes
int target_value, so no.cuchange is needed.target_valueis a singlehost-side branch bit per call — the CPU decides it host-side too; the in-kernel per-row sampling keeps
using the device curand RNG (
self.rng_gen.state), unchanged.A second, latent defect exposed by this fix (commit 2)
Once the
target_true_pTypeError was gone, the kernel launch failed withpack requires exactly 13 arguments:prepare_X_autoencoderreturned the hostactive_outputnumpy array as a stray 2nd tuple element, which
produce_autoencoder_examplesplats into thelaunch (
*encoded_X) — 14 args for the 13-arg kernel (prepare("PPiPPiPPiPiii")). The host arrayis not indexed anywhere on the CUDA path (only
encoded_X[-1]and the splat are used), so commit 2drops it; only the device copy
active_output_gpuis a kernel argument. Both commits are needed forthe GPU autoencoder to run at all.
Verification (RTX 3090)
Small synthetic-corpus run — 400 docs × 40 binary features (co-occurrence "topics"), 20 clauses,
T=15, s=5, accumulation=10, 500 examples, seed 42; mean
clause_precision/clause_recallover4 output targets, CPU vs GPU:
main,platform='GPU'→TypeError: ... unexpected keyword argument 'target_true_p'.this branch:
The GPU autoencoder now runs and tracks the CPU reference (non-degenerate, same precision,
comparable recall; the exact GPU recall varies run-to-run because the device curand generator is
created unseeded — a pre-existing issue). GPU wall-clock is slower on this tiny workload because
produce_autoencoder_examplelaunches a full grid but works on a single thread — addressed in afollow-up PR that parallelises the kernel's init.