Skip to content

[SPARK-58360][ML][CONNECT] Avoid nested parent overcount in RFormulaModel size estimate - #57552

Closed
zhengruifeng wants to merge 7 commits into
apache:masterfrom
zhengruifeng:rformula-size-estimate-dev3
Closed

[SPARK-58360][ML][CONNECT] Avoid nested parent overcount in RFormulaModel size estimate#57552
zhengruifeng wants to merge 7 commits into
apache:masterfrom
zhengruifeng:rformula-size-estimate-dev3

Conversation

@zhengruifeng

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR adds a specialized RFormulaModel.estimatedSize implementation. It counts the model metadata, the resolved formula, and the nested PipelineModel through its parent-safe estimate.

Why are the changes needed?

The default model-size estimate clears only the outer model parent. RFormulaModel retains its nested pipeline, whose stages can otherwise retain estimator-parent graphs and overcount Spark session or context state in ML Connect cache accounting.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Added RFormulaSuite coverage that fits a categorical R formula and verifies that the fitted model estimate stays below the expected upper bound.

Also ran git diff --check, ASCII, and source-line-length checks.

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

Generated-by: Codex (GPT-5)

@zhengruifeng zhengruifeng changed the title [WIP][ML] Avoid nested parent overcount in RFormulaModel size estimate [SPARK-58360][ML][CONNECT] Avoid nested parent overcount in RFormulaModel size estimate Jul 27, 2026
@zhengruifeng
zhengruifeng marked this pull request as ready for review July 27, 2026 07:47
@zhengruifeng
zhengruifeng requested a review from HyukjinKwon July 27, 2026 07:51
assert(
model.estimatedSize < maxSize,
s"Estimation (${model.estimatedSize}) should be less than $maxSize")
}

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 new test asserts only an upper bound (estimatedSize < 16KiB). It genuinely fails without the fix (the default walk blows past 16KiB via SparkSession), so it is a real regression guard, but a buggy implementation returning 0 or a too-small value would also pass. Please add a lower bound to match that standard from predecessor PRs.

@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.

Thank you @zhengruifeng, LGTM after addressing!

zhengruifeng added a commit that referenced this pull request Jul 28, 2026
…odel size estimate

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

This PR adds a specialized `RFormulaModel.estimatedSize` implementation. It counts the model metadata, the resolved formula, and the nested `PipelineModel` through its parent-safe estimate.

### Why are the changes needed?

The default model-size estimate clears only the outer model parent. `RFormulaModel` retains its nested pipeline, whose stages can otherwise retain estimator-parent graphs and overcount Spark session or context state in ML Connect cache accounting.

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

No.

### How was this patch tested?

Added `RFormulaSuite` coverage that fits a categorical R formula and verifies that the fitted model estimate stays below the expected upper bound.

Also ran `git diff --check`, ASCII, and source-line-length checks.

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

Generated-by: Codex (GPT-5)

Closes #57552 from zhengruifeng/rformula-size-estimate-dev3.

Authored-by: Ruifeng Zheng <ruifengz@apache.org>
Signed-off-by: Ruifeng Zheng <ruifengz@apache.org>
(cherry picked from commit 6f12573)
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 rformula-size-estimate-dev3 branch July 28, 2026 08:20
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.

2 participants