-
Notifications
You must be signed in to change notification settings - Fork 397
Local scoring (aka Sparkless) using Aardpfark #41
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
Conversation
}.head | ||
val vector = r(inputName).asInstanceOf[Vector].toArray | ||
val input = s"""{"$inputName":${vector.mkString("[", ",", "]")}}""" | ||
val res = e.action(e.jsonInput(input)).toString |
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.
@MLnick is using json is the most efficient way to call engine action?
Codecov Report
@@ Coverage Diff @@
## master #41 +/- ##
=========================================
Coverage ? 86.14%
=========================================
Files ? 296
Lines ? 9594
Branches ? 319
=========================================
Hits ? 8265
Misses ? 1329
Partials ? 0
Continue to review full report at Codecov.
|
Have you looked at https://github.com/combust/mleap ? |
@manuzhang last time I checked spark support wast that great, but it seems better now. Whats your experience with it? |
@manuzhang let's chat over https://gitter.im ? |
* | ||
* @return a [[collection.mutable.Map]] with row contents | ||
*/ | ||
def toMutableMap: collection.mutable.Map[String, Any] = { |
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.
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.
so you are saying that row.getValuesMap[Any]
should work as well? let me try.
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.
Oook, so my function is faster, because getValuesMap
calls def getAs[T](fieldName: String): T = getAs[T](fieldIndex(fieldName))
for each value, while my function operates on indices.
*/ | ||
def score(params: OpParams): ScoreFunction = { | ||
require(params.modelLocation.isDefined, "Model location must be set in params") | ||
val model = workflow.loadModel(params.modelLocation.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.
will the standard load method work on spark models that use parquet storage without a spark context?
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.
None of the spark ml readers require the context explicitly, but I will need to verify, cause they might get/create spark context inside. Do you have a model in mind that I can check against?
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.
maybe try PCA
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 snap, they simply create a spark context internally when loading models 🤦♂️ https://github.com/apache/spark/blob/5264164a67df498b73facae207eda12ee133be7d/mllib/src/main/scala/org/apache/spark/ml/feature/PCA.scala#L212
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.
well, we also use spark context when reading the model & stages - https://github.com/salesforce/TransmogrifAI/blob/master/core/src/main/scala/com/salesforce/op/OpWorkflowModelReader.scala#L61
and
https://github.com/salesforce/TransmogrifAI/blob/master/features/src/main/scala/com/salesforce/op/stages/OpPipelineStageReader.scala#L63
|
||
// TODO: remove .map[Text] once Aardpfark supports null inputs for StringIndexer | ||
val indexed = description.map[Text](v => if (v.isEmpty) Text("") else v) | ||
.indexed(handleInvalid = StringIndexerHandleInvalid.Skip) |
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.
We should add a spark model that uses complicated serialization - maybe PCA since that uses parquet
@@ -88,6 +88,8 @@ configure(allProjs) { | |||
commonsValidatorVersion = '1.6' | |||
commonsIOVersion = '2.6' | |||
scoveragePluginVersion = '1.3.1' | |||
hadrianVersion = '0.8.5' | |||
aardpfarkVersion = '0.1.0-SNAPSHOT' |
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 are we pulling in a shapshot?
Describe the proposed solution
Added a subproject that enables loading and scoring models without Spark context but locally using Aardpfark (PFA for Spark) and Hadrian libraries instead. This allows orders of magnitude faster scoring times compared to Spark.
Describe alternatives you've considered
dbml-local, ml-local and a custom runtime.
Additional Context
Sample usage:
Test results (single thread running on MacBook Pro i7 3.5Ghz):
TODO: