Skip to content

[SPARK-58395][ML][CONNECT] Include LDA metadata in size estimates - #57589

Closed
zhengruifeng wants to merge 7 commits into
apache:masterfrom
zhengruifeng:lda-model-size-metadata-dev3
Closed

[SPARK-58395][ML][CONNECT] Include LDA metadata in size estimates#57589
zhengruifeng wants to merge 7 commits into
apache:masterfrom
zhengruifeng:lda-model-size-metadata-dev3

Conversation

@zhengruifeng

@zhengruifeng zhengruifeng commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Adds parameter metadata to DistributedLDAModel.estimatedSize while retaining its existing Arrow-data estimates for the serialized LDA internals. Adds a specialized LocalLDAModel.estimatedSize that charges its learned topic matrix and document-concentration vector without traversing its Spark session.

LDAParams.supportedOptimizers remains an Array[String] field for ABI compatibility. It directly references an equivalent companion-owned array, which the optimizer validator uses so its closure does not retain an LDA model. Adds regression coverage for both model types.

Why are the changes needed?

The distributed-model estimate omitted parameter metadata. Local LDA relied on the generic object-graph walk, which can include its direct SparkSession reference.

Restoring the instance supportedOptimizers field for ABI compatibility would cause the validator lambda to capture the model if it referenced that field. SizeEstimator then follows the closure into unrelated Spark-session state and significantly overestimates the model size. Using the companion-owned array preserves the field while avoiding that capture.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Added LocalLDAModel estimated size and DistributedLDAModel estimated size coverage in LDASuite. The suite was not run locally.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Codex (GPT-5)

@zhengruifeng zhengruifeng changed the title [WIP][ML] Include LDA metadata in size estimates [SPARK-58395][ML] Include LDA metadata in size estimates Jul 28, 2026
@zhengruifeng zhengruifeng changed the title [SPARK-58395][ML] Include LDA metadata in size estimates [SPARK-58395][ML][CONNECT] Include LDA metadata in size estimates Jul 28, 2026
@zhengruifeng
zhengruifeng marked this pull request as ready for review July 28, 2026 08:18
@zhengruifeng
zhengruifeng force-pushed the lda-model-size-metadata-dev3 branch from 954b664 to eb99c2f Compare July 30, 2026 10:18
@zhengruifeng
zhengruifeng requested a review from HyukjinKwon July 31, 2026 04:22

@uros-b uros-b left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change to estimateMatadataSize is a global reduction of the size reported by every Params-implementing model in the system. It breaks two pre-existing Connect tests that have calibrated thresholds against the old estimates: MLSuite.MLCache offloading works (expects 6 cached models, gets 5) and MLSuite.Model size limit (expects MLModelSizeOverflowException at a 4000-byte cap that is no longer reached). Both failures are confirmed in the PR's CI run (annotation messages on check-run 90233623207 show changed model size = 2209 bytes, well below the 4000-byte limit). The PR author notes the suite was not run locally. Adding a dedicated LocalLDAModel.estimatedSize override that bypasses the generic object-graph walk (as this PR already does) is sufficient on its own; the estimateMatadataSize change should either be reverted or the two MLSuite tests must be updated with the rationale for the deliberately lowered estimates documented.

zhengruifeng added a commit that referenced this pull request Aug 3, 2026
### What changes were proposed in this pull request?

Adds parameter metadata to `DistributedLDAModel.estimatedSize` while retaining its existing Arrow-data estimates for the serialized LDA internals. Adds a specialized `LocalLDAModel.estimatedSize` that charges its learned topic matrix and document-concentration vector without traversing its Spark session.

`LDAParams.supportedOptimizers` remains an `Array[String]` field for ABI compatibility. It directly references an equivalent companion-owned array, which the optimizer validator uses so its closure does not retain an LDA model. Adds regression coverage for both model types.

### Why are the changes needed?

The distributed-model estimate omitted parameter metadata. Local LDA relied on the generic object-graph walk, which can include its direct `SparkSession` reference.

Restoring the instance `supportedOptimizers` field for ABI compatibility would cause the validator lambda to capture the model if it referenced that field. `SizeEstimator` then follows the closure into unrelated Spark-session state and significantly overestimates the model size. Using the companion-owned array preserves the field while avoiding that capture.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Added `LocalLDAModel estimated size` and `DistributedLDAModel estimated size` coverage in `LDASuite`. The suite was not run locally.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Codex (GPT-5)

Closes #57589 from zhengruifeng/lda-model-size-metadata-dev3.

Authored-by: Ruifeng Zheng <ruifengz@apache.org>
Signed-off-by: Ruifeng Zheng <ruifengz@apache.org>
(cherry picked from commit 7864cd1)
Signed-off-by: Ruifeng Zheng <ruifengz@apache.org>
@zhengruifeng

Copy link
Copy Markdown
Contributor Author

Merge Summary:

Posted by merge_spark_pr.py

@zhengruifeng
zhengruifeng deleted the lda-model-size-metadata-dev3 branch August 3, 2026 08:29
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.

3 participants