-
Notifications
You must be signed in to change notification settings - Fork 28.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-10017] [MLlib]: ML model broadcasts should be stored in private vars: mllib NaiveBayes #8241
Changes from 6 commits
304ec4c
1f47715
78aac79
0e7684e
e616b76
ab175b4
965aaec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.mllib.util | ||
|
||
import scala.reflect.ClassTag | ||
|
||
import org.apache.spark.SparkContext | ||
import org.apache.spark.broadcast.Broadcast | ||
|
||
private[spark] trait Broadcastable[T] { | ||
|
||
private var bcModel: Option[Broadcast[T]] = None | ||
|
||
/** | ||
* Checks whether the model object is already broadcast and returns the reference. | ||
* If not, then broadcasts the model and returns a reference | ||
* @param sc SparkContext that will be used for the broadcast | ||
* @param modelToBc Model object to broadcast | ||
* @return the broadcast model | ||
*/ | ||
def getBroadcastModel(sc: SparkContext, modelToBc: T) | ||
(implicit ev: ClassTag[T]) : Broadcast[T] = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was the ClassTag necessary to get this to work? If you want to make sure T is a ClassTag, can you do
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it might be better to keep parameterization on the entire trait rather than just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 that's better |
||
bcModel match { | ||
case None => bcModel = Some(sc.broadcast(modelToBc)) | ||
case _ => | ||
} | ||
bcModel.get | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need these imports now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@feynmanliang These json* imports were always there. They were simply reordered by the import order plugin I used for IntelliJ. The only additional import is for the Broadcastable trait.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, those need to go back to where they were before, see style guide
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, ill take care of that.