Skip to content

Commit

Permalink
Merge pull request #115 from scc-digitalhub/models-hf-mlflow-sklearn
Browse files Browse the repository at this point in the history
Models hf mlflow sklearn
  • Loading branch information
matteo-s authored Aug 20, 2024
2 parents ec14294 + f9f5545 commit 2061e60
Show file tree
Hide file tree
Showing 42 changed files with 1,843 additions and 33 deletions.
5 changes: 5 additions & 0 deletions application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@
<artifactId>dh-runtime-python</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>it.smartcommunitylabdhub</groupId>
<artifactId>dh-runtime-model-serve</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>it.smartcommunitylabdhub</groupId>
<artifactId>dh-console</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

package it.smartcommunitylabdhub.core.models.specs.model;


import it.smartcommunitylabdhub.commons.annotations.common.SpecType;
import it.smartcommunitylabdhub.commons.models.enums.EntityName;


@SpecType(kind = "huggingface", entity = EntityName.MODEL)
public class HuggingFaceModelSpec extends it.smartcommunitylabdhub.commons.models.entities.model.HuggingFaceModelSpec {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package it.smartcommunitylabdhub.core.models.specs.model;


import it.smartcommunitylabdhub.commons.annotations.common.SpecType;
import it.smartcommunitylabdhub.commons.models.enums.EntityName;
@SpecType(kind = "mlflow", entity = EntityName.MODEL)
public class MlflowModelSpec extends it.smartcommunitylabdhub.commons.models.entities.model.MlflowModelSpec {

}
Original file line number Diff line number Diff line change
@@ -1,37 +1,7 @@
package it.smartcommunitylabdhub.core.models.specs.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import it.smartcommunitylabdhub.commons.annotations.common.SpecType;
import it.smartcommunitylabdhub.commons.models.entities.model.ModelBaseSpec;
import it.smartcommunitylabdhub.commons.models.enums.EntityName;
import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@SpecType(kind = "model", entity = EntityName.MODEL)
public class ModelSpec extends ModelBaseSpec {

@JsonProperty("base_model")
private String baseModel;

@JsonProperty("parameters")
private Map<String, Serializable> parameters = new LinkedHashMap<>();

@JsonProperty("metrics")
private Map<String, Number> metrics = new LinkedHashMap<>();

@Override
public void configure(Map<String, Serializable> data) {
super.configure(data);

ModelSpec spec = mapper.convertValue(data, ModelSpec.class);

this.baseModel = spec.getBaseModel();
this.parameters = spec.getParameters();
this.metrics = spec.getMetrics();
}
public class ModelSpec extends it.smartcommunitylabdhub.commons.models.entities.model.ModelBaseSpec {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package it.smartcommunitylabdhub.core.models.specs.model;


import it.smartcommunitylabdhub.commons.annotations.common.SpecType;
import it.smartcommunitylabdhub.commons.models.enums.EntityName;

@SpecType(kind = "sklearn", entity = EntityName.MODEL)
public class SKLearnModelSpec extends it.smartcommunitylabdhub.commons.models.entities.model.SKLearnModelSpec {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package it.smartcommunitylabdhub.core.models.specs.model.mlflow;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class Dataset {

private String name;
private String digest;
private String profile;
private String schema;
private String source;
@JsonProperty("source_type")
private String sourceType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package it.smartcommunitylabdhub.core.models.specs.model.mlflow;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class Signature {

private String inputs;
private String outputs;
private String params;
}
7 changes: 6 additions & 1 deletion application/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ runtime:
PYTHON3_9: ${RUNTIME_PYTHON_IMAGE_3_9:ghcr.io/scc-digitalhub/digitalhub-serverless/python-runtime:3.9}
PYTHON3_10: ${RUNTIME_PYTHON_IMAGE_3_10:ghcr.io/scc-digitalhub/digitalhub-serverless/python-runtime:3.10}
command: /usr/local/bin/processor

sklearnserve:
image: ${RUNTIME_SKLEARN_SERVE_IMAGE:kserve/sklearnserver:latest}
mlflowserve:
image: ${RUNTIME_MLFLOW_SERVE_IMAGE:seldonio/mlserver:1.6.0-mlflow}
huggingfaceserve:
image: ${RUNTIME_HUGGINGFACE_SERVE_IMAGE:kserve/huggingfaceserver:latest}

# Spring Docs
springdoc:
Expand Down
7 changes: 7 additions & 0 deletions core-builder-tool/builder-tool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ if [ -f "$source_dir/context-refs.txt" ]; then
curl -o "$destination_dir/$destination" -L "$source"
unzip "$destination_dir/$destination" -d "$destination_dir"
;;
"s3") # for now accept a folder/path
mc alias set $minio $S3_ENDPOINT_URL $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY
echo "Protocol: $protocol"
echo "Downloading $minio/$rebuilt_url"
echo "to $destination_dir/$destination"
mc cp --recursive "$minio/$rebuilt_url" "$destination_dir/$destination"
;;
# Add more cases for other protocols as needed
*)
echo "Unknown protocol: $protocol"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package it.smartcommunitylabdhub.commons.models.entities.model;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonProperty;

@Getter
@Setter
public class HuggingFaceModelSpec extends ModelSpec {

//Huggingface model id
@JsonProperty("model_id")
private String modelId;

//Huggingface model revision
@JsonProperty("model_revision")
private String modelRevision;

@Override
public void configure(Map<String, Serializable> data) {
super.configure(data);

HuggingFaceModelSpec spec = mapper.convertValue(data, HuggingFaceModelSpec.class);

this.modelId = spec.getModelId();
this.modelRevision = spec.getModelRevision();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package it.smartcommunitylabdhub.commons.models.entities.model;


import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonProperty;

import it.smartcommunitylabdhub.commons.models.entities.model.mlflow.Dataset;
import it.smartcommunitylabdhub.commons.models.entities.model.mlflow.Signature;

@Getter
@Setter
public class MlflowModelSpec extends ModelSpec {

private String flavor;

@JsonProperty("model_config")
private Map<String, String> modelConfig;

@JsonProperty("input_datasets")
private List<Dataset> inputDatasets;

private Signature signature;

@Override
public void configure(Map<String, Serializable> data) {
super.configure(data);

MlflowModelSpec spec = mapper.convertValue(data, MlflowModelSpec.class);
this.flavor = spec.getFlavor();
this.signature = spec.getSignature();
this.inputDatasets = spec.getInputDatasets();
this.modelConfig = spec.getModelConfig();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package it.smartcommunitylabdhub.commons.models.entities.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class ModelSpec extends ModelBaseSpec {

@JsonProperty("base_model")
private String baseModel;

@JsonProperty("parameters")
private Map<String, Serializable> parameters = new LinkedHashMap<>();

@JsonProperty("metrics")
private Map<String, Number> metrics = new LinkedHashMap<>();

@Override
public void configure(Map<String, Serializable> data) {
super.configure(data);

ModelSpec spec = mapper.convertValue(data, ModelSpec.class);

this.baseModel = spec.getBaseModel();
this.parameters = spec.getParameters();
this.metrics = spec.getMetrics();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package it.smartcommunitylabdhub.commons.models.entities.model;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class SKLearnModelSpec extends ModelSpec {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package it.smartcommunitylabdhub.commons.models.entities.model.mlflow;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class Dataset {

private String name;
private String digest;
private String profile;
private String schema;
private String source;
@JsonProperty("source_type")
private String sourceType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package it.smartcommunitylabdhub.commons.models.entities.model.mlflow;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class Signature {

private String inputs;
private String outputs;
private String params;
}
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public V1Service build(K8sServeRunnable runnable) throws K8sFrameworkException {
.stream()
.filter(p -> p.port() != null && p.targetPort() != null)
.map(p ->
new V1ServicePort().port(p.port()).targetPort(new IntOrString(p.targetPort())).protocol("TCP")
new V1ServicePort().port(p.port()).targetPort(new IntOrString(p.targetPort())).protocol("TCP").name("port" + p.port())
)
.collect(Collectors.toList())
)
Expand Down
77 changes: 77 additions & 0 deletions modules/runtime-model-serve/.flattened-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>it.smartcommunitylabdhub</groupId>
<artifactId>dh-runtime-model-serve</artifactId>
<version>0.7.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>it.smartcommunitylabdhub</groupId>
<artifactId>dh-commons</artifactId>
<version>0.7.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>it.smartcommunitylabdhub</groupId>
<artifactId>dh-framework-k8s</artifactId>
<version>0.7.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>it.smartcommunitylabdhub</groupId>
<artifactId>dh-framework-kaniko</artifactId>
<version>0.7.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.34</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.16.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-cbor</artifactId>
<version>2.16.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.16.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jsonSchema</artifactId>
<version>2.16.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.16.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.9</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>2.0.9</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Loading

0 comments on commit 2061e60

Please sign in to comment.