hangzhou188 commented on code in PR #9337:
URL: https://github.com/apache/iotdb/pull/9337#discussion_r1147276120


##########
mlnode/iotdb/mlnode/model_storage.py:
##########
@@ -0,0 +1,113 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+import os
+import json
+import torch
+import shutil
+import torch.nn as nn
+from pylru import lrucache
+from iotdb.mlnode.exception import ModelNotExistError
+from iotdb.mlnode.config import config
+
+
+# TODO: Add permission check firstly
+# TODO: Consider concurrency, maybe
+class ModelStorage(object):
+    def __init__(self,
+                 root_path: str,
+                 cache_size: int):
+        self.__model_dir = os.path.join(os.getcwd(), root_path)
+        if not os.path.exists(self.__model_dir):
+            os.mkdir(self.__model_dir)
+        self.__model_cache = lrucache(cache_size)
+
+    def save_model(self,
+                   model: nn.Module,
+                   model_config: dict,
+                   model_id: str,
+                   trial_id: str) -> bool:
+        """
+        Return: True if successfully saved
+
+        Note: model config for time series should contain 'input_len' and 
'input_vars'
+        """
+        fold_path = os.path.join(self.__model_dir, f'{model_id}')
+        if not os.path.exists(fold_path):

Review Comment:
   Should there be a function defining the map from model_id to the actual 
model path? 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to