Skip to content

Commit 1a93531

Browse files
author
Adrien Lavoillotte
authored
Merge PR #35 Model export
from feature/dss51-model-export
2 parents 5ccf07e + 1f82921 commit 1a93531

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

dataikuapi/dss/ml.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,50 @@ def get_coefficient_paths(self):
548548
raise ValueError("This model has no coefficient paths")
549549
return DSSCoefficientPaths(data)
550550

551+
## Model export
552+
553+
def get_scoring_jar_stream(self, model_class="model.Model", include_libs=False):
554+
"""
555+
Get a scoring jar for this trained model,
556+
provided that you have the license to do so and that the model is compatible with optimized scoring.
557+
You need to close the stream after download. Failure to do so will result in the DSSClient becoming unusable.
558+
559+
:param str model_class: fully-qualified class name, e.g. "com.company.project.Model"
560+
:param bool include_libs: if True, also packs the required dependencies;
561+
if False, runtime will require the scoring libs given by :func:`DSSClient.scoring_libs`
562+
:returns: a jar file, as a stream
563+
:rtype: file-like
564+
"""
565+
include_libs = "true" if include_libs else "false"
566+
if self.mltask is not None:
567+
return self.mltask.client._perform_raw(
568+
"GET", "/projects/%s/models/lab/%s/%s/models/%s/scoring-jar?fullClassName=%s&includeLibs=%s" %
569+
(self.mltask.project_key, self.mltask.analysis_id, self.mltask.mltask_id, self.mltask_model_id,
570+
model_class, include_libs))
571+
else:
572+
return self.saved_model.client._perform_raw(
573+
"GET", "/projects/%s/savedmodels/%s/versions/%s/scoring-jar?fullClassName=%s&includeLibs=%s" %
574+
(self.saved_model.project_key, self.saved_model.sm_id, self.saved_model_version,
575+
model_class, include_libs))
576+
577+
def get_scoring_pmml_stream(self):
578+
"""
579+
Get a scoring PMML for this trained model,
580+
provided that you have the license to do so and that the model is compatible with PMML scoring
581+
You need to close the stream after download. Failure to do so will result in the DSSClient becoming unusable.
582+
583+
:returns: a PMML file, as a stream
584+
:rtype: file-like
585+
"""
586+
if self.mltask is not None:
587+
return self.mltask.client._perform_raw(
588+
"GET", "/projects/%s/models/lab/%s/%s/models/%s/scoring-pmml" %
589+
(self.mltask.project_key, self.mltask.analysis_id, self.mltask.mltask_id, self.mltask_model_id))
590+
else:
591+
return self.saved_model.client._perform_raw(
592+
"GET", "/projects/%s/savedmodels/%s/versions/%s/scoring-pmml" %
593+
(self.saved_model.project_key, self.saved_model.sm_id, self.saved_model_version))
594+
551595

552596
class DSSClustersFacts(object):
553597
def __init__(self, clusters_facts):

dataikuapi/dssclient.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,18 @@ def catalog_index_connections(self, connection_names=[], all_connections=False,
706706
"indexingMode": indexing_mode
707707
})
708708

709+
########################################################
710+
# Model export
711+
########################################################
712+
def get_scoring_libs_stream(self):
713+
"""
714+
Get the scoring libraries jar required for scoring with model jars that don't include libraries.
715+
You need to close the stream after download. Failure to do so will result in the DSSClient becoming unusable.
716+
717+
:returns: a jar file, as a stream
718+
:rtype: file-like
719+
"""
720+
return self._perform_raw("GET", "/resources/scoring-lib-jar")
709721

710722
########################################################
711723
# Auth

0 commit comments

Comments
 (0)