Skip to content

[SPARK-58251][ML][CONNECT] Add size estimates for OneHotEncoderModel, PCAModel, StringIndexerModel, and IDFModel#57422

Closed
zhengruifeng wants to merge 5 commits into
apache:masterfrom
zhengruifeng:feature-model-size-estimates-master-dev3
Closed

[SPARK-58251][ML][CONNECT] Add size estimates for OneHotEncoderModel, PCAModel, StringIndexerModel, and IDFModel#57422
zhengruifeng wants to merge 5 commits into
apache:masterfrom
zhengruifeng:feature-model-size-estimates-master-dev3

Conversation

@zhengruifeng

@zhengruifeng zhengruifeng commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Add explicit estimatedSize implementations for OneHotEncoderModel, PCAModel, StringIndexerModel, and IDFModel. Each directly accounts for model metadata and model-owned learned state; vectors and matrices use getSizeInBytes.

Why are the changes needed?

SPARK-57521 already makes the default Model.estimatedSize estimate a parentless copy, avoiding parent-estimator and SparkSession traversal. These explicit implementations make size accounting cheaper and more precise for feature models, and align them with models that already provide specialized estimates.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

  • Added fitted-model size bounds to the corresponding feature algorithm suites.
  • JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 build/sbt 'mllib/Test/compile'\n- Targeted suites were not run.\n\n### Was this patch authored or co-authored using generative AI tooling?\n\nGenerated-by: OpenAI Codex (GPT-5)

@zhengruifeng zhengruifeng changed the title [WIP][ML] Add feature model size estimates [WIP][ML] Add size estimates for OneHotEncoderModel, PCAModel, StringIndexerModel, and IDFModel Jul 22, 2026
@zhengruifeng zhengruifeng changed the title [WIP][ML] Add size estimates for OneHotEncoderModel, PCAModel, StringIndexerModel, and IDFModel [SPARK-58251][ML][CONNECT] Add size estimates for OneHotEncoderModel, PCAModel, StringIndexerModel, and IDFModel Jul 22, 2026
@zhengruifeng
zhengruifeng marked this pull request as ready for review July 22, 2026 07:20
@zhengruifeng
zhengruifeng requested a review from HyukjinKwon July 22, 2026 11:45
ParamsSuite.checkParams(model)
}

test("IDFModel estimated size") {

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.

Each new test asserts only an upper bound (estimatedSize < 2KB/4KB). This exercises the code path (guards against NPE / session traversal) but a regression that dropped a learned-state component or returned 0 would still pass all four. A > 0 lower bound, or a "grows with data" check across two input sizes (as in ModelSuite's Word2Vec test and the relative-accuracy checks in LogisticRegressionSuite), would give real regression protection for these four new overrides. Low risk given the implementations are trivial, but it is the one actionable gap for a test-carrying change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks. These tests are deliberately focused on ensuring that estimatedSize does not unexpectedly retain or traverse a reference to a large object; that is the regression they are intended to catch. For PCAModel, pc is never null when the model is fitted or loaded and can only be null through the private[ml] constructor, so the null check is only a defensive safeguard.

zhengruifeng added a commit that referenced this pull request Jul 23, 2026
… PCAModel, StringIndexerModel, and IDFModel

### What changes were proposed in this pull request?

Add explicit `estimatedSize` implementations for OneHotEncoderModel, PCAModel, StringIndexerModel, and IDFModel. Each directly accounts for model metadata and model-owned learned state; vectors and matrices use `getSizeInBytes`.

### Why are the changes needed?

SPARK-57521 already makes the default `Model.estimatedSize` estimate a parentless copy, avoiding parent-estimator and SparkSession traversal. These explicit implementations make size accounting cheaper and more precise for feature models, and align them with models that already provide specialized estimates.

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

No.

### How was this patch tested?

- Added fitted-model size bounds to the corresponding feature algorithm suites.
- `JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 build/sbt 'mllib/Test/compile'`\n- Targeted suites were not run.\n\n### Was this patch authored or co-authored using generative AI tooling?\n\nGenerated-by: OpenAI Codex (GPT-5)

Closes #57422 from zhengruifeng/feature-model-size-estimates-master-dev3.

Authored-by: Ruifeng Zheng <ruifengz@apache.org>
Signed-off-by: Ruifeng Zheng <ruifengz@apache.org>
(cherry picked from commit 36d311f)
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 feature-model-size-estimates-master-dev3 branch July 23, 2026 02:05
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