You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ru...@apache.org on 2026/09/09 12:23:46 UTC

(spark) branch master updated: [SPARK-59313][ML] Avoid serializing FeedForwardModel scratch buffers

This is an automated email from the ASF dual-hosted git repository.

zhengruifeng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 695237002055 [SPARK-59313][ML] Avoid serializing FeedForwardModel scratch buffers
695237002055 is described below

commit 695237002055329161b13dbd6f0f3829baad3955
Author: Ruifeng Zheng <ru...@apache.org>
AuthorDate: Wed Sep 9 20:23:31 2026 +0800

    [SPARK-59313][ML] Avoid serializing FeedForwardModel scratch buffers
    
    ### What changes were proposed in this pull request?
    
    This PR marks the reusable `outputs` and `deltas` arrays in `FeedForwardModel` as transient.
    
    ### Why are the changes needed?
    
    `FeedForwardModel` lazily allocates these arrays as scratch buffers and reuses them for forward and
    gradient computations with the same batch size. They can be recreated after deserialization, so
    serializing them unnecessarily carries cached batch matrices with the model.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    - `build/sbt mllib/compile`
    - `build/sbt 'mllib/testOnly *ANNSuite'`
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: Codex (GPT-5)
    
    Closes #58608 from zhengruifeng/ml-spark-59313-mlp-eager-model-dev-8.
    
    Authored-by: Ruifeng Zheng <ru...@apache.org>
    Signed-off-by: Ruifeng Zheng <ru...@foxmail.com>
---
 mllib/src/main/scala/org/apache/spark/ml/ann/Layer.scala | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mllib/src/main/scala/org/apache/spark/ml/ann/Layer.scala b/mllib/src/main/scala/org/apache/spark/ml/ann/Layer.scala
index 7b7ec5f21e56..f2d77e33db18 100644
--- a/mllib/src/main/scala/org/apache/spark/ml/ann/Layer.scala
+++ b/mllib/src/main/scala/org/apache/spark/ml/ann/Layer.scala
@@ -488,8 +488,8 @@ private[ml] class FeedForwardModel private(
       new BDV[Double](denseWeights, offset, 1, layers(i).weightSize))
     offset += layers(i).weightSize
   }
-  private var outputs: Array[BDM[Double]] = null
-  private var deltas: Array[BDM[Double]] = null
+  @transient private var outputs: Array[BDM[Double]] = null
+  @transient private var deltas: Array[BDM[Double]] = null
 
   override def forward(data: BDM[Double], includeLastLayer: Boolean): Array[BDM[Double]] = {
     // Initialize output arrays for all layers. Special treatment for InPlace


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org