Reset shouldSaveState after use; clamp numThreads to corpus size - #223
Open
pangwangshu wants to merge 1 commit into
Open
pangwangshu wants to merge 1 commit into
pangwangshu wants to merge 1 commit into
Conversation
Two small, independent robustness fixes from mimno#219. 1. Correctness finding mimno#5: shouldSaveState is never reset, so saveSampleInterval is a dead knob. collectAlphaStatistics() arms WorkerCallable to collect docLengthCounts/topicDocCounts for the next call(), but nothing ever cleared it back to false -- WorkerRunnable and DMRCallable both do this at the end of their run; WorkerCallable, which replaced WorkerRunnable and is what ParallelTopicModel actually uses, never did. Once hyperparameter optimization starts collecting, every subsequent call() (i.e. every iteration) kept accumulating into those histograms instead of only every saveSampleInterval-th one, silently turning the intended thinned samples into a long, highly autocorrelated run. Now reset at the end of call(), after the armed pass has used it. 2. Robustness finding: numThreads > numDocs silently serializes the run. estimate() computed docsPerThread = data.size() / numThreads, which is 0 whenever numThreads exceeds the corpus size, so every thread but the last got zero documents while the last took the entire corpus. Output was still correct (empty workers contribute all-zero counts to the merge), but with all parallelism lost and numThreads full copies of typeTopicCounts allocated regardless. estimate() now clamps numThreads to the corpus size, with a log warning, before any of that allocation happens. Added TestWorkerCallable#shouldSaveStateResetsAfterOneCall (arms the flag, calls call() twice, confirms the histogram total after the second, unarmed call() matches the first instead of doubling) and TestParallelTopicModelNumThreadsGuard (trains a 3-document corpus with numThreads=16, confirms numThreads is clamped to 3 and the run still produces valid topic assignments). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This branch has not been deployed
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.
Part of #219 — correctness finding #5 and the robustness finding about
numThreads > numDocs. Two small, independent fixes.1.
shouldSaveStateis never reset, sosaveSampleIntervalis a dead knob.collectAlphaStatistics()armsWorkerCallableto collectdocLengthCounts/topicDocCountsfor the nextcall().WorkerRunnableandDMRCallableboth clear the flag at the end of their run;WorkerCallable— the class that replacedWorkerRunnableand the oneParallelTopicModelactually uses — never did. Once hyperparameter optimization starts collecting, every subsequent iteration kept accumulating instead of only everysaveSampleInterval-th one, silently turning the intended thinned samples into one long, highly autocorrelated run. Now reset at the end ofcall(), after the armed pass has used it.2.
numThreads > numDocssilently serializes the run.estimate()computeddocsPerThread = data.size() / numThreads, which is 0 whenevernumThreadsexceeds the corpus size, so every thread but the last got zero documents while the last took the entire corpus. Output stayed correct (empty workers contribute all-zero counts to the merge), but with all parallelism lost andnumThreadsfull copies oftypeTopicCountsallocated regardless.estimate()now clampsnumThreadsto the corpus size, with a log warning, before any of that allocation happens.Added
TestWorkerCallable#shouldSaveStateResetsAfterOneCall(arms the flag, callscall()twice, confirms the histogram total after the second, unarmed call matches the first instead of doubling) andTestParallelTopicModelNumThreadsGuard(trains a 3-document corpus withnumThreads=16, confirms it's clamped to 3 and the run still produces valid topic assignments).