You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@submarine.apache.org by GitBox <gi...@apache.org> on 2021/09/01 09:45:26 UTC

[GitHub] [submarine] jeff-901 commented on a change in pull request #733: SUBMARINE-1000. Add submarine save model method

jeff-901 commented on a change in pull request #733:
URL: https://github.com/apache/submarine/pull/733#discussion_r699249324



##########
File path: submarine-sdk/pysubmarine/submarine/models/client.py
##########
@@ -101,6 +107,39 @@ def save_model(self,
             else:
                 raise MlflowException("No valid type of model has been matched")
 
+    def save_model_submarine(self,
+                             model_type,
+                             model,
+                             artifact_path,
+                             registered_model_name=None):
+        pattern = r"[0-9A-Za-z][0-9A-Za-z-_]*[0-9A-Za-z]|[0-9A-Za-z]"
+        if not re.fullmatch(pattern, artifact_path):
+            raise Exception(
+                "Artifact_path must only contains numbers, characters, hyphen and underscore.  \
+            Artifact_path must starts and ends with numbers or characters.")
+        local_dir = os.path.join(self.root, artifact_path)
+        if os.path.exists(local_dir):
+            version = len(os.listdir(local_dir)) + 1
+        else:
+            version = 1
+        artifact_path = os.path.join(artifact_path, str(version))
+        local_dir = os.path.join(local_dir, str(version))
+        os.makedirs(local_dir)
+        if model_type == "pytorch":
+            import submarine.models.pytorch

Review comment:
       No. I use the function on 131 line.

##########
File path: submarine-sdk/pysubmarine/submarine/models/client.py
##########
@@ -101,6 +107,39 @@ def save_model(self,
             else:
                 raise MlflowException("No valid type of model has been matched")
 
+    def save_model_submarine(self,
+                             model_type,
+                             model,
+                             artifact_path,
+                             registered_model_name=None):
+        pattern = r"[0-9A-Za-z][0-9A-Za-z-_]*[0-9A-Za-z]|[0-9A-Za-z]"
+        if not re.fullmatch(pattern, artifact_path):
+            raise Exception(
+                "Artifact_path must only contains numbers, characters, hyphen and underscore.  \
+            Artifact_path must starts and ends with numbers or characters.")
+        local_dir = os.path.join(self.root, artifact_path)
+        if os.path.exists(local_dir):
+            version = len(os.listdir(local_dir)) + 1
+        else:
+            version = 1
+        artifact_path = os.path.join(artifact_path, str(version))
+        local_dir = os.path.join(local_dir, str(version))
+        os.makedirs(local_dir)
+        if model_type == "pytorch":
+            import submarine.models.pytorch
+
+            submarine.models.pytorch.save_model(model, local_dir)
+        elif model_type == "tensorflow":
+            import submarine.models.tensorflow

Review comment:
       No. I use the function on 135 line.

##########
File path: submarine-sdk/pysubmarine/submarine/models/client.py
##########
@@ -101,6 +107,39 @@ def save_model(self,
             else:
                 raise MlflowException("No valid type of model has been matched")
 
+    def save_model_submarine(self,
+                             model_type,
+                             model,
+                             artifact_path,
+                             registered_model_name=None):
+        pattern = r"[0-9A-Za-z][0-9A-Za-z-_]*[0-9A-Za-z]|[0-9A-Za-z]"
+        if not re.fullmatch(pattern, artifact_path):
+            raise Exception(
+                "Artifact_path must only contains numbers, characters, hyphen and underscore.  \
+            Artifact_path must starts and ends with numbers or characters.")
+        local_dir = os.path.join(self.root, artifact_path)
+        if os.path.exists(local_dir):
+            version = len(os.listdir(local_dir)) + 1
+        else:
+            version = 1

Review comment:
       That sounds good. I will edit it.

##########
File path: submarine-sdk/pysubmarine/submarine/models/client.py
##########
@@ -101,6 +107,39 @@ def save_model(self,
             else:
                 raise MlflowException("No valid type of model has been matched")
 
+    def save_model_submarine(self,
+                             model_type,
+                             model,
+                             artifact_path,
+                             registered_model_name=None):
+        pattern = r"[0-9A-Za-z][0-9A-Za-z-_]*[0-9A-Za-z]|[0-9A-Za-z]"
+        if not re.fullmatch(pattern, artifact_path):
+            raise Exception(
+                "Artifact_path must only contains numbers, characters, hyphen and underscore.  \
+            Artifact_path must starts and ends with numbers or characters.")
+        local_dir = os.path.join(self.root, artifact_path)
+        if os.path.exists(local_dir):
+            version = len(os.listdir(local_dir)) + 1
+        else:
+            version = 1
+        artifact_path = os.path.join(artifact_path, str(version))
+        local_dir = os.path.join(local_dir, str(version))
+        os.makedirs(local_dir)
+        if model_type == "pytorch":
+            import submarine.models.pytorch
+
+            submarine.models.pytorch.save_model(model, local_dir)
+        elif model_type == "tensorflow":
+            import submarine.models.tensorflow
+
+            submarine.models.tensorflow.save_model(model, local_dir)
+        else:
+            raise Exception(
+                "No valid type of model has been matched to {}".format(
+                    model_type))
+        self.artifact_repo.log_artifacts(local_dir, artifact_path)

Review comment:
       That sounds correct. I will delete all the local model.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@submarine.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org