Skip to content

Commit

Permalink
Fixing python module and yaml tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ShamsUlAzeem committed May 7, 2020
1 parent 65c2372 commit 0477ec6
Show file tree
Hide file tree
Showing 18 changed files with 301 additions and 112 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ pom.xml.versionsBackup
konduit-serving-codegen/src/main/resources/docker/centos/aarch64/cuda/10.0/nvidia-deb/cuda-repo-l4t-10-0-local-10.0.326_1.0-1_arm64.deb
konduit-serving-codegen/src/main/resources/docker/centos/aarch64/cuda/10.0/nvidia-deb/libcudnn7_7.6.3.28-1+cuda10.0_arm64.deb

konduit-serving-core-git.properties
konduit-serving-core-git.properties
builds
31 changes: 31 additions & 0 deletions create-all-binaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

set -euxo pipefail

declare -a platforms=("windows-x86_64" "macosx-x86_64" "linux-x86_64")
declare -a chips=("cpu" "gpu")
declare -a spins=("minimal" "pmml" "python" "all")

mkdir -p builds

PROJECT_VERSION="$(mvn help:evaluate -D expression=project.version | grep -e '^[^\[]')"

## now loop through the above array
for platform in "${platforms[@]}"
do
for chip in "${chips[@]}"
do
for spin in "${spins[@]}"
do
if [[ "${platform}" == 'macosx-x86_64' && "${chip}" == 'gpu' ]]; then
continue
fi

echo "Compiling for $platform | $chip | $spin"

python build_jar.py --os "${platform}" --chip "${chip}" --spin "${spin}" \
--target builds/konduit-serving-uberjar-"${PROJECT_VERSION}"-"${spin}"-"${platform}"-"${chip}".jar
done
done
done

Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,31 @@

@JsonSubTypes({
@JsonSubTypes.Type(value = PmmlStep.class, name = "PMML"),
@JsonSubTypes.Type(value = PmmlStep.class, name = "PmmlConfig"),
@JsonSubTypes.Type(value = PmmlStep.class, name = "PmmlStep"),
@JsonSubTypes.Type(value = SameDiffStep.class, name = "SAMEDIFF"),
@JsonSubTypes.Type(value = SameDiffStep.class, name = "SameDiffConfig"),
@JsonSubTypes.Type(value = SameDiffStep.class, name = "SameDiffStep"),
@JsonSubTypes.Type(value = TensorFlowStep.class, name = "TENSORFLOW"),
@JsonSubTypes.Type(value = TensorFlowStep.class, name = "TensorFlowConfig"),
@JsonSubTypes.Type(value = TensorFlowStep.class, name = "TensorFlowStep"),
@JsonSubTypes.Type(value = OnnxStep.class, name = "ONNX"),
@JsonSubTypes.Type(value = OnnxStep.class, name = "OnnxConfig"),
@JsonSubTypes.Type(value = OnnxStep.class, name = "OnnxStep"),
@JsonSubTypes.Type(value = KerasStep.class, name = "KERAS"),
@JsonSubTypes.Type(value = KerasStep.class, name = "KerasConfig"),
@JsonSubTypes.Type(value = KerasStep.class, name = "KerasStep"),
@JsonSubTypes.Type(value = Dl4jStep.class, name= "DL4J"),
@JsonSubTypes.Type(value = Dl4jStep.class, name= "DL4JConfig"),
@JsonSubTypes.Type(value = Dl4jStep.class, name= "Dl4jStep"),
@JsonSubTypes.Type(value = PythonStep.class, name = "PYTHON"),
@JsonSubTypes.Type(value = PythonStep.class, name = "PythonStep"),
@JsonSubTypes.Type(value = PmmlStep.class, name = "PMML"),
@JsonSubTypes.Type(value = PmmlStep.class, name = "PmmlStep"),
@JsonSubTypes.Type(value = TransformProcessStep.class, name = "TRANSFORM"),
@JsonSubTypes.Type(value = TransformProcessStep.class, name = "TransformProcessStep"),
@JsonSubTypes.Type(value = CustomPipelineStep.class, name = "CUSTOM"),
@JsonSubTypes.Type(value = CustomPipelineStep.class, name = "CustomPipelineStep"),
@JsonSubTypes.Type(value = ImageLoadingStep.class, name = "IMAGE"),
@JsonSubTypes.Type(value = ImageLoadingStep.class, name = "ImageLoadingStep"),
@JsonSubTypes.Type(value = JsonExpanderTransformStep.class, name = "JSON_EXPANDER"),
@JsonSubTypes.Type(value = JsonExpanderTransformStep.class, name = "JsonExpanderTransformStep"),
@JsonSubTypes.Type(value = ArrayConcatenationStep.class, name = "ARRAY_CONCAT"),
@JsonSubTypes.Type(value = ArrayConcatenationStep.class, name = "ArrayConcatenationStep"),
@JsonSubTypes.Type(value = WordPieceTokenizerStep.class, name = "WORDPIECE_TOKENIZER"),
@JsonSubTypes.Type(value = WordPieceTokenizerStep.class, name = "WordPieceTokenizerStep")
@JsonSubTypes.Type(value = WordPieceTokenizerStep.class, name = "WordPieceTokenizerStep"),
@JsonSubTypes.Type(value = CustomPipelineStep.class, name = "CUSTOM"),
@JsonSubTypes.Type(value = CustomPipelineStep.class, name = "CustomPipelineStep")
})
@JsonTypeInfo(use = NAME, property = "type")
@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import ai.konduit.serving.InferenceConfiguration;
import ai.konduit.serving.config.*;
import ai.konduit.serving.config.metrics.ColumnDistribution;
import ai.konduit.serving.config.metrics.MetricsConfig;
import ai.konduit.serving.config.metrics.NoOpMetricsConfig;
import ai.konduit.serving.config.metrics.impl.ClassificationMetricsConfig;
import ai.konduit.serving.config.metrics.impl.MultiLabelMetricsConfig;
Expand Down Expand Up @@ -63,6 +65,8 @@ public static void main( String[] args ) throws Exception {
JsonSchemaGenerator jsonSchemaGenerator = new JsonSchemaGenerator(objectMapper, JsonSchemaConfig.html5EnabledSchema());

Set<Class<?>> clazzes = new LinkedHashSet<>();
clazzes.add(ColumnDistribution.class);
clazzes.add(MetricsConfig.class);
clazzes.add(MultiLabelMetricsConfig.class);
clazzes.add(NoOpMetricsConfig.class);
clazzes.add(ClassificationMetricsConfig.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@
import io.vertx.micrometer.MicrometerMetricsOptions;
import io.vertx.micrometer.VertxPrometheusOptions;
import io.vertx.micrometer.backends.BackendRegistries;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import uk.org.lidalia.sysoutslf4j.context.SysOutOverSLF4J;

import java.util.concurrent.TimeUnit;

@Slf4j
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class DeployKonduitServing {

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void manualTest() throws Exception {
.width(w)
.height(h)
.outputKey("myImage")
.build())
.build())
.add(ShowImagePipelineStep.builder()
.displayName("Image Viewer")
.width(w)
Expand Down
15 changes: 10 additions & 5 deletions python/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
import subprocess
import click
from packaging.version import parse
from hurry.filesize import size

USER_PATH = os.path.expanduser("~")
KONDUIT_BASE_DIR = os.path.join(USER_PATH, ".konduit-serving")
KONDUIT_SOURCE_DIR = os.path.join(KONDUIT_BASE_DIR, "source")
KONDUIT_JAR_DIR = os.path.join(KONDUIT_BASE_DIR, "jar")
KONDUIT_JAR_PATH = os.path.join(KONDUIT_JAR_DIR, "konduit.jar")

INCOMPATIBLE_COMPILATION_TAGS = ["cli_base", "cli_base_2", "cli_base_3", "cli_base_4"]
DOWNLOAD_TAG = "cli_base"

LAST_COMPATIBLE_KONDUIT_VERSION = "0.1.0-SNAPSHOT"
DEFAULT_KONDUIT_TAG = "cli_base_2"
DEFAULT_KONDUIT_TAG = "cli_base_4"
KONDUIT_JAR_URL_FORMAT = "https://github.com/KonduitAI/konduit-serving/releases/download/" \
"{tag}/konduit-serving-uberjar-{version}-{spin}-{platform}-{chip}.jar"

Expand Down Expand Up @@ -54,7 +56,7 @@ def download_if_required(url, save_path):
print("The required CLI binary has already been downloaded.")
return
else:
print("Downloading command line binaries")
print("Downloading command line binaries from " + url)

with open(save_path, 'wb') as f:
if total is None:
Expand All @@ -66,7 +68,8 @@ def download_if_required(url, save_path):
downloaded += len(data)
f.write(data)
done = int(50 * downloaded / total)
sys.stdout.write('\r[{}{}]'.format('█' * done, '.' * (50 - done)))
sys.stdout.write('\r[{}{}]'.format('█' * done, '.' * (50 - done)) +
(" ({}/{})".format(size(downloaded), size(total))))
sys.stdout.flush()
sys.stdout.write('\n')

Expand Down Expand Up @@ -154,7 +157,9 @@ def get_jar_url(platform, version, spin, chip):
chip=chip)


git_tags = get_git_tags()
git_tags = set(get_git_tags()).difference(INCOMPATIBLE_COMPILATION_TAGS)
if len(git_tags) == 0:
git_tags = [DEFAULT_KONDUIT_TAG]
DEFAULT_KONDUIT_TAG = git_tags[0] # Assuming the first one in the response is the most recent one


Expand Down Expand Up @@ -230,4 +235,4 @@ def cli():
subprocess.call(
arguments,
shell=sys.platform.startswith("win")
)
)
6 changes: 3 additions & 3 deletions python/konduit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os

USER_PATH = os.path.expanduser("~")
KONDUIT_BASE_DIR = os.path.join(USER_PATH, ".konduit")
KONDUIT_DIR = os.path.join(KONDUIT_BASE_DIR, "konduit-serving")
KONDUIT_BASE_DIR = os.path.join(USER_PATH, ".konduit-serving")
KONDUIT_JAR_DIR = os.path.join(KONDUIT_BASE_DIR, "jar")

jar = os.getenv("KONDUIT_JAR_PATH", os.path.join(KONDUIT_DIR, "konduit.jar"))
jar = os.getenv("KONDUIT_JAR_PATH", os.path.join(KONDUIT_JAR_DIR, "konduit.jar"))

try:
import pydl4j
Expand Down
133 changes: 130 additions & 3 deletions python/konduit/base_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,133 @@
from konduit.json_utils import empty_type_dict, DictWrapper, ListWrapper


class ColumnDistribution(object):

_normalizerType_enum = enum.Enum(
"_normalizerType_enum",
"STANDARDIZE MIN_MAX IMAGE_MIN_MAX IMAGE_VGG16 MULTI_STANDARDIZE MULTI_MIN_MAX MULTI_HYBRID CUSTOM",
module=__name__,
)
_types_map = {
"mean": {"type": float, "subtype": None},
"min": {"type": float, "subtype": None},
"max": {"type": float, "subtype": None},
"standardDeviation": {"type": float, "subtype": None},
"normalizerType": {"type": str, "subtype": None},
}
_formats_map = {}

def __init__(
self,
mean=None,
min=None,
max=None,
standard_deviation=None,
normalizer_type=None,
):
self.__mean = mean
self.__min = min
self.__max = max
self.__standard_deviation = standard_deviation
self.__normalizer_type = normalizer_type

def _get_mean(self):
return self.__mean

def _set_mean(self, value):
if not isinstance(value, float):
raise TypeError("mean must be float")
self.__mean = value

mean = property(_get_mean, _set_mean)

def _get_min(self):
return self.__min

def _set_min(self, value):
if not isinstance(value, float):
raise TypeError("min must be float")
self.__min = value

min = property(_get_min, _set_min)

def _get_max(self):
return self.__max

def _set_max(self, value):
if not isinstance(value, float):
raise TypeError("max must be float")
self.__max = value

max = property(_get_max, _set_max)

def _get_standard_deviation(self):
return self.__standard_deviation

def _set_standard_deviation(self, value):
if not isinstance(value, float):
raise TypeError("standardDeviation must be float")
self.__standard_deviation = value

standard_deviation = property(_get_standard_deviation, _set_standard_deviation)

def _get_normalizer_type(self):
return self.__normalizer_type

def _set_normalizer_type(self, value):
if not isinstance(value, str):
raise TypeError("normalizerType must be str")
if value in self._normalizerType_enum.__members__:
self.__type = value
else:
raise ValueError("Value {} not in _normalizerType_enum list".format(value))

normalizer_type = property(_get_normalizer_type, _set_normalizer_type)

def as_dict(self):
d = empty_type_dict(self)
if self.__mean is not None:
d["mean"] = (
self.__mean.as_dict()
if hasattr(self.__mean, "as_dict")
else self.__mean
)
if self.__min is not None:
d["min"] = (
self.__min.as_dict() if hasattr(self.__min, "as_dict") else self.__min
)
if self.__max is not None:
d["max"] = (
self.__max.as_dict() if hasattr(self.__max, "as_dict") else self.__max
)
if self.__standard_deviation is not None:
d["standardDeviation"] = (
self.__standard_deviation.as_dict()
if hasattr(self.__standard_deviation, "as_dict")
else self.__standard_deviation
)
if self.__normalizer_type is not None:
d["normalizerType"] = (
self.__normalizer_type.as_dict()
if hasattr(self.__normalizer_type, "as_dict")
else self.__normalizer_type
)
return d


class MetricsConfig(object):

_types_map = {}
_formats_map = {}

def __init__(self):
pass

def as_dict(self):
d = empty_type_dict(self)
return d


class MultiLabelMetricsConfig(object):

_types_map = {
Expand Down Expand Up @@ -888,11 +1015,11 @@ class ServingConfig(object):
def __init__(
self,
http_port=None,
listen_host=None,
listen_host="localhost",
output_data_format="NUMPY",
uploads_directory="file-uploads/",
log_timings=None,
create_logging_endpoints=None,
log_timings=False,
create_logging_endpoints=False,
metrics_configurations=None,
metric_types=None,
):
Expand Down
8 changes: 4 additions & 4 deletions python/konduit/json_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,27 @@ def _ensure_serializable(input_config):
def config_to_dict_with_type(inference_config):
"""
Converts an inference configuration to a Python dictionary
with '@type' key.
with 'type' key.
:param inference_config: InferenceConfig object
:return: Python dict
"""
has_as_dict_attribute(inference_config)
_ensure_serializable(inference_config)
input_dict = inference_config.as_dict()
input_dict["@type"] = inference_config.__class__.__name__
input_dict["type"] = inference_config.__class__.__name__
return input_dict


def empty_type_dict(input_object):
"""Generates an otherwise empty Python dict with the correct
"@type" key from Java.
"type" key from Java.
:param input_class: arbitrary instance of a Python class
:return:
"""
d = dict()
d["@type"] = input_object.__class__.__name__
d["type"] = input_object.__class__.__name__
return d


Expand Down
6 changes: 3 additions & 3 deletions python/konduit/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def server_from_file(file_path, start_server=False, use_yaml=True):

step_data = data.get("steps", None)
steps = []
for step_config in step_data.values():
for step_config in step_data:
steps.append(get_step(step_config))

server = Server(
Expand Down Expand Up @@ -211,8 +211,8 @@ def get_python_step(step_config):
"""

python_step = PythonStep()
for key, python_config in step_config:
python_step.step(key, PythonConfig(**python_config))
for key, config in step_config["python_configs"].items():
python_step.step(python_config=PythonConfig(**config), input_name=key)

return python_step

Expand Down
Loading

0 comments on commit 0477ec6

Please sign in to comment.