Local scoring (aka Sparkless) using Aardpfark#41
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.
@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.
There was a problem hiding this comment.
so you are saying that row.getValuesMap[Any] should work as well? let me try.
There was a problem hiding this comment.
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.
will the standard load method work on spark models that use parquet storage without a spark context?
There was a problem hiding this comment.
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.
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.
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.
We should add a spark model that uses complicated serialization - maybe PCA since that uses parquet
| commonsIOVersion = '2.6' | ||
| scoveragePluginVersion = '1.3.1' | ||
| hadrianVersion = '0.8.5' | ||
| aardpfarkVersion = '0.1.0-SNAPSHOT' |
There was a problem hiding this comment.
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: