Skip to content

Commit

Permalink
MLeap Flavor/Deployment mlflow#3: Java implementation of a scoring se…
Browse files Browse the repository at this point in the history
…rver for SageMaker (mlflow#327)

* Add SparkJava plugin

* Change default port

* Support multiple instances of SageMakerServer

* Add SageMaker tests

* Rename SageMakerServer >> ScoringServer and add new tests

* New tests

* Format code

* Remove unused import

* Format again

* New test and artifact name update

* Using jetty scoring server

* Select random port

* Port fixes

* Add port number to start method

* Use apache http for tests

* pom versioning

* More tests

* Code formatting

* Line removal

* Format again

* Format code, address comments

* Format code, docs

* Add stream parsing test, fix other test asserts

* Import fix

* Add CSV to predictor error test

* Fix test

* Fix test, format code

* Remove abstractions for testing sys env reading

* Fixes

* Address comments
  • Loading branch information
dbczumar committed Aug 23, 2018
1 parent b6547a7 commit 0e972dc
Show file tree
Hide file tree
Showing 10 changed files with 656 additions and 71 deletions.
43 changes: 39 additions & 4 deletions mlflow/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.mlflow</groupId>
<artifactId>mlflow-java</artifactId>
<artifactId>mlflow</artifactId>
<version>0.4.2</version>
<packaging>jar</packaging>
<name>mlflow-java</name>
<name>mlflow</name>
<url>http://maven.apache.org</url>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down Expand Up @@ -36,19 +36,54 @@
<dependency>
<groupId>ml.combust.mleap</groupId>
<artifactId>mleap-spark_2.11</artifactId>
<version>0.4.0</version>
<version>0.10.3</version>
</dependency>
<dependency>
<groupId>ml.combust.mleap</groupId>
<artifactId>mleap-runtime_2.11</artifactId>
<version>0.10.0</version>
<version>0.10.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.11.v20180605</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.11.v20180605</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>9.4.11.v20180605</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
58 changes: 0 additions & 58 deletions mlflow/java/src/main/java/org/mlflow/sagemaker/DataFrame.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class MLeapPredictor extends Predictor {
public MLeapPredictor(String modelDataPath, String inputSchemaPath) {}

@Override
protected DataFrame predict(DataFrame input) {
protected PredictorDataWrapper predict(PredictorDataWrapper input) {
throw new UnsupportedOperationException("Not yet implemented!");
}

Expand Down
4 changes: 2 additions & 2 deletions mlflow/java/src/main/java/org/mlflow/sagemaker/Predictor.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.mlflow.sagemaker;


/**
* A generic predictor object that provides a uniform interface for model inference. By extending
* {@link org.mlflow.sagemaker.Predictor}, models of a specific flavor can expose their inference
* routines for use by generic tools, such as model containers
*/
public abstract class Predictor {
/** Performs inference on the specified input and produces a result */
protected abstract DataFrame predict(DataFrame input) throws PredictorEvaluationException;
protected abstract PredictorDataWrapper predict(PredictorDataWrapper input)
throws PredictorEvaluationException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.mlflow.sagemaker;

/** Input/output data representation for use by {@link org.mlflow.sagemaker.Predictor} objects */
public class PredictorDataWrapper {
public enum ContentType {
Json,
Csv
}

private final String content;
private final ContentType contentType;

/** Constructs a PredictorDataWrapper */
public PredictorDataWrapper(String content, ContentType contentType) {
this.content = content;
this.contentType = contentType;
}

/** @return The type of content contained in the wrapper (JSON, CSV, etc.) */
ContentType getContentType() {
return this.contentType;
}

/**
* Produces a JSON string representation of the PredictorDataWrapper
*
* @return A string in JSON format
*/
String toJson() {
if (this.contentType == ContentType.Json) {
return this.content;
} else {
throw new UnsupportedOperationException(
"Converting a data wrapper of a non-JSON content type to JSON is not yet supported.");
}
}

/**
* Produces a CSV string representation of the PredictorDataWrapper
*
* @return A string in CSV format
*/
String toCsv() {
throw new UnsupportedOperationException(
"Converting a data wrapper to CSV is not yet supported.");
}
}
Loading

0 comments on commit 0e972dc

Please sign in to comment.