Skip to content

Commit 95fb59e

Browse files
authored
[AINode] Fix circular import bug (apache#16137)
1 parent 7d39619 commit 95fb59e

File tree

8 files changed

+90
-62
lines changed

8 files changed

+90
-62
lines changed

iotdb-core/ainode/ainode/core/constant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from enum import Enum
2222
from typing import List
2323

24-
from ainode.core.model.model_info import BuiltInModelType
24+
from ainode.core.model.model_enums import BuiltInModelType
2525
from ainode.thrift.common.ttypes import TEndPoint
2626

2727
AINODE_VERSION_INFO = "UNKNOWN"

iotdb-core/ainode/ainode/core/manager/model_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
InvalidUriError,
2727
)
2828
from ainode.core.log import Logger
29-
from ainode.core.model.model_info import BuiltInModelType, ModelInfo, ModelStates
29+
from ainode.core.model.model_enums import BuiltInModelType, ModelStates
30+
from ainode.core.model.model_info import ModelInfo
3031
from ainode.core.model.model_storage import ModelStorage
3132
from ainode.core.rpc.status import get_status
3233
from ainode.core.util.decorator import singleton

iotdb-core/ainode/ainode/core/model/built_in_model_factory.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
WrongAttributeTypeError,
4545
)
4646
from ainode.core.log import Logger
47-
from ainode.core.model.model_info import TIMER_REPO_ID, BuiltInModelType
47+
from ainode.core.model.model_enums import BuiltInModelType
48+
from ainode.core.model.model_info import TIMER_REPO_ID
4849
from ainode.core.model.sundial import modeling_sundial
4950
from ainode.core.model.timerxl import modeling_timer
5051

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
from enum import Enum
19+
from typing import List
20+
21+
22+
class BuiltInModelType(Enum):
23+
# forecast models
24+
ARIMA = "Arima"
25+
HOLTWINTERS = "HoltWinters"
26+
EXPONENTIAL_SMOOTHING = "ExponentialSmoothing"
27+
NAIVE_FORECASTER = "NaiveForecaster"
28+
STL_FORECASTER = "StlForecaster"
29+
30+
# anomaly detection models
31+
GAUSSIAN_HMM = "GaussianHmm"
32+
GMM_HMM = "GmmHmm"
33+
STRAY = "Stray"
34+
35+
# large time series models (LTSM)
36+
TIMER_XL = "Timer-XL"
37+
# sundial
38+
SUNDIAL = "Timer-Sundial"
39+
40+
@classmethod
41+
def values(cls) -> List[str]:
42+
return [item.value for item in cls]
43+
44+
@staticmethod
45+
def is_built_in_model(model_type: str) -> bool:
46+
"""
47+
Check if the given model type corresponds to a built-in model.
48+
"""
49+
return model_type in BuiltInModelType.values()
50+
51+
52+
class ModelFileType(Enum):
53+
SAFETENSORS = "safetensors"
54+
PYTORCH = "pytorch"
55+
UNKNOWN = "unknown"
56+
57+
58+
class ModelCategory(Enum):
59+
BUILT_IN = "BUILT-IN"
60+
FINE_TUNED = "FINE-TUNED"
61+
USER_DEFINED = "USER-DEFINED"
62+
63+
64+
class ModelStates(Enum):
65+
ACTIVE = "ACTIVE"
66+
INACTIVE = "INACTIVE"
67+
LOADING = "LOADING"
68+
DROPPING = "DROPPING"
69+
TRAINING = "TRAINING"
70+
FAILED = "FAILED"

iotdb-core/ainode/ainode/core/model/model_factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
)
2929
from ainode.core.exception import BadConfigValueError, InvalidUriError
3030
from ainode.core.log import Logger
31-
from ainode.core.model.model_info import ModelFileType
31+
from ainode.core.model.model_enums import ModelFileType
3232
from ainode.core.model.uri_utils import (
3333
UriType,
3434
download_file,

iotdb-core/ainode/ainode/core/model/model_info.py

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,51 +17,19 @@
1717
#
1818
import glob
1919
import os
20-
from enum import Enum
21-
from typing import List
2220

2321
from ainode.core.constant import (
2422
MODEL_CONFIG_FILE_IN_JSON,
2523
MODEL_CONFIG_FILE_IN_YAML,
2624
MODEL_WEIGHTS_FILE_IN_PT,
2725
MODEL_WEIGHTS_FILE_IN_SAFETENSORS,
2826
)
29-
30-
31-
class BuiltInModelType(Enum):
32-
# forecast models
33-
ARIMA = "Arima"
34-
HOLTWINTERS = "HoltWinters"
35-
EXPONENTIAL_SMOOTHING = "ExponentialSmoothing"
36-
NAIVE_FORECASTER = "NaiveForecaster"
37-
STL_FORECASTER = "StlForecaster"
38-
39-
# anomaly detection models
40-
GAUSSIAN_HMM = "GaussianHmm"
41-
GMM_HMM = "GmmHmm"
42-
STRAY = "Stray"
43-
44-
# large time series models (LTSM)
45-
TIMER_XL = "Timer-XL"
46-
# sundial
47-
SUNDIAL = "Timer-Sundial"
48-
49-
@classmethod
50-
def values(cls) -> List[str]:
51-
return [item.value for item in cls]
52-
53-
@staticmethod
54-
def is_built_in_model(model_type: str) -> bool:
55-
"""
56-
Check if the given model type corresponds to a built-in model.
57-
"""
58-
return model_type in BuiltInModelType.values()
59-
60-
61-
class ModelFileType(Enum):
62-
SAFETENSORS = "safetensors"
63-
PYTORCH = "pytorch"
64-
UNKNOWN = "unknown"
27+
from ainode.core.model.model_enums import (
28+
BuiltInModelType,
29+
ModelCategory,
30+
ModelFileType,
31+
ModelStates,
32+
)
6533

6634

6735
def get_model_file_type(model_path: str) -> ModelFileType:
@@ -96,21 +64,6 @@ def get_built_in_model_type(model_type: str) -> BuiltInModelType:
9664
return BuiltInModelType(model_type)
9765

9866

99-
class ModelCategory(Enum):
100-
BUILT_IN = "BUILT-IN"
101-
FINE_TUNED = "FINE-TUNED"
102-
USER_DEFINED = "USER-DEFINED"
103-
104-
105-
class ModelStates(Enum):
106-
ACTIVE = "ACTIVE"
107-
INACTIVE = "INACTIVE"
108-
LOADING = "LOADING"
109-
DROPPING = "DROPPING"
110-
TRAINING = "TRAINING"
111-
FAILED = "FAILED"
112-
113-
11467
class ModelInfo:
11568
def __init__(
11669
self,

iotdb-core/ainode/ainode/core/model/model_storage.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@
4242
download_built_in_ltsm_from_hf_if_necessary,
4343
fetch_built_in_model,
4444
)
45+
from ainode.core.model.model_enums import (
46+
BuiltInModelType,
47+
ModelCategory,
48+
ModelFileType,
49+
ModelStates,
50+
)
4551
from ainode.core.model.model_factory import fetch_model_by_uri
4652
from ainode.core.model.model_info import (
4753
BUILT_IN_LTSM_MAP,
4854
BUILT_IN_MACHINE_LEARNING_MODEL_MAP,
49-
BuiltInModelType,
50-
ModelCategory,
51-
ModelFileType,
5255
ModelInfo,
53-
ModelStates,
5456
get_built_in_model_type,
5557
get_model_file_type,
5658
)

iotdb-core/ainode/ainode/core/model/uri_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
)
3131
from ainode.core.exception import UnsupportedError
3232
from ainode.core.log import Logger
33-
from ainode.core.model.model_info import ModelFileType, get_model_file_type
33+
from ainode.core.model.model_enums import ModelFileType
34+
from ainode.core.model.model_info import get_model_file_type
3435

3536
HTTP_PREFIX = "http://"
3637
HTTPS_PREFIX = "https://"

0 commit comments

Comments
 (0)