diff --git a/src/UserGuide/Master/Table/AI-capability/AINode_Upgrade_apache.md b/src/UserGuide/Master/Table/AI-capability/AINode_Upgrade_apache.md index be7a0606b..5e2027b61 100644 --- a/src/UserGuide/Master/Table/AI-capability/AINode_Upgrade_apache.md +++ b/src/UserGuide/Master/Table/AI-capability/AINode_Upgrade_apache.md @@ -164,8 +164,9 @@ It costs 1.615s 1. AINode uses Transformers v4.56.2; avoid inheriting interfaces from older versions (<4.50). 2. The model must inherit an AINode inference pipeline class (currently supports forecasting pipeline): * iotdb-core/ainode/iotdb/ainode/core/inference/pipeline/basic_pipeline.py - - ```python + + **Before V2.0.9.3** + ```Python class BasicPipeline(ABC): def __init__(self, model_id, **model_kwargs): self.model_info = model_info @@ -174,12 +175,16 @@ It costs 1.615s @abstractmethod def preprocess(self, inputs, **infer_kwargs): - """Preprocess input data before inference, including shape validation and numerical conversion.""" + """ + Preprocess the input data before the inference task starts, including shape validation and numerical conversion. + """ pass @abstractmethod def postprocess(self, output, **infer_kwargs): - """Postprocess model outputs after inference.""" + """ + Postprocess the output results after the inference task is completed. + """ pass @@ -189,69 +194,176 @@ It costs 1.615s def preprocess(self, inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], **infer_kwargs): """ - Preprocess and validate input data before model inference. + Preprocess the input data before passing it to the model for inference, validating the shape and type of the input data. Args: inputs (list[dict]): - Input data as list of dicts containing: - - 'targets': Tensor of shape (input_length,) or (target_count, input_length). - - 'past_covariates': Optional dict of tensors, each of shape (input_length,). - - 'future_covariates': Optional dict of tensors, each of shape (input_length,). - infer_kwargs (dict, optional): Additional inference parameters, e.g.: - - `output_length` (int): Required if 'future_covariates' provided for validation. + Input data, a list of dictionaries, each dictionary contains: + - 'targets': Tensor with shape (input_length,) or (target_count, input_length). + - 'past_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + - 'future_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + + infer_kwargs (dict, optional): Additional keyword arguments for inference, such as: + - `output_length`(int): Used to validate the validity of 'future_covariates' if provided. Raises: - ValueError: For invalid input formats (missing keys, invalid tensor shapes). + ValueError: If the input format is invalid (e.g., missing keys, invalid tensor shapes). Returns: - Preprocessed and validated input ready for model inference. + Preprocessed and validated input data that can be directly used for model inference. """ pass def forecast(self, inputs, **infer_kwargs): """ - Perform forecasting on given inputs. + Perform forecasting on the given inputs. Parameters: - inputs: Input data for forecasting (type/structure model-specific). - **infer_kwargs: Additional parameters, e.g.: - - `output_length` (int): Number of future time points to generate. + inputs: Input data for forecasting. The type and structure depend on the specific model implementation. + **infer_kwargs: Additional inference parameters, e.g.: + - `output_length`(int): The number of time points the model should generate. Returns: - Forecast output (format model-specific). + Forecast output, the specific form depends on the specific model implementation. """ pass def postprocess(self, outputs: list[torch.Tensor], **infer_kwargs) -> list[torch.Tensor]: """ - Postprocess model outputs, validate shapes, and ensure expected dimensions. + Postprocess the model outputs after inference, validating the shape of the output data and ensuring it meets the expected dimensions. Args: - outputs: List of 2D tensors, each of shape `[target_count, output_length]`. + outputs: + Model outputs, a list of 2D tensors, each tensor with shape `[target_count, output_length]`. Raises: - InferenceModelInternalException: For invalid output tensor shapes. - ValueError: For incorrect output format. + InferenceModelInternalException: If the output tensor shape is invalid (e.g., incorrect dimensions). + ValueError: If the output format is incorrect. Returns: - List of postprocessed 2D tensors. + list[torch.Tensor]: + Postprocessed outputs, which will be a list of 2D tensors. """ pass ``` -3. Modify `config.json` to include: - ```json + + **From V2.0.9.3 onwards** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + Preprocess the input data before the inference task starts, including shape validation and numerical conversion. + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + Postprocess the output results after the inference task is completed. + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def _preprocess( + self, + inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], + **infer_kwargs, + ): + """ + Preprocess the input data before passing it to the model for inference, validating the shape and type of the input data. + + Args: + inputs (list[dict[str, dict[str, torch.Tensor] | torch.Tensor]]): + Input data, a list of dictionaries, each dictionary contains: + - 'targets': Tensor with shape (input_length,) or (target_count, input_length). + - 'past_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + - 'future_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + + infer_kwargs (dict, optional): Additional keyword arguments for inference, such as: + - `output_length`(int): Used to validate the validity of 'future_covariates' if provided. + + Raises: + ValueError: If the input format is invalid (e.g., missing keys, invalid tensor shapes). + + Returns: + Preprocessed and validated input data that can be directly used for model inference. + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + Perform forecasting on the given inputs. + + Parameters: + inputs: Input data for forecasting. The type and structure depend on the specific model implementation. + **infer_kwargs: Additional inference parameters, e.g.: + - `output_length`(int): The number of time points the model should generate. + + Returns: + Forecast output, the specific form depends on the specific model implementation. + """ + pass + + def _postprocess(self, outputs, **infer_kwargs) -> list[torch.Tensor]: + """ + Postprocess the model outputs after inference, validating the shape of the output data and ensuring it meets the expected dimensions. + + Args: + outputs: + Model outputs, a list of 2D tensors, each tensor with shape `[target_count, output_length]`. + + Raises: + InferenceModelInternalException: If the output tensor shape is invalid (e.g., incorrect dimensions). + ValueError: If the output format is incorrect. + + Returns: + list[torch.Tensor]: + Postprocessed outputs, which will be a list of 2D tensors. + """ + pass + ``` + +3. Modify the model configuration file `config.json` to ensure it contains the following fields: + + **Before V2.0.9.3** + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // Specify the model Config class + "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the inference pipeline for the model + "model_type": "custom_t5", // Specify the model type + } + ``` + * The model Config class and model class **must** be specified via `auto_map`; + * The inference pipeline class **must** be inherited and specified; + * For built-in and user-defined models managed by AINode, `model_type` also serves as a unique non-duplicable identifier. That is, the model type to be registered must not duplicate any existing model types; models created via fine-tuning will inherit the model type of the original model. + + **From V2.0.9.3 onwards** + > The `model_type` parameter is **not required** + ```JSON { "auto_map": { - "AutoConfig": "config.Chronos2CoreConfig", - "AutoModelForCausalLM": "model.Chronos2Model" + "AutoConfig": "config.Chronos2CoreConfig", // Specify the model Config class + "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class }, - "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", - "model_type": "custom_t5" + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the inference pipeline for the model } ``` - * Must specify model Config and model classes via `auto_map`. - * Must implement and specify the inference pipeline class. - * `model_type` serves as a unique identifier. Must not conflict with existing model types (for both `builtin` and `user_defined` models). + * The model Config class and model class **must** be specified via `auto_map`; + * The inference pipeline class **must** be inherited and specified; + 4. Ensure the model directory contains: * `config.json` (model configuration) * `model.safetensors` (model weights) diff --git a/src/UserGuide/Master/Table/AI-capability/AINode_Upgrade_timecho.md b/src/UserGuide/Master/Table/AI-capability/AINode_Upgrade_timecho.md index e53c4d202..db1354e93 100644 --- a/src/UserGuide/Master/Table/AI-capability/AINode_Upgrade_timecho.md +++ b/src/UserGuide/Master/Table/AI-capability/AINode_Upgrade_timecho.md @@ -487,101 +487,205 @@ IoTDB> show models 2. The model must inherit a pipeline for inference tasks of AINode (currently supports prediction pipeline): * iotdb-core/ainode/iotdb/ainode/core/inference/pipeline/basic_pipeline.py - ```Python - class BasicPipeline(ABC): - def __init__(self, model_id, **model_kwargs): - self.model_info = model_info - self.device = model_kwargs.get("device", "cpu") - self.model = load_model(model_info, device_map=self.device, **model_kwargs) - - @abstractmethod - def preprocess(self, inputs, **infer_kwargs): - """ - Preprocess input data before the inference task, including shape validation and numerical conversion. - """ - pass - - @abstractmethod - def postprocess(self, output, **infer_kwargs): - """ - Postprocess output results after the inference task. - """ - pass - - - class ForecastPipeline(BasicPipeline): - def __init__(self, model_info, **model_kwargs): - super().__init__(model_info, model_kwargs=model_kwargs) - - def preprocess(self, inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], **infer_kwargs): - """ - Preprocess input data before passing it to the model for inference, validate input data shape and type. - - Args: - inputs (list[dict]): - Input data, list of dictionaries, each dictionary contains: - - 'targets': tensor of shape (input_length,) or (target_count, input_length). - - 'past_covariates': optional, tensor dictionary, each tensor of shape (input_length,). - - 'future_covariates': optional, tensor dictionary, each tensor of shape (input_length,). - - infer_kwargs (dict, optional): Additional keyword parameters for inference, such as: - - `output_length`(int): If 'future_covariates' is provided, used to validate its validity. - - Raises: - ValueError: If input format is incorrect (e.g., missing keys, invalid tensor shapes). - - Returns: - Processed and validated input data, ready for model inference. - """ - pass - - def forecast(self, inputs, **infer_kwargs): - """ - Perform prediction on given input. - - Parameters: - inputs: Input data for prediction. Type and structure depend on the model's specific implementation. - **infer_kwargs: Additional inference parameters, e.g.: - - `output_length`(int): Number of time points the model should generate. - - Returns: - Prediction output, specific form depends on the model's specific implementation. - """ - pass - - def postprocess(self, outputs: list[torch.Tensor], **infer_kwargs) -> list[torch.Tensor]: - """ - Postprocess model output after inference, validate output data shape and ensure it meets expected dimensions. - - Args: - outputs: - Model output, list of 2D tensors, each tensor of shape `[target_count, output_length]`. - - Raises: - InferenceModelInternalException: If output tensor shape is invalid (e.g., dimension error). - ValueError: If output format is incorrect. - - Returns: - list[torch.Tensor]: - Postprocessed output, a list of 2D tensors. - """ - pass - ``` -3. Modify the model configuration file config.json to ensure it includes the following fields: - ```JSON - { - "auto_map": { - "AutoConfig": "config.Chronos2CoreConfig", // Specify the Config class of the model - "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class - }, - "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the model's inference pipeline - "model_type": "custom_t5", // Specify the model type - } - ``` + **Before V2.0.9.3** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + Preprocess the input data before the inference task starts, including shape validation and numerical conversion. + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + Postprocess the output results after the inference task is completed. + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def preprocess(self, inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], **infer_kwargs): + """ + Preprocess the input data before passing it to the model for inference, validating the shape and type of the input data. + + Args: + inputs (list[dict]): + Input data, a list of dictionaries, each dictionary contains: + - 'targets': Tensor with shape (input_length,) or (target_count, input_length). + - 'past_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + - 'future_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + + infer_kwargs (dict, optional): Additional keyword arguments for inference, such as: + - `output_length`(int): Used to validate the validity of 'future_covariates' if provided. + + Raises: + ValueError: If the input format is invalid (e.g., missing keys, invalid tensor shapes). + + Returns: + Preprocessed and validated input data that can be directly used for model inference. + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + Perform forecasting on the given inputs. + + Parameters: + inputs: Input data for forecasting. The type and structure depend on the specific model implementation. + **infer_kwargs: Additional inference parameters, e.g.: + - `output_length`(int): The number of time points the model should generate. + + Returns: + Forecast output, the specific form depends on the specific model implementation. + """ + pass + + def postprocess(self, outputs: list[torch.Tensor], **infer_kwargs) -> list[torch.Tensor]: + """ + Postprocess the model outputs after inference, validating the shape of the output data and ensuring it meets the expected dimensions. + + Args: + outputs: + Model outputs, a list of 2D tensors, each tensor with shape `[target_count, output_length]`. + + Raises: + InferenceModelInternalException: If the output tensor shape is invalid (e.g., incorrect dimensions). + ValueError: If the output format is incorrect. + + Returns: + list[torch.Tensor]: + Postprocessed outputs, which will be a list of 2D tensors. + """ + pass + ``` + + **From V2.0.9.3 onwards** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + Preprocess the input data before the inference task starts, including shape validation and numerical conversion. + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + Postprocess the output results after the inference task is completed. + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def _preprocess( + self, + inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], + **infer_kwargs, + ): + """ + Preprocess the input data before passing it to the model for inference, validating the shape and type of the input data. + + Args: + inputs (list[dict[str, dict[str, torch.Tensor] | torch.Tensor]]): + Input data, a list of dictionaries, each dictionary contains: + - 'targets': Tensor with shape (input_length,) or (target_count, input_length). + - 'past_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + - 'future_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + + infer_kwargs (dict, optional): Additional keyword arguments for inference, such as: + - `output_length`(int): Used to validate the validity of 'future_covariates' if provided. + + Raises: + ValueError: If the input format is invalid (e.g., missing keys, invalid tensor shapes). + + Returns: + Preprocessed and validated input data that can be directly used for model inference. + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + Perform forecasting on the given inputs. + + Parameters: + inputs: Input data for forecasting. The type and structure depend on the specific model implementation. + **infer_kwargs: Additional inference parameters, e.g.: + - `output_length`(int): The number of time points the model should generate. + + Returns: + Forecast output, the specific form depends on the specific model implementation. + """ + pass + + def _postprocess(self, outputs, **infer_kwargs) -> list[torch.Tensor]: + """ + Postprocess the model outputs after inference, validating the shape of the output data and ensuring it meets the expected dimensions. + + Args: + outputs: + Model outputs, a list of 2D tensors, each tensor with shape `[target_count, output_length]`. + + Raises: + InferenceModelInternalException: If the output tensor shape is invalid (e.g., incorrect dimensions). + ValueError: If the output format is incorrect. + + Returns: + list[torch.Tensor]: + Postprocessed outputs, which will be a list of 2D tensors. + """ + pass + ``` + +3. Modify the model configuration file `config.json` to ensure it contains the following fields: + + **Before V2.0.9.3** + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // Specify the model Config class + "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the inference pipeline for the model + "model_type": "custom_t5", // Specify the model type + } + ``` + * The model Config class and model class **must** be specified via `auto_map`; + * The inference pipeline class **must** be inherited and specified; + * For built-in and user-defined models managed by AINode, `model_type` also serves as a unique non-duplicable identifier. That is, the model type to be registered must not duplicate any existing model types; models created via fine-tuning will inherit the model type of the original model. + + **From V2.0.9.3 onwards** + > The `model_type` parameter is **not required** + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // Specify the model Config class + "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the inference pipeline for the model + } + ``` + * The model Config class and model class **must** be specified via `auto_map`; + * The inference pipeline class **must** be inherited and specified; - * Must specify the Config class and model class through auto_map; - * Must integrate and specify the inference pipeline class; - * For built-in (builtin) and custom (user_defined) models managed by AINode, the model category (model_type) also serves as a unique identifier. That is, the model category to be registered must not duplicate any existing model types. Models created through fine-tuning will inherit the model category of the original model. 4. Ensure the model directory to be registered contains the following files, and the model configuration file name and weight file name are not customizable: * Model configuration file: config.json; * Model weight file: model.safetensors; diff --git a/src/UserGuide/Master/Tree/AI-capability/AINode_Upgrade_apache.md b/src/UserGuide/Master/Tree/AI-capability/AINode_Upgrade_apache.md index 836c10fb4..d163087d4 100644 --- a/src/UserGuide/Master/Tree/AI-capability/AINode_Upgrade_apache.md +++ b/src/UserGuide/Master/Tree/AI-capability/AINode_Upgrade_apache.md @@ -139,101 +139,205 @@ Total line number = 48 2. The model must inherit from a type of AINode inference task pipeline (currently supports forecast pipeline): * iotdb-core/ainode/iotdb/ainode/core/inference/pipeline/basic_pipeline.py - ```Python - class BasicPipeline(ABC): - def __init__(self, model_id, **model_kwargs): - self.model_info = model_info - self.device = model_kwargs.get("device", "cpu") - self.model = load_model(model_info, device_map=self.device, **model_kwargs) - - @abstractmethod - def preprocess(self, inputs, **infer_kwargs): - """ - Preprocess the input data before the inference task, including shape verification and numerical conversion. - """ - pass - - @abstractmethod - def postprocess(self, output, **infer_kwargs): - """ - Postprocess the output results after the inference task. - """ - pass - - - class ForecastPipeline(BasicPipeline): - def __init__(self, model_info, **model_kwargs): - super().__init__(model_info, model_kwargs=model_kwargs) - - def preprocess(self, inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], **infer_kwargs): - """ - Preprocess the input data before passing it to the model for inference, verifying the shape and type of input data. - - Args: - inputs (list[dict]): - Input data, a list of dictionaries, each dictionary contains: - - 'targets': A tensor of shape (input_length,) or (target_count, input_length). - - 'past_covariates': Optional, a dictionary of tensors, each tensor of shape (input_length,). - - 'future_covariates': Optional, a dictionary of tensors, each tensor of shape (input_length,). - - infer_kwargs (dict, optional): Additional keyword parameters for inference, such as: - - `output_length`(int): Used to verify validity if 'future_covariates' is provided. - - Raises: - ValueError: If the input format is incorrect (e.g., missing keys, invalid tensor shapes). - - Returns: - Preprocessed and verified input data, ready for model inference. - """ - pass - - def forecast(self, inputs, **infer_kwargs): - """ - Perform prediction on the given input. - - Parameters: - inputs: Input data for prediction. Type and structure depend on the specific model implementation. - **infer_kwargs: Additional inference parameters, for example: - - `output_length`(int): The number of time points the model should generate. - - Returns: - Prediction output, specific form depends on the specific model implementation. - """ - pass - - def postprocess(self, outputs: list[torch.Tensor], **infer_kwargs) -> list[torch.Tensor]: - """ - Postprocess the model output after inference, verifying the shape of the output tensor and ensuring it meets expected dimensions. - - Args: - outputs: - Model output, a list of 2D tensors, each tensor shape is `[target_count, output_length]`. - - Raises: - InferenceModelInternalException: If the output tensor shape is invalid (e.g., dimension error). - ValueError: If the output format is incorrect. - - Returns: - list[torch.Tensor]: - Postprocessed output, a list of 2D tensors. - """ - pass - ``` -3. Modify the model configuration file config.json to ensure it contains the following fields: - ```JSON - { - "auto_map": { - "AutoConfig": "config.Chronos2CoreConfig", // Specify the model Config class - "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class - }, - "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the model's inference pipeline - "model_type": "custom_t5", // Specify the model type - } - ``` + **Before V2.0.9.3** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + Preprocess the input data before the inference task starts, including shape validation and numerical conversion. + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + Postprocess the output results after the inference task is completed. + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def preprocess(self, inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], **infer_kwargs): + """ + Preprocess the input data before passing it to the model for inference, validating the shape and type of the input data. + + Args: + inputs (list[dict]): + Input data, a list of dictionaries, each dictionary contains: + - 'targets': Tensor with shape (input_length,) or (target_count, input_length). + - 'past_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + - 'future_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + + infer_kwargs (dict, optional): Additional keyword arguments for inference, such as: + - `output_length`(int): Used to validate the validity of 'future_covariates' if provided. + + Raises: + ValueError: If the input format is invalid (e.g., missing keys, invalid tensor shapes). + + Returns: + Preprocessed and validated input data that can be directly used for model inference. + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + Perform forecasting on the given inputs. + + Parameters: + inputs: Input data for forecasting. The type and structure depend on the specific model implementation. + **infer_kwargs: Additional inference parameters, e.g.: + - `output_length`(int): The number of time points the model should generate. + + Returns: + Forecast output, the specific form depends on the specific model implementation. + """ + pass + + def postprocess(self, outputs: list[torch.Tensor], **infer_kwargs) -> list[torch.Tensor]: + """ + Postprocess the model outputs after inference, validating the shape of the output data and ensuring it meets the expected dimensions. + + Args: + outputs: + Model outputs, a list of 2D tensors, each tensor with shape `[target_count, output_length]`. + + Raises: + InferenceModelInternalException: If the output tensor shape is invalid (e.g., incorrect dimensions). + ValueError: If the output format is incorrect. + + Returns: + list[torch.Tensor]: + Postprocessed outputs, which will be a list of 2D tensors. + """ + pass + ``` + + **From V2.0.9.3 onwards** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + Preprocess the input data before the inference task starts, including shape validation and numerical conversion. + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + Postprocess the output results after the inference task is completed. + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def _preprocess( + self, + inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], + **infer_kwargs, + ): + """ + Preprocess the input data before passing it to the model for inference, validating the shape and type of the input data. + + Args: + inputs (list[dict[str, dict[str, torch.Tensor] | torch.Tensor]]): + Input data, a list of dictionaries, each dictionary contains: + - 'targets': Tensor with shape (input_length,) or (target_count, input_length). + - 'past_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + - 'future_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + + infer_kwargs (dict, optional): Additional keyword arguments for inference, such as: + - `output_length`(int): Used to validate the validity of 'future_covariates' if provided. + + Raises: + ValueError: If the input format is invalid (e.g., missing keys, invalid tensor shapes). + + Returns: + Preprocessed and validated input data that can be directly used for model inference. + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + Perform forecasting on the given inputs. + + Parameters: + inputs: Input data for forecasting. The type and structure depend on the specific model implementation. + **infer_kwargs: Additional inference parameters, e.g.: + - `output_length`(int): The number of time points the model should generate. + + Returns: + Forecast output, the specific form depends on the specific model implementation. + """ + pass + + def _postprocess(self, outputs, **infer_kwargs) -> list[torch.Tensor]: + """ + Postprocess the model outputs after inference, validating the shape of the output data and ensuring it meets the expected dimensions. + + Args: + outputs: + Model outputs, a list of 2D tensors, each tensor with shape `[target_count, output_length]`. + + Raises: + InferenceModelInternalException: If the output tensor shape is invalid (e.g., incorrect dimensions). + ValueError: If the output format is incorrect. + + Returns: + list[torch.Tensor]: + Postprocessed outputs, which will be a list of 2D tensors. + """ + pass + ``` + +3. Modify the model configuration file `config.json` to ensure it contains the following fields: + + **Before V2.0.9.3** + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // Specify the model Config class + "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the inference pipeline for the model + "model_type": "custom_t5", // Specify the model type + } + ``` + * The model Config class and model class **must** be specified via `auto_map`; + * The inference pipeline class **must** be inherited and specified; + * For built-in and user-defined models managed by AINode, `model_type` also serves as a unique non-duplicable identifier. That is, the model type to be registered must not duplicate any existing model types; models created via fine-tuning will inherit the model type of the original model. + + **From V2.0.9.3 onwards** + > The `model_type` parameter is **not required** + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // Specify the model Config class + "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the inference pipeline for the model + } + ``` + * The model Config class and model class **must** be specified via `auto_map`; + * The inference pipeline class **must** be inherited and specified; - * Must specify the model's Config class and model class through auto_map; - * Must integrate and specify the inference pipeline class; - * For built-in (builtin) and user-defined (user_defined) models managed by AINode, the model category (model_type) also serves as a unique identifier. That is, the model category to be registered must not duplicate any existing model types. 4. Ensure the model directory to be registered contains the following files, and the model configuration file name and weight file name are not customizable: * Model configuration file: config.json; * Model weight file: model.safetensors; diff --git a/src/UserGuide/Master/Tree/AI-capability/AINode_Upgrade_timecho.md b/src/UserGuide/Master/Tree/AI-capability/AINode_Upgrade_timecho.md index 1bc14c36f..54f4d63b6 100644 --- a/src/UserGuide/Master/Tree/AI-capability/AINode_Upgrade_timecho.md +++ b/src/UserGuide/Master/Tree/AI-capability/AINode_Upgrade_timecho.md @@ -219,101 +219,205 @@ IoTDB> show models 2. The model needs to inherit a type of AINode inference task pipeline (currently supports the forecasting pipeline): * iotdb-core/ainode/iotdb/ainode/core/inference/pipeline/basic\_pipeline.py - ```Python - class BasicPipeline(ABC): - def __init__(self, model_id, **model_kwargs): - self.model_info = model_info - self.device = model_kwargs.get("device", "cpu") - self.model = load_model(model_info, device_map=self.device, **model_kwargs) - - @abstractmethod - def preprocess(self, inputs, **infer_kwargs): - """ - Preprocess the input data before the inference task starts, including shape verification and numerical conversion. - """ - pass - - @abstractmethod - def postprocess(self, output, **infer_kwargs): - """ - Postprocess the output results after the inference task ends. - """ - pass - - - class ForecastPipeline(BasicPipeline): - def __init__(self, model_info, **model_kwargs): - super().__init__(model_info, model_kwargs=model_kwargs) - - def preprocess(self, inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], **infer_kwargs): - """ - Preprocess the input data before passing it to the model for inference, verifying the shape and type of input data. - - Args: - inputs (list[dict]): - Input data, a list of dictionaries, each dictionary contains: - - 'targets': a tensor of shape (input_length,) or (target_count, input_length). - - 'past_covariates': optional, a dictionary of tensors, each tensor shape is (input_length,). - - 'future_covariates': optional, a dictionary of tensors, each tensor shape is (input_length,). - - infer_kwargs (dict, optional): Additional inference keyword parameters, such as: - - `output_length`(int): If 'future_covariates' is provided, used to validate its validity. - - Raises: - ValueError: If the input format is incorrect (e.g., missing keys, invalid tensor shapes). - - Returns: - Preprocessed and validated input data, ready for model inference. - """ - pass - - def forecast(self, inputs, **infer_kwargs): - """ - Perform prediction on the given input. - - Parameters: - inputs: Input data for prediction. The type and structure depend on the specific implementation of the model. - **infer_kwargs: Additional inference parameters, such as: - - `output_length`(int): The number of time points the model should generate. - - Returns: - Prediction output, specific form depends on the specific implementation of the model. - """ - pass - - def postprocess(self, outputs: list[torch.Tensor], **infer_kwargs) -> list[torch.Tensor]: - """ - Postprocess the model output after inference, verifying the shape of output tensors and ensuring they meet the expected dimensions. - - Args: - outputs: - Model output, a list of 2D tensors, each tensor shape is `[target_count, output_length]`. - - Raises: - InferenceModelInternalException: If the output tensor shape is invalid (e.g., dimension error). - ValueError: If the output format is incorrect. - - Returns: - list[torch.Tensor]: - Postprocessed output, a list of 2D tensors. - """ - pass - ``` -3. Modify the model configuration file config.json to ensure it contains the following fields: - ```JSON - { - "auto_map": { - "AutoConfig": "config.Chronos2CoreConfig", // Specify the model Config class - "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class - }, - "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the model's inference pipeline - "model_type": "custom_t5", // Specify the model type - } - ``` - - * Must specify the model Config class and model class through auto\_map; - * Must integrate and specify the inference pipeline class; - * For AINode-managed built-in (builtin) and custom (user\_defined) models, the model category (model\_type) also serves as a unique identifier. That is, the model category to be registered must not be duplicated with any existing model type. Models created through fine-tuning will inherit the model category of the original model. + **Before V2.0.9.3** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + Preprocess the input data before the inference task starts, including shape validation and numerical conversion. + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + Postprocess the output results after the inference task is completed. + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def preprocess(self, inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], **infer_kwargs): + """ + Preprocess the input data before passing it to the model for inference, validating the shape and type of the input data. + + Args: + inputs (list[dict]): + Input data, a list of dictionaries, each dictionary contains: + - 'targets': Tensor with shape (input_length,) or (target_count, input_length). + - 'past_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + - 'future_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + + infer_kwargs (dict, optional): Additional keyword arguments for inference, such as: + - `output_length`(int): Used to validate the validity of 'future_covariates' if provided. + + Raises: + ValueError: If the input format is invalid (e.g., missing keys, invalid tensor shapes). + + Returns: + Preprocessed and validated input data that can be directly used for model inference. + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + Perform forecasting on the given inputs. + + Parameters: + inputs: Input data for forecasting. The type and structure depend on the specific model implementation. + **infer_kwargs: Additional inference parameters, e.g.: + - `output_length`(int): The number of time points the model should generate. + + Returns: + Forecast output, the specific form depends on the specific model implementation. + """ + pass + + def postprocess(self, outputs: list[torch.Tensor], **infer_kwargs) -> list[torch.Tensor]: + """ + Postprocess the model outputs after inference, validating the shape of the output data and ensuring it meets the expected dimensions. + + Args: + outputs: + Model outputs, a list of 2D tensors, each tensor with shape `[target_count, output_length]`. + + Raises: + InferenceModelInternalException: If the output tensor shape is invalid (e.g., incorrect dimensions). + ValueError: If the output format is incorrect. + + Returns: + list[torch.Tensor]: + Postprocessed outputs, which will be a list of 2D tensors. + """ + pass + ``` + + **From V2.0.9.3 onwards** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + Preprocess the input data before the inference task starts, including shape validation and numerical conversion. + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + Postprocess the output results after the inference task is completed. + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def _preprocess( + self, + inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], + **infer_kwargs, + ): + """ + Preprocess the input data before passing it to the model for inference, validating the shape and type of the input data. + + Args: + inputs (list[dict[str, dict[str, torch.Tensor] | torch.Tensor]]): + Input data, a list of dictionaries, each dictionary contains: + - 'targets': Tensor with shape (input_length,) or (target_count, input_length). + - 'past_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + - 'future_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + + infer_kwargs (dict, optional): Additional keyword arguments for inference, such as: + - `output_length`(int): Used to validate the validity of 'future_covariates' if provided. + + Raises: + ValueError: If the input format is invalid (e.g., missing keys, invalid tensor shapes). + + Returns: + Preprocessed and validated input data that can be directly used for model inference. + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + Perform forecasting on the given inputs. + + Parameters: + inputs: Input data for forecasting. The type and structure depend on the specific model implementation. + **infer_kwargs: Additional inference parameters, e.g.: + - `output_length`(int): The number of time points the model should generate. + + Returns: + Forecast output, the specific form depends on the specific model implementation. + """ + pass + + def _postprocess(self, outputs, **infer_kwargs) -> list[torch.Tensor]: + """ + Postprocess the model outputs after inference, validating the shape of the output data and ensuring it meets the expected dimensions. + + Args: + outputs: + Model outputs, a list of 2D tensors, each tensor with shape `[target_count, output_length]`. + + Raises: + InferenceModelInternalException: If the output tensor shape is invalid (e.g., incorrect dimensions). + ValueError: If the output format is incorrect. + + Returns: + list[torch.Tensor]: + Postprocessed outputs, which will be a list of 2D tensors. + """ + pass + ``` + +3. Modify the model configuration file `config.json` to ensure it contains the following fields: + + **Before V2.0.9.3** + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // Specify the model Config class + "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the inference pipeline for the model + "model_type": "custom_t5", // Specify the model type + } + ``` + * The model Config class and model class **must** be specified via `auto_map`; + * The inference pipeline class **must** be inherited and specified; + * For built-in and user-defined models managed by AINode, `model_type` also serves as a unique non-duplicable identifier. That is, the model type to be registered must not duplicate any existing model types; models created via fine-tuning will inherit the model type of the original model. + + **From V2.0.9.3 onwards** + > The `model_type` parameter is **not required** + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // Specify the model Config class + "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the inference pipeline for the model + } + ``` + * The model Config class and model class **must** be specified via `auto_map`; + * The inference pipeline class **must** be inherited and specified; + 4. Ensure that the model directory to be registered contains the following files, and the model configuration file name and weight file name are not customizable: * Model configuration file: config.json; * Model weight file: model.safetensors; diff --git a/src/UserGuide/latest-Table/AI-capability/AINode_Upgrade_apache.md b/src/UserGuide/latest-Table/AI-capability/AINode_Upgrade_apache.md index be7a0606b..5e2027b61 100644 --- a/src/UserGuide/latest-Table/AI-capability/AINode_Upgrade_apache.md +++ b/src/UserGuide/latest-Table/AI-capability/AINode_Upgrade_apache.md @@ -164,8 +164,9 @@ It costs 1.615s 1. AINode uses Transformers v4.56.2; avoid inheriting interfaces from older versions (<4.50). 2. The model must inherit an AINode inference pipeline class (currently supports forecasting pipeline): * iotdb-core/ainode/iotdb/ainode/core/inference/pipeline/basic_pipeline.py - - ```python + + **Before V2.0.9.3** + ```Python class BasicPipeline(ABC): def __init__(self, model_id, **model_kwargs): self.model_info = model_info @@ -174,12 +175,16 @@ It costs 1.615s @abstractmethod def preprocess(self, inputs, **infer_kwargs): - """Preprocess input data before inference, including shape validation and numerical conversion.""" + """ + Preprocess the input data before the inference task starts, including shape validation and numerical conversion. + """ pass @abstractmethod def postprocess(self, output, **infer_kwargs): - """Postprocess model outputs after inference.""" + """ + Postprocess the output results after the inference task is completed. + """ pass @@ -189,69 +194,176 @@ It costs 1.615s def preprocess(self, inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], **infer_kwargs): """ - Preprocess and validate input data before model inference. + Preprocess the input data before passing it to the model for inference, validating the shape and type of the input data. Args: inputs (list[dict]): - Input data as list of dicts containing: - - 'targets': Tensor of shape (input_length,) or (target_count, input_length). - - 'past_covariates': Optional dict of tensors, each of shape (input_length,). - - 'future_covariates': Optional dict of tensors, each of shape (input_length,). - infer_kwargs (dict, optional): Additional inference parameters, e.g.: - - `output_length` (int): Required if 'future_covariates' provided for validation. + Input data, a list of dictionaries, each dictionary contains: + - 'targets': Tensor with shape (input_length,) or (target_count, input_length). + - 'past_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + - 'future_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + + infer_kwargs (dict, optional): Additional keyword arguments for inference, such as: + - `output_length`(int): Used to validate the validity of 'future_covariates' if provided. Raises: - ValueError: For invalid input formats (missing keys, invalid tensor shapes). + ValueError: If the input format is invalid (e.g., missing keys, invalid tensor shapes). Returns: - Preprocessed and validated input ready for model inference. + Preprocessed and validated input data that can be directly used for model inference. """ pass def forecast(self, inputs, **infer_kwargs): """ - Perform forecasting on given inputs. + Perform forecasting on the given inputs. Parameters: - inputs: Input data for forecasting (type/structure model-specific). - **infer_kwargs: Additional parameters, e.g.: - - `output_length` (int): Number of future time points to generate. + inputs: Input data for forecasting. The type and structure depend on the specific model implementation. + **infer_kwargs: Additional inference parameters, e.g.: + - `output_length`(int): The number of time points the model should generate. Returns: - Forecast output (format model-specific). + Forecast output, the specific form depends on the specific model implementation. """ pass def postprocess(self, outputs: list[torch.Tensor], **infer_kwargs) -> list[torch.Tensor]: """ - Postprocess model outputs, validate shapes, and ensure expected dimensions. + Postprocess the model outputs after inference, validating the shape of the output data and ensuring it meets the expected dimensions. Args: - outputs: List of 2D tensors, each of shape `[target_count, output_length]`. + outputs: + Model outputs, a list of 2D tensors, each tensor with shape `[target_count, output_length]`. Raises: - InferenceModelInternalException: For invalid output tensor shapes. - ValueError: For incorrect output format. + InferenceModelInternalException: If the output tensor shape is invalid (e.g., incorrect dimensions). + ValueError: If the output format is incorrect. Returns: - List of postprocessed 2D tensors. + list[torch.Tensor]: + Postprocessed outputs, which will be a list of 2D tensors. """ pass ``` -3. Modify `config.json` to include: - ```json + + **From V2.0.9.3 onwards** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + Preprocess the input data before the inference task starts, including shape validation and numerical conversion. + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + Postprocess the output results after the inference task is completed. + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def _preprocess( + self, + inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], + **infer_kwargs, + ): + """ + Preprocess the input data before passing it to the model for inference, validating the shape and type of the input data. + + Args: + inputs (list[dict[str, dict[str, torch.Tensor] | torch.Tensor]]): + Input data, a list of dictionaries, each dictionary contains: + - 'targets': Tensor with shape (input_length,) or (target_count, input_length). + - 'past_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + - 'future_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + + infer_kwargs (dict, optional): Additional keyword arguments for inference, such as: + - `output_length`(int): Used to validate the validity of 'future_covariates' if provided. + + Raises: + ValueError: If the input format is invalid (e.g., missing keys, invalid tensor shapes). + + Returns: + Preprocessed and validated input data that can be directly used for model inference. + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + Perform forecasting on the given inputs. + + Parameters: + inputs: Input data for forecasting. The type and structure depend on the specific model implementation. + **infer_kwargs: Additional inference parameters, e.g.: + - `output_length`(int): The number of time points the model should generate. + + Returns: + Forecast output, the specific form depends on the specific model implementation. + """ + pass + + def _postprocess(self, outputs, **infer_kwargs) -> list[torch.Tensor]: + """ + Postprocess the model outputs after inference, validating the shape of the output data and ensuring it meets the expected dimensions. + + Args: + outputs: + Model outputs, a list of 2D tensors, each tensor with shape `[target_count, output_length]`. + + Raises: + InferenceModelInternalException: If the output tensor shape is invalid (e.g., incorrect dimensions). + ValueError: If the output format is incorrect. + + Returns: + list[torch.Tensor]: + Postprocessed outputs, which will be a list of 2D tensors. + """ + pass + ``` + +3. Modify the model configuration file `config.json` to ensure it contains the following fields: + + **Before V2.0.9.3** + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // Specify the model Config class + "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the inference pipeline for the model + "model_type": "custom_t5", // Specify the model type + } + ``` + * The model Config class and model class **must** be specified via `auto_map`; + * The inference pipeline class **must** be inherited and specified; + * For built-in and user-defined models managed by AINode, `model_type` also serves as a unique non-duplicable identifier. That is, the model type to be registered must not duplicate any existing model types; models created via fine-tuning will inherit the model type of the original model. + + **From V2.0.9.3 onwards** + > The `model_type` parameter is **not required** + ```JSON { "auto_map": { - "AutoConfig": "config.Chronos2CoreConfig", - "AutoModelForCausalLM": "model.Chronos2Model" + "AutoConfig": "config.Chronos2CoreConfig", // Specify the model Config class + "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class }, - "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", - "model_type": "custom_t5" + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the inference pipeline for the model } ``` - * Must specify model Config and model classes via `auto_map`. - * Must implement and specify the inference pipeline class. - * `model_type` serves as a unique identifier. Must not conflict with existing model types (for both `builtin` and `user_defined` models). + * The model Config class and model class **must** be specified via `auto_map`; + * The inference pipeline class **must** be inherited and specified; + 4. Ensure the model directory contains: * `config.json` (model configuration) * `model.safetensors` (model weights) diff --git a/src/UserGuide/latest-Table/AI-capability/AINode_Upgrade_timecho.md b/src/UserGuide/latest-Table/AI-capability/AINode_Upgrade_timecho.md index e53c4d202..db1354e93 100644 --- a/src/UserGuide/latest-Table/AI-capability/AINode_Upgrade_timecho.md +++ b/src/UserGuide/latest-Table/AI-capability/AINode_Upgrade_timecho.md @@ -487,101 +487,205 @@ IoTDB> show models 2. The model must inherit a pipeline for inference tasks of AINode (currently supports prediction pipeline): * iotdb-core/ainode/iotdb/ainode/core/inference/pipeline/basic_pipeline.py - ```Python - class BasicPipeline(ABC): - def __init__(self, model_id, **model_kwargs): - self.model_info = model_info - self.device = model_kwargs.get("device", "cpu") - self.model = load_model(model_info, device_map=self.device, **model_kwargs) - - @abstractmethod - def preprocess(self, inputs, **infer_kwargs): - """ - Preprocess input data before the inference task, including shape validation and numerical conversion. - """ - pass - - @abstractmethod - def postprocess(self, output, **infer_kwargs): - """ - Postprocess output results after the inference task. - """ - pass - - - class ForecastPipeline(BasicPipeline): - def __init__(self, model_info, **model_kwargs): - super().__init__(model_info, model_kwargs=model_kwargs) - - def preprocess(self, inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], **infer_kwargs): - """ - Preprocess input data before passing it to the model for inference, validate input data shape and type. - - Args: - inputs (list[dict]): - Input data, list of dictionaries, each dictionary contains: - - 'targets': tensor of shape (input_length,) or (target_count, input_length). - - 'past_covariates': optional, tensor dictionary, each tensor of shape (input_length,). - - 'future_covariates': optional, tensor dictionary, each tensor of shape (input_length,). - - infer_kwargs (dict, optional): Additional keyword parameters for inference, such as: - - `output_length`(int): If 'future_covariates' is provided, used to validate its validity. - - Raises: - ValueError: If input format is incorrect (e.g., missing keys, invalid tensor shapes). - - Returns: - Processed and validated input data, ready for model inference. - """ - pass - - def forecast(self, inputs, **infer_kwargs): - """ - Perform prediction on given input. - - Parameters: - inputs: Input data for prediction. Type and structure depend on the model's specific implementation. - **infer_kwargs: Additional inference parameters, e.g.: - - `output_length`(int): Number of time points the model should generate. - - Returns: - Prediction output, specific form depends on the model's specific implementation. - """ - pass - - def postprocess(self, outputs: list[torch.Tensor], **infer_kwargs) -> list[torch.Tensor]: - """ - Postprocess model output after inference, validate output data shape and ensure it meets expected dimensions. - - Args: - outputs: - Model output, list of 2D tensors, each tensor of shape `[target_count, output_length]`. - - Raises: - InferenceModelInternalException: If output tensor shape is invalid (e.g., dimension error). - ValueError: If output format is incorrect. - - Returns: - list[torch.Tensor]: - Postprocessed output, a list of 2D tensors. - """ - pass - ``` -3. Modify the model configuration file config.json to ensure it includes the following fields: - ```JSON - { - "auto_map": { - "AutoConfig": "config.Chronos2CoreConfig", // Specify the Config class of the model - "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class - }, - "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the model's inference pipeline - "model_type": "custom_t5", // Specify the model type - } - ``` + **Before V2.0.9.3** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + Preprocess the input data before the inference task starts, including shape validation and numerical conversion. + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + Postprocess the output results after the inference task is completed. + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def preprocess(self, inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], **infer_kwargs): + """ + Preprocess the input data before passing it to the model for inference, validating the shape and type of the input data. + + Args: + inputs (list[dict]): + Input data, a list of dictionaries, each dictionary contains: + - 'targets': Tensor with shape (input_length,) or (target_count, input_length). + - 'past_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + - 'future_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + + infer_kwargs (dict, optional): Additional keyword arguments for inference, such as: + - `output_length`(int): Used to validate the validity of 'future_covariates' if provided. + + Raises: + ValueError: If the input format is invalid (e.g., missing keys, invalid tensor shapes). + + Returns: + Preprocessed and validated input data that can be directly used for model inference. + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + Perform forecasting on the given inputs. + + Parameters: + inputs: Input data for forecasting. The type and structure depend on the specific model implementation. + **infer_kwargs: Additional inference parameters, e.g.: + - `output_length`(int): The number of time points the model should generate. + + Returns: + Forecast output, the specific form depends on the specific model implementation. + """ + pass + + def postprocess(self, outputs: list[torch.Tensor], **infer_kwargs) -> list[torch.Tensor]: + """ + Postprocess the model outputs after inference, validating the shape of the output data and ensuring it meets the expected dimensions. + + Args: + outputs: + Model outputs, a list of 2D tensors, each tensor with shape `[target_count, output_length]`. + + Raises: + InferenceModelInternalException: If the output tensor shape is invalid (e.g., incorrect dimensions). + ValueError: If the output format is incorrect. + + Returns: + list[torch.Tensor]: + Postprocessed outputs, which will be a list of 2D tensors. + """ + pass + ``` + + **From V2.0.9.3 onwards** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + Preprocess the input data before the inference task starts, including shape validation and numerical conversion. + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + Postprocess the output results after the inference task is completed. + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def _preprocess( + self, + inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], + **infer_kwargs, + ): + """ + Preprocess the input data before passing it to the model for inference, validating the shape and type of the input data. + + Args: + inputs (list[dict[str, dict[str, torch.Tensor] | torch.Tensor]]): + Input data, a list of dictionaries, each dictionary contains: + - 'targets': Tensor with shape (input_length,) or (target_count, input_length). + - 'past_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + - 'future_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + + infer_kwargs (dict, optional): Additional keyword arguments for inference, such as: + - `output_length`(int): Used to validate the validity of 'future_covariates' if provided. + + Raises: + ValueError: If the input format is invalid (e.g., missing keys, invalid tensor shapes). + + Returns: + Preprocessed and validated input data that can be directly used for model inference. + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + Perform forecasting on the given inputs. + + Parameters: + inputs: Input data for forecasting. The type and structure depend on the specific model implementation. + **infer_kwargs: Additional inference parameters, e.g.: + - `output_length`(int): The number of time points the model should generate. + + Returns: + Forecast output, the specific form depends on the specific model implementation. + """ + pass + + def _postprocess(self, outputs, **infer_kwargs) -> list[torch.Tensor]: + """ + Postprocess the model outputs after inference, validating the shape of the output data and ensuring it meets the expected dimensions. + + Args: + outputs: + Model outputs, a list of 2D tensors, each tensor with shape `[target_count, output_length]`. + + Raises: + InferenceModelInternalException: If the output tensor shape is invalid (e.g., incorrect dimensions). + ValueError: If the output format is incorrect. + + Returns: + list[torch.Tensor]: + Postprocessed outputs, which will be a list of 2D tensors. + """ + pass + ``` + +3. Modify the model configuration file `config.json` to ensure it contains the following fields: + + **Before V2.0.9.3** + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // Specify the model Config class + "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the inference pipeline for the model + "model_type": "custom_t5", // Specify the model type + } + ``` + * The model Config class and model class **must** be specified via `auto_map`; + * The inference pipeline class **must** be inherited and specified; + * For built-in and user-defined models managed by AINode, `model_type` also serves as a unique non-duplicable identifier. That is, the model type to be registered must not duplicate any existing model types; models created via fine-tuning will inherit the model type of the original model. + + **From V2.0.9.3 onwards** + > The `model_type` parameter is **not required** + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // Specify the model Config class + "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the inference pipeline for the model + } + ``` + * The model Config class and model class **must** be specified via `auto_map`; + * The inference pipeline class **must** be inherited and specified; - * Must specify the Config class and model class through auto_map; - * Must integrate and specify the inference pipeline class; - * For built-in (builtin) and custom (user_defined) models managed by AINode, the model category (model_type) also serves as a unique identifier. That is, the model category to be registered must not duplicate any existing model types. Models created through fine-tuning will inherit the model category of the original model. 4. Ensure the model directory to be registered contains the following files, and the model configuration file name and weight file name are not customizable: * Model configuration file: config.json; * Model weight file: model.safetensors; diff --git a/src/UserGuide/latest/AI-capability/AINode_Upgrade_apache.md b/src/UserGuide/latest/AI-capability/AINode_Upgrade_apache.md index 836c10fb4..d163087d4 100644 --- a/src/UserGuide/latest/AI-capability/AINode_Upgrade_apache.md +++ b/src/UserGuide/latest/AI-capability/AINode_Upgrade_apache.md @@ -139,101 +139,205 @@ Total line number = 48 2. The model must inherit from a type of AINode inference task pipeline (currently supports forecast pipeline): * iotdb-core/ainode/iotdb/ainode/core/inference/pipeline/basic_pipeline.py - ```Python - class BasicPipeline(ABC): - def __init__(self, model_id, **model_kwargs): - self.model_info = model_info - self.device = model_kwargs.get("device", "cpu") - self.model = load_model(model_info, device_map=self.device, **model_kwargs) - - @abstractmethod - def preprocess(self, inputs, **infer_kwargs): - """ - Preprocess the input data before the inference task, including shape verification and numerical conversion. - """ - pass - - @abstractmethod - def postprocess(self, output, **infer_kwargs): - """ - Postprocess the output results after the inference task. - """ - pass - - - class ForecastPipeline(BasicPipeline): - def __init__(self, model_info, **model_kwargs): - super().__init__(model_info, model_kwargs=model_kwargs) - - def preprocess(self, inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], **infer_kwargs): - """ - Preprocess the input data before passing it to the model for inference, verifying the shape and type of input data. - - Args: - inputs (list[dict]): - Input data, a list of dictionaries, each dictionary contains: - - 'targets': A tensor of shape (input_length,) or (target_count, input_length). - - 'past_covariates': Optional, a dictionary of tensors, each tensor of shape (input_length,). - - 'future_covariates': Optional, a dictionary of tensors, each tensor of shape (input_length,). - - infer_kwargs (dict, optional): Additional keyword parameters for inference, such as: - - `output_length`(int): Used to verify validity if 'future_covariates' is provided. - - Raises: - ValueError: If the input format is incorrect (e.g., missing keys, invalid tensor shapes). - - Returns: - Preprocessed and verified input data, ready for model inference. - """ - pass - - def forecast(self, inputs, **infer_kwargs): - """ - Perform prediction on the given input. - - Parameters: - inputs: Input data for prediction. Type and structure depend on the specific model implementation. - **infer_kwargs: Additional inference parameters, for example: - - `output_length`(int): The number of time points the model should generate. - - Returns: - Prediction output, specific form depends on the specific model implementation. - """ - pass - - def postprocess(self, outputs: list[torch.Tensor], **infer_kwargs) -> list[torch.Tensor]: - """ - Postprocess the model output after inference, verifying the shape of the output tensor and ensuring it meets expected dimensions. - - Args: - outputs: - Model output, a list of 2D tensors, each tensor shape is `[target_count, output_length]`. - - Raises: - InferenceModelInternalException: If the output tensor shape is invalid (e.g., dimension error). - ValueError: If the output format is incorrect. - - Returns: - list[torch.Tensor]: - Postprocessed output, a list of 2D tensors. - """ - pass - ``` -3. Modify the model configuration file config.json to ensure it contains the following fields: - ```JSON - { - "auto_map": { - "AutoConfig": "config.Chronos2CoreConfig", // Specify the model Config class - "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class - }, - "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the model's inference pipeline - "model_type": "custom_t5", // Specify the model type - } - ``` + **Before V2.0.9.3** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + Preprocess the input data before the inference task starts, including shape validation and numerical conversion. + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + Postprocess the output results after the inference task is completed. + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def preprocess(self, inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], **infer_kwargs): + """ + Preprocess the input data before passing it to the model for inference, validating the shape and type of the input data. + + Args: + inputs (list[dict]): + Input data, a list of dictionaries, each dictionary contains: + - 'targets': Tensor with shape (input_length,) or (target_count, input_length). + - 'past_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + - 'future_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + + infer_kwargs (dict, optional): Additional keyword arguments for inference, such as: + - `output_length`(int): Used to validate the validity of 'future_covariates' if provided. + + Raises: + ValueError: If the input format is invalid (e.g., missing keys, invalid tensor shapes). + + Returns: + Preprocessed and validated input data that can be directly used for model inference. + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + Perform forecasting on the given inputs. + + Parameters: + inputs: Input data for forecasting. The type and structure depend on the specific model implementation. + **infer_kwargs: Additional inference parameters, e.g.: + - `output_length`(int): The number of time points the model should generate. + + Returns: + Forecast output, the specific form depends on the specific model implementation. + """ + pass + + def postprocess(self, outputs: list[torch.Tensor], **infer_kwargs) -> list[torch.Tensor]: + """ + Postprocess the model outputs after inference, validating the shape of the output data and ensuring it meets the expected dimensions. + + Args: + outputs: + Model outputs, a list of 2D tensors, each tensor with shape `[target_count, output_length]`. + + Raises: + InferenceModelInternalException: If the output tensor shape is invalid (e.g., incorrect dimensions). + ValueError: If the output format is incorrect. + + Returns: + list[torch.Tensor]: + Postprocessed outputs, which will be a list of 2D tensors. + """ + pass + ``` + + **From V2.0.9.3 onwards** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + Preprocess the input data before the inference task starts, including shape validation and numerical conversion. + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + Postprocess the output results after the inference task is completed. + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def _preprocess( + self, + inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], + **infer_kwargs, + ): + """ + Preprocess the input data before passing it to the model for inference, validating the shape and type of the input data. + + Args: + inputs (list[dict[str, dict[str, torch.Tensor] | torch.Tensor]]): + Input data, a list of dictionaries, each dictionary contains: + - 'targets': Tensor with shape (input_length,) or (target_count, input_length). + - 'past_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + - 'future_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + + infer_kwargs (dict, optional): Additional keyword arguments for inference, such as: + - `output_length`(int): Used to validate the validity of 'future_covariates' if provided. + + Raises: + ValueError: If the input format is invalid (e.g., missing keys, invalid tensor shapes). + + Returns: + Preprocessed and validated input data that can be directly used for model inference. + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + Perform forecasting on the given inputs. + + Parameters: + inputs: Input data for forecasting. The type and structure depend on the specific model implementation. + **infer_kwargs: Additional inference parameters, e.g.: + - `output_length`(int): The number of time points the model should generate. + + Returns: + Forecast output, the specific form depends on the specific model implementation. + """ + pass + + def _postprocess(self, outputs, **infer_kwargs) -> list[torch.Tensor]: + """ + Postprocess the model outputs after inference, validating the shape of the output data and ensuring it meets the expected dimensions. + + Args: + outputs: + Model outputs, a list of 2D tensors, each tensor with shape `[target_count, output_length]`. + + Raises: + InferenceModelInternalException: If the output tensor shape is invalid (e.g., incorrect dimensions). + ValueError: If the output format is incorrect. + + Returns: + list[torch.Tensor]: + Postprocessed outputs, which will be a list of 2D tensors. + """ + pass + ``` + +3. Modify the model configuration file `config.json` to ensure it contains the following fields: + + **Before V2.0.9.3** + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // Specify the model Config class + "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the inference pipeline for the model + "model_type": "custom_t5", // Specify the model type + } + ``` + * The model Config class and model class **must** be specified via `auto_map`; + * The inference pipeline class **must** be inherited and specified; + * For built-in and user-defined models managed by AINode, `model_type` also serves as a unique non-duplicable identifier. That is, the model type to be registered must not duplicate any existing model types; models created via fine-tuning will inherit the model type of the original model. + + **From V2.0.9.3 onwards** + > The `model_type` parameter is **not required** + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // Specify the model Config class + "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the inference pipeline for the model + } + ``` + * The model Config class and model class **must** be specified via `auto_map`; + * The inference pipeline class **must** be inherited and specified; - * Must specify the model's Config class and model class through auto_map; - * Must integrate and specify the inference pipeline class; - * For built-in (builtin) and user-defined (user_defined) models managed by AINode, the model category (model_type) also serves as a unique identifier. That is, the model category to be registered must not duplicate any existing model types. 4. Ensure the model directory to be registered contains the following files, and the model configuration file name and weight file name are not customizable: * Model configuration file: config.json; * Model weight file: model.safetensors; diff --git a/src/UserGuide/latest/AI-capability/AINode_Upgrade_timecho.md b/src/UserGuide/latest/AI-capability/AINode_Upgrade_timecho.md index 1bc14c36f..54f4d63b6 100644 --- a/src/UserGuide/latest/AI-capability/AINode_Upgrade_timecho.md +++ b/src/UserGuide/latest/AI-capability/AINode_Upgrade_timecho.md @@ -219,101 +219,205 @@ IoTDB> show models 2. The model needs to inherit a type of AINode inference task pipeline (currently supports the forecasting pipeline): * iotdb-core/ainode/iotdb/ainode/core/inference/pipeline/basic\_pipeline.py - ```Python - class BasicPipeline(ABC): - def __init__(self, model_id, **model_kwargs): - self.model_info = model_info - self.device = model_kwargs.get("device", "cpu") - self.model = load_model(model_info, device_map=self.device, **model_kwargs) - - @abstractmethod - def preprocess(self, inputs, **infer_kwargs): - """ - Preprocess the input data before the inference task starts, including shape verification and numerical conversion. - """ - pass - - @abstractmethod - def postprocess(self, output, **infer_kwargs): - """ - Postprocess the output results after the inference task ends. - """ - pass - - - class ForecastPipeline(BasicPipeline): - def __init__(self, model_info, **model_kwargs): - super().__init__(model_info, model_kwargs=model_kwargs) - - def preprocess(self, inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], **infer_kwargs): - """ - Preprocess the input data before passing it to the model for inference, verifying the shape and type of input data. - - Args: - inputs (list[dict]): - Input data, a list of dictionaries, each dictionary contains: - - 'targets': a tensor of shape (input_length,) or (target_count, input_length). - - 'past_covariates': optional, a dictionary of tensors, each tensor shape is (input_length,). - - 'future_covariates': optional, a dictionary of tensors, each tensor shape is (input_length,). - - infer_kwargs (dict, optional): Additional inference keyword parameters, such as: - - `output_length`(int): If 'future_covariates' is provided, used to validate its validity. - - Raises: - ValueError: If the input format is incorrect (e.g., missing keys, invalid tensor shapes). - - Returns: - Preprocessed and validated input data, ready for model inference. - """ - pass - - def forecast(self, inputs, **infer_kwargs): - """ - Perform prediction on the given input. - - Parameters: - inputs: Input data for prediction. The type and structure depend on the specific implementation of the model. - **infer_kwargs: Additional inference parameters, such as: - - `output_length`(int): The number of time points the model should generate. - - Returns: - Prediction output, specific form depends on the specific implementation of the model. - """ - pass - - def postprocess(self, outputs: list[torch.Tensor], **infer_kwargs) -> list[torch.Tensor]: - """ - Postprocess the model output after inference, verifying the shape of output tensors and ensuring they meet the expected dimensions. - - Args: - outputs: - Model output, a list of 2D tensors, each tensor shape is `[target_count, output_length]`. - - Raises: - InferenceModelInternalException: If the output tensor shape is invalid (e.g., dimension error). - ValueError: If the output format is incorrect. - - Returns: - list[torch.Tensor]: - Postprocessed output, a list of 2D tensors. - """ - pass - ``` -3. Modify the model configuration file config.json to ensure it contains the following fields: - ```JSON - { - "auto_map": { - "AutoConfig": "config.Chronos2CoreConfig", // Specify the model Config class - "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class - }, - "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the model's inference pipeline - "model_type": "custom_t5", // Specify the model type - } - ``` - - * Must specify the model Config class and model class through auto\_map; - * Must integrate and specify the inference pipeline class; - * For AINode-managed built-in (builtin) and custom (user\_defined) models, the model category (model\_type) also serves as a unique identifier. That is, the model category to be registered must not be duplicated with any existing model type. Models created through fine-tuning will inherit the model category of the original model. + **Before V2.0.9.3** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + Preprocess the input data before the inference task starts, including shape validation and numerical conversion. + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + Postprocess the output results after the inference task is completed. + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def preprocess(self, inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], **infer_kwargs): + """ + Preprocess the input data before passing it to the model for inference, validating the shape and type of the input data. + + Args: + inputs (list[dict]): + Input data, a list of dictionaries, each dictionary contains: + - 'targets': Tensor with shape (input_length,) or (target_count, input_length). + - 'past_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + - 'future_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + + infer_kwargs (dict, optional): Additional keyword arguments for inference, such as: + - `output_length`(int): Used to validate the validity of 'future_covariates' if provided. + + Raises: + ValueError: If the input format is invalid (e.g., missing keys, invalid tensor shapes). + + Returns: + Preprocessed and validated input data that can be directly used for model inference. + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + Perform forecasting on the given inputs. + + Parameters: + inputs: Input data for forecasting. The type and structure depend on the specific model implementation. + **infer_kwargs: Additional inference parameters, e.g.: + - `output_length`(int): The number of time points the model should generate. + + Returns: + Forecast output, the specific form depends on the specific model implementation. + """ + pass + + def postprocess(self, outputs: list[torch.Tensor], **infer_kwargs) -> list[torch.Tensor]: + """ + Postprocess the model outputs after inference, validating the shape of the output data and ensuring it meets the expected dimensions. + + Args: + outputs: + Model outputs, a list of 2D tensors, each tensor with shape `[target_count, output_length]`. + + Raises: + InferenceModelInternalException: If the output tensor shape is invalid (e.g., incorrect dimensions). + ValueError: If the output format is incorrect. + + Returns: + list[torch.Tensor]: + Postprocessed outputs, which will be a list of 2D tensors. + """ + pass + ``` + + **From V2.0.9.3 onwards** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + Preprocess the input data before the inference task starts, including shape validation and numerical conversion. + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + Postprocess the output results after the inference task is completed. + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def _preprocess( + self, + inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], + **infer_kwargs, + ): + """ + Preprocess the input data before passing it to the model for inference, validating the shape and type of the input data. + + Args: + inputs (list[dict[str, dict[str, torch.Tensor] | torch.Tensor]]): + Input data, a list of dictionaries, each dictionary contains: + - 'targets': Tensor with shape (input_length,) or (target_count, input_length). + - 'past_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + - 'future_covariates': Optional, dictionary of tensors, each tensor with shape (input_length,). + + infer_kwargs (dict, optional): Additional keyword arguments for inference, such as: + - `output_length`(int): Used to validate the validity of 'future_covariates' if provided. + + Raises: + ValueError: If the input format is invalid (e.g., missing keys, invalid tensor shapes). + + Returns: + Preprocessed and validated input data that can be directly used for model inference. + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + Perform forecasting on the given inputs. + + Parameters: + inputs: Input data for forecasting. The type and structure depend on the specific model implementation. + **infer_kwargs: Additional inference parameters, e.g.: + - `output_length`(int): The number of time points the model should generate. + + Returns: + Forecast output, the specific form depends on the specific model implementation. + """ + pass + + def _postprocess(self, outputs, **infer_kwargs) -> list[torch.Tensor]: + """ + Postprocess the model outputs after inference, validating the shape of the output data and ensuring it meets the expected dimensions. + + Args: + outputs: + Model outputs, a list of 2D tensors, each tensor with shape `[target_count, output_length]`. + + Raises: + InferenceModelInternalException: If the output tensor shape is invalid (e.g., incorrect dimensions). + ValueError: If the output format is incorrect. + + Returns: + list[torch.Tensor]: + Postprocessed outputs, which will be a list of 2D tensors. + """ + pass + ``` + +3. Modify the model configuration file `config.json` to ensure it contains the following fields: + + **Before V2.0.9.3** + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // Specify the model Config class + "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the inference pipeline for the model + "model_type": "custom_t5", // Specify the model type + } + ``` + * The model Config class and model class **must** be specified via `auto_map`; + * The inference pipeline class **must** be inherited and specified; + * For built-in and user-defined models managed by AINode, `model_type` also serves as a unique non-duplicable identifier. That is, the model type to be registered must not duplicate any existing model types; models created via fine-tuning will inherit the model type of the original model. + + **From V2.0.9.3 onwards** + > The `model_type` parameter is **not required** + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // Specify the model Config class + "AutoModelForCausalLM": "model.Chronos2Model" // Specify the model class + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // Specify the inference pipeline for the model + } + ``` + * The model Config class and model class **must** be specified via `auto_map`; + * The inference pipeline class **must** be inherited and specified; + 4. Ensure that the model directory to be registered contains the following files, and the model configuration file name and weight file name are not customizable: * Model configuration file: config.json; * Model weight file: model.safetensors; diff --git a/src/zh/UserGuide/Master/Table/AI-capability/AINode_Upgrade_apache.md b/src/zh/UserGuide/Master/Table/AI-capability/AINode_Upgrade_apache.md index 59a261acd..6823c69a0 100644 --- a/src/zh/UserGuide/Master/Table/AI-capability/AINode_Upgrade_apache.md +++ b/src/zh/UserGuide/Master/Table/AI-capability/AINode_Upgrade_apache.md @@ -164,6 +164,7 @@ It costs 1.615s 2. 模型需继承一类 AINode 的推理任务流水线(当前支持预测流水线): * iotdb-core/ainode/iotdb/ainode/core/inference/pipeline/basic\_pipeline.py + **V2.0.9.3 之前** ```Python class BasicPipeline(ABC): def __init__(self, model_id, **model_kwargs): @@ -244,7 +245,96 @@ It costs 1.615s """ pass ``` + + **V2.0.9.3 起** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + 在推理任务开始前对输入数据进行前处理,包括形状验证和数值转换。 + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + 在推理任务结束后对输出结果进行后处理。 + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def _preprocess( + self, + inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], + **infer_kwargs, + ): + """ + 在将输入数据传递给模型进行推理之前进行预处理,验证输入数据的形状和类型。 + + Args: + inputs (list[dict[str, dict[str, torch.Tensor] | torch.Tensor]]): + 输入数据,字典列表,每个字典包含: + - 'targets': 形状为 (input_length,) 或 (target_count, input_length) 的张量。 + - 'past_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 + - 'future_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 + + infer_kwargs (dict, optional): 推理的额外关键字参数,如: + - `output_length`(int): 如果提供'future_covariates',用于验证其有效性。 + + Raises: + ValueError: 如果输入格式不正确(例如,缺少键、张量形状无效)。 + + Returns: + 经过预处理和验证的输入数据,可直接用于模型推理。 + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + 对给定输入执行预测。 + + Parameters: + inputs: 用于进行预测的输入数据。类型和结构取决于模型的具体实现。 + **infer_kwargs: 额外的推理参数,例如: + - `output_length`(int): 模型应该生成的时间点数量。 + + Returns: + 预测输出,具体形式取决于模型的具体实现。 + """ + pass + + def _postprocess(self, outputs, **infer_kwargs) -> list[torch.Tensor]: + """ + 在推理后对模型输出进行后处理,验证输出数据的形状并确保其符合预期维度。 + + Args: + outputs: + 模型输出,2D张量列表,每个张量形状为 `[target_count, output_length]`。 + + Raises: + InferenceModelInternalException: 如果输出张量形状无效(例如,维数错误)。 + ValueError: 如果输出格式不正确。 + + Returns: + list[torch.Tensor]: + 后处理后的输出,将是一个2D张量列表。 + """ + pass + ``` + 3. 修改模型配置文件 config.json,确保包含以下字段: + + **V2.0.9.3 之前** ```JSON { "auto_map": { @@ -256,9 +346,25 @@ It costs 1.615s } ``` - * 必须通过 auto\_map 指定模型的 Config 类和模型类; - * 必须集成并指定推理流水线类; - * 对于 AINode 管理的内置(builtin)和自定义(user\_defined)模型,模型类别(model\_type)也作为不可重复的唯一标识。即,要注册的模型类别不得与任何已存在的模型类型重复。 + * 必须通过 auto\_map 指定模型的 Config 类和模型类; + * 必须集成并指定推理流水线类; + * 对于 AINode 管理的内置(builtin)和自定义(user\_defined)模型,模型类别(model\_type)也作为不可重复的唯一标识。即,要注册的模型类别不得与任何已存在的模型类型重复,通过微调创建的模型将继承原模型的模型类别。 + + **V2.0.9.3 起** + > 参数 model_type 非必填 + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // 指定模型 Config 类 + "AutoModelForCausalLM": "model.Chronos2Model" // 指定模型类 + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // 指定模型的推理流水线 + } + ``` + * 必须通过 auto\_map 指定模型的 Config 类和模型类; + * 必须集成并指定推理流水线类; + + 4. 确保要注册的模型目录包含以下文件,且模型配置文件名称和权重文件名称不支持自定义: * 模型配置文件:config.json; * 模型权重文件:model.safetensors; diff --git a/src/zh/UserGuide/Master/Table/AI-capability/AINode_Upgrade_timecho.md b/src/zh/UserGuide/Master/Table/AI-capability/AINode_Upgrade_timecho.md index 3f8171ebd..a578df0c2 100644 --- a/src/zh/UserGuide/Master/Table/AI-capability/AINode_Upgrade_timecho.md +++ b/src/zh/UserGuide/Master/Table/AI-capability/AINode_Upgrade_timecho.md @@ -493,87 +493,177 @@ IoTDB> show models 2. 模型需继承一类 AINode 的推理任务流水线(当前支持预测流水线): * iotdb-core/ainode/iotdb/ainode/core/inference/pipeline/basic\_pipeline.py - ```Python - class BasicPipeline(ABC): - def __init__(self, model_id, **model_kwargs): - self.model_info = model_info - self.device = model_kwargs.get("device", "cpu") - self.model = load_model(model_info, device_map=self.device, **model_kwargs) + **V2.0.9.3 之前** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) - @abstractmethod - def preprocess(self, inputs, **infer_kwargs): - """ - 在推理任务开始前对输入数据进行前处理,包括形状验证和数值转换。 - """ - pass + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + 在推理任务开始前对输入数据进行前处理,包括形状验证和数值转换。 + """ + pass - @abstractmethod - def postprocess(self, output, **infer_kwargs): - """ - 在推理任务结束后对输出结果进行后处理。 - """ - pass + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + 在推理任务结束后对输出结果进行后处理。 + """ + pass - class ForecastPipeline(BasicPipeline): - def __init__(self, model_info, **model_kwargs): - super().__init__(model_info, model_kwargs=model_kwargs) + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) - def preprocess(self, inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], **infer_kwargs): - """ - 在将输入数据传递给模型进行推理之前进行预处理,验证输入数据的形状和类型。 + def preprocess(self, inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], **infer_kwargs): + """ + 在将输入数据传递给模型进行推理之前进行预处理,验证输入数据的形状和类型。 - Args: - inputs (list[dict]): - 输入数据,字典列表,每个字典包含: - - 'targets': 形状为 (input_length,) 或 (target_count, input_length) 的张量。 - - 'past_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 - - 'future_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 + Args: + inputs (list[dict]): + 输入数据,字典列表,每个字典包含: + - 'targets': 形状为 (input_length,) 或 (target_count, input_length) 的张量。 + - 'past_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 + - 'future_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 - infer_kwargs (dict, optional): 推理的额外关键字参数,如: - - `output_length`(int): 如果提供'future_covariates',用于验证其有效性。 + infer_kwargs (dict, optional): 推理的额外关键字参数,如: + - `output_length`(int): 如果提供'future_covariates',用于验证其有效性。 - Raises: - ValueError: 如果输入格式不正确(例如,缺少键、张量形状无效)。 + Raises: + ValueError: 如果输入格式不正确(例如,缺少键、张量形状无效)。 - Returns: - 经过预处理和验证的输入数据,可直接用于模型推理。 - """ - pass + Returns: + 经过预处理和验证的输入数据,可直接用于模型推理。 + """ + pass - def forecast(self, inputs, **infer_kwargs): - """ - 对给定输入执行预测。 + def forecast(self, inputs, **infer_kwargs): + """ + 对给定输入执行预测。 - Parameters: - inputs: 用于进行预测的输入数据。类型和结构取决于模型的具体实现。 - **infer_kwargs: 额外的推理参数,例如: - - `output_length`(int): 模型应该生成的时间点数量。 + Parameters: + inputs: 用于进行预测的输入数据。类型和结构取决于模型的具体实现。 + **infer_kwargs: 额外的推理参数,例如: + - `output_length`(int): 模型应该生成的时间点数量。 - Returns: - 预测输出,具体形式取决于模型的具体实现。 - """ - pass + Returns: + 预测输出,具体形式取决于模型的具体实现。 + """ + pass - def postprocess(self, outputs: list[torch.Tensor], **infer_kwargs) -> list[torch.Tensor]: - """ - 在推理后对模型输出进行后处理,验证输出数据的形状并确保其符合预期维度。 + def postprocess(self, outputs: list[torch.Tensor], **infer_kwargs) -> list[torch.Tensor]: + """ + 在推理后对模型输出进行后处理,验证输出数据的形状并确保其符合预期维度。 - Args: - outputs: - 模型输出,2D张量列表,每个张量形状为 `[target_count, output_length]`。 + Args: + outputs: + 模型输出,2D张量列表,每个张量形状为 `[target_count, output_length]`。 - Raises: - InferenceModelInternalException: 如果输出张量形状无效(例如,维数错误)。 - ValueError: 如果输出格式不正确。 + Raises: + InferenceModelInternalException: 如果输出张量形状无效(例如,维数错误)。 + ValueError: 如果输出格式不正确。 - Returns: - list[torch.Tensor]: - 后处理后的输出,将是一个2D张量列表。 - """ - pass - ``` + Returns: + list[torch.Tensor]: + 后处理后的输出,将是一个2D张量列表。 + """ + pass + ``` + + **V2.0.9.3 起** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + 在推理任务开始前对输入数据进行前处理,包括形状验证和数值转换。 + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + 在推理任务结束后对输出结果进行后处理。 + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def _preprocess( + self, + inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], + **infer_kwargs, + ): + """ + 在将输入数据传递给模型进行推理之前进行预处理,验证输入数据的形状和类型。 + + Args: + inputs (list[dict[str, dict[str, torch.Tensor] | torch.Tensor]]): + 输入数据,字典列表,每个字典包含: + - 'targets': 形状为 (input_length,) 或 (target_count, input_length) 的张量。 + - 'past_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 + - 'future_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 + + infer_kwargs (dict, optional): 推理的额外关键字参数,如: + - `output_length`(int): 如果提供'future_covariates',用于验证其有效性。 + + Raises: + ValueError: 如果输入格式不正确(例如,缺少键、张量形状无效)。 + + Returns: + 经过预处理和验证的输入数据,可直接用于模型推理。 + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + 对给定输入执行预测。 + + Parameters: + inputs: 用于进行预测的输入数据。类型和结构取决于模型的具体实现。 + **infer_kwargs: 额外的推理参数,例如: + - `output_length`(int): 模型应该生成的时间点数量。 + + Returns: + 预测输出,具体形式取决于模型的具体实现。 + """ + pass + + def _postprocess(self, outputs, **infer_kwargs) -> list[torch.Tensor]: + """ + 在推理后对模型输出进行后处理,验证输出数据的形状并确保其符合预期维度。 + + Args: + outputs: + 模型输出,2D张量列表,每个张量形状为 `[target_count, output_length]`。 + + Raises: + InferenceModelInternalException: 如果输出张量形状无效(例如,维数错误)。 + ValueError: 如果输出格式不正确。 + + Returns: + list[torch.Tensor]: + 后处理后的输出,将是一个2D张量列表。 + """ + pass + ``` + 3. 修改模型配置文件 config.json,确保包含以下字段: + + **V2.0.9.3 之前** ```JSON { "auto_map": { @@ -585,9 +675,25 @@ IoTDB> show models } ``` - * 必须通过 auto\_map 指定模型的 Config 类和模型类; - * 必须集成并指定推理流水线类; - * 对于 AINode 管理的内置(builtin)和自定义(user\_defined)模型,模型类别(model\_type)也作为不可重复的唯一标识。即,要注册的模型类别不得与任何已存在的模型类型重复,通过微调创建的模型将继承原模型的模型类别。 + * 必须通过 auto\_map 指定模型的 Config 类和模型类; + * 必须集成并指定推理流水线类; + * 对于 AINode 管理的内置(builtin)和自定义(user\_defined)模型,模型类别(model\_type)也作为不可重复的唯一标识。即,要注册的模型类别不得与任何已存在的模型类型重复,通过微调创建的模型将继承原模型的模型类别。 + + **V2.0.9.3 起** + > 参数 model_type 非必填 + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // 指定模型 Config 类 + "AutoModelForCausalLM": "model.Chronos2Model" // 指定模型类 + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // 指定模型的推理流水线 + } + ``` + * 必须通过 auto\_map 指定模型的 Config 类和模型类; + * 必须集成并指定推理流水线类; + + 4. 确保要注册的模型目录包含以下文件,且模型配置文件名称和权重文件名称不支持自定义: * 模型配置文件:config.json; * 模型权重文件:model.safetensors; diff --git a/src/zh/UserGuide/Master/Tree/AI-capability/AINode_Upgrade_apache.md b/src/zh/UserGuide/Master/Tree/AI-capability/AINode_Upgrade_apache.md index 95356315b..3af7a5e99 100644 --- a/src/zh/UserGuide/Master/Tree/AI-capability/AINode_Upgrade_apache.md +++ b/src/zh/UserGuide/Master/Tree/AI-capability/AINode_Upgrade_apache.md @@ -140,6 +140,7 @@ Total line number = 48 2. 模型需继承一类 AINode 的推理任务流水线(当前支持预测流水线): * iotdb-core/ainode/iotdb/ainode/core/inference/pipeline/basic\_pipeline.py + **V2.0.9.3 之前** ```Python class BasicPipeline(ABC): def __init__(self, model_id, **model_kwargs): @@ -220,7 +221,96 @@ Total line number = 48 """ pass ``` + + **V2.0.9.3 起** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + 在推理任务开始前对输入数据进行前处理,包括形状验证和数值转换。 + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + 在推理任务结束后对输出结果进行后处理。 + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def _preprocess( + self, + inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], + **infer_kwargs, + ): + """ + 在将输入数据传递给模型进行推理之前进行预处理,验证输入数据的形状和类型。 + + Args: + inputs (list[dict[str, dict[str, torch.Tensor] | torch.Tensor]]): + 输入数据,字典列表,每个字典包含: + - 'targets': 形状为 (input_length,) 或 (target_count, input_length) 的张量。 + - 'past_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 + - 'future_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 + + infer_kwargs (dict, optional): 推理的额外关键字参数,如: + - `output_length`(int): 如果提供'future_covariates',用于验证其有效性。 + + Raises: + ValueError: 如果输入格式不正确(例如,缺少键、张量形状无效)。 + + Returns: + 经过预处理和验证的输入数据,可直接用于模型推理。 + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + 对给定输入执行预测。 + + Parameters: + inputs: 用于进行预测的输入数据。类型和结构取决于模型的具体实现。 + **infer_kwargs: 额外的推理参数,例如: + - `output_length`(int): 模型应该生成的时间点数量。 + + Returns: + 预测输出,具体形式取决于模型的具体实现。 + """ + pass + + def _postprocess(self, outputs, **infer_kwargs) -> list[torch.Tensor]: + """ + 在推理后对模型输出进行后处理,验证输出数据的形状并确保其符合预期维度。 + + Args: + outputs: + 模型输出,2D张量列表,每个张量形状为 `[target_count, output_length]`。 + + Raises: + InferenceModelInternalException: 如果输出张量形状无效(例如,维数错误)。 + ValueError: 如果输出格式不正确。 + + Returns: + list[torch.Tensor]: + 后处理后的输出,将是一个2D张量列表。 + """ + pass + ``` + 3. 修改模型配置文件 config.json,确保包含以下字段: + + **V2.0.9.3 之前** ```JSON { "auto_map": { @@ -232,9 +322,25 @@ Total line number = 48 } ``` - * 必须通过 auto\_map 指定模型的 Config 类和模型类; - * 必须集成并指定推理流水线类; - * 对于 AINode 管理的内置(builtin)和自定义(user\_defined)模型,模型类别(model\_type)也作为不可重复的唯一标识。即,要注册的模型类别不得与任何已存在的模型类型重复。 + * 必须通过 auto\_map 指定模型的 Config 类和模型类; + * 必须集成并指定推理流水线类; + * 对于 AINode 管理的内置(builtin)和自定义(user\_defined)模型,模型类别(model\_type)也作为不可重复的唯一标识。即,要注册的模型类别不得与任何已存在的模型类型重复,通过微调创建的模型将继承原模型的模型类别。 + + **V2.0.9.3 起** + > 参数 model_type 非必填 + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // 指定模型 Config 类 + "AutoModelForCausalLM": "model.Chronos2Model" // 指定模型类 + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // 指定模型的推理流水线 + } + ``` + * 必须通过 auto\_map 指定模型的 Config 类和模型类; + * 必须集成并指定推理流水线类; + + 4. 确保要注册的模型目录包含以下文件,且模型配置文件名称和权重文件名称不支持自定义: * 模型配置文件:config.json; * 模型权重文件:model.safetensors; diff --git a/src/zh/UserGuide/Master/Tree/AI-capability/AINode_Upgrade_timecho.md b/src/zh/UserGuide/Master/Tree/AI-capability/AINode_Upgrade_timecho.md index 1cffb75ce..e7464bc7f 100644 --- a/src/zh/UserGuide/Master/Tree/AI-capability/AINode_Upgrade_timecho.md +++ b/src/zh/UserGuide/Master/Tree/AI-capability/AINode_Upgrade_timecho.md @@ -221,6 +221,7 @@ IoTDB> show models 2. 模型需继承一类 AINode 的推理任务流水线(当前支持预测流水线): * iotdb-core/ainode/iotdb/ainode/core/inference/pipeline/basic\_pipeline.py + **V2.0.9.3 之前** ```Python class BasicPipeline(ABC): def __init__(self, model_id, **model_kwargs): @@ -301,7 +302,96 @@ IoTDB> show models """ pass ``` + + **V2.0.9.3 起** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + 在推理任务开始前对输入数据进行前处理,包括形状验证和数值转换。 + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + 在推理任务结束后对输出结果进行后处理。 + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def _preprocess( + self, + inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], + **infer_kwargs, + ): + """ + 在将输入数据传递给模型进行推理之前进行预处理,验证输入数据的形状和类型。 + + Args: + inputs (list[dict[str, dict[str, torch.Tensor] | torch.Tensor]]): + 输入数据,字典列表,每个字典包含: + - 'targets': 形状为 (input_length,) 或 (target_count, input_length) 的张量。 + - 'past_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 + - 'future_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 + + infer_kwargs (dict, optional): 推理的额外关键字参数,如: + - `output_length`(int): 如果提供'future_covariates',用于验证其有效性。 + + Raises: + ValueError: 如果输入格式不正确(例如,缺少键、张量形状无效)。 + + Returns: + 经过预处理和验证的输入数据,可直接用于模型推理。 + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + 对给定输入执行预测。 + + Parameters: + inputs: 用于进行预测的输入数据。类型和结构取决于模型的具体实现。 + **infer_kwargs: 额外的推理参数,例如: + - `output_length`(int): 模型应该生成的时间点数量。 + + Returns: + 预测输出,具体形式取决于模型的具体实现。 + """ + pass + + def _postprocess(self, outputs, **infer_kwargs) -> list[torch.Tensor]: + """ + 在推理后对模型输出进行后处理,验证输出数据的形状并确保其符合预期维度。 + + Args: + outputs: + 模型输出,2D张量列表,每个张量形状为 `[target_count, output_length]`。 + + Raises: + InferenceModelInternalException: 如果输出张量形状无效(例如,维数错误)。 + ValueError: 如果输出格式不正确。 + + Returns: + list[torch.Tensor]: + 后处理后的输出,将是一个2D张量列表。 + """ + pass + ``` + 3. 修改模型配置文件 config.json,确保包含以下字段: + + **V2.0.9.3 之前** ```JSON { "auto_map": { @@ -316,6 +406,22 @@ IoTDB> show models * 必须通过 auto\_map 指定模型的 Config 类和模型类; * 必须集成并指定推理流水线类; * 对于 AINode 管理的内置(builtin)和自定义(user\_defined)模型,模型类别(model\_type)也作为不可重复的唯一标识。即,要注册的模型类别不得与任何已存在的模型类型重复,通过微调创建的模型将继承原模型的模型类别。 + + **V2.0.9.3 起** + > 参数 model_type 非必填 + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // 指定模型 Config 类 + "AutoModelForCausalLM": "model.Chronos2Model" // 指定模型类 + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // 指定模型的推理流水线 + } + ``` + * 必须通过 auto\_map 指定模型的 Config 类和模型类; + * 必须集成并指定推理流水线类; + + 4. 确保要注册的模型目录包含以下文件,且模型配置文件名称和权重文件名称不支持自定义: * 模型配置文件:config.json; * 模型权重文件:model.safetensors; diff --git a/src/zh/UserGuide/latest-Table/AI-capability/AINode_Upgrade_apache.md b/src/zh/UserGuide/latest-Table/AI-capability/AINode_Upgrade_apache.md index 59a261acd..6823c69a0 100644 --- a/src/zh/UserGuide/latest-Table/AI-capability/AINode_Upgrade_apache.md +++ b/src/zh/UserGuide/latest-Table/AI-capability/AINode_Upgrade_apache.md @@ -164,6 +164,7 @@ It costs 1.615s 2. 模型需继承一类 AINode 的推理任务流水线(当前支持预测流水线): * iotdb-core/ainode/iotdb/ainode/core/inference/pipeline/basic\_pipeline.py + **V2.0.9.3 之前** ```Python class BasicPipeline(ABC): def __init__(self, model_id, **model_kwargs): @@ -244,7 +245,96 @@ It costs 1.615s """ pass ``` + + **V2.0.9.3 起** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + 在推理任务开始前对输入数据进行前处理,包括形状验证和数值转换。 + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + 在推理任务结束后对输出结果进行后处理。 + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def _preprocess( + self, + inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], + **infer_kwargs, + ): + """ + 在将输入数据传递给模型进行推理之前进行预处理,验证输入数据的形状和类型。 + + Args: + inputs (list[dict[str, dict[str, torch.Tensor] | torch.Tensor]]): + 输入数据,字典列表,每个字典包含: + - 'targets': 形状为 (input_length,) 或 (target_count, input_length) 的张量。 + - 'past_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 + - 'future_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 + + infer_kwargs (dict, optional): 推理的额外关键字参数,如: + - `output_length`(int): 如果提供'future_covariates',用于验证其有效性。 + + Raises: + ValueError: 如果输入格式不正确(例如,缺少键、张量形状无效)。 + + Returns: + 经过预处理和验证的输入数据,可直接用于模型推理。 + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + 对给定输入执行预测。 + + Parameters: + inputs: 用于进行预测的输入数据。类型和结构取决于模型的具体实现。 + **infer_kwargs: 额外的推理参数,例如: + - `output_length`(int): 模型应该生成的时间点数量。 + + Returns: + 预测输出,具体形式取决于模型的具体实现。 + """ + pass + + def _postprocess(self, outputs, **infer_kwargs) -> list[torch.Tensor]: + """ + 在推理后对模型输出进行后处理,验证输出数据的形状并确保其符合预期维度。 + + Args: + outputs: + 模型输出,2D张量列表,每个张量形状为 `[target_count, output_length]`。 + + Raises: + InferenceModelInternalException: 如果输出张量形状无效(例如,维数错误)。 + ValueError: 如果输出格式不正确。 + + Returns: + list[torch.Tensor]: + 后处理后的输出,将是一个2D张量列表。 + """ + pass + ``` + 3. 修改模型配置文件 config.json,确保包含以下字段: + + **V2.0.9.3 之前** ```JSON { "auto_map": { @@ -256,9 +346,25 @@ It costs 1.615s } ``` - * 必须通过 auto\_map 指定模型的 Config 类和模型类; - * 必须集成并指定推理流水线类; - * 对于 AINode 管理的内置(builtin)和自定义(user\_defined)模型,模型类别(model\_type)也作为不可重复的唯一标识。即,要注册的模型类别不得与任何已存在的模型类型重复。 + * 必须通过 auto\_map 指定模型的 Config 类和模型类; + * 必须集成并指定推理流水线类; + * 对于 AINode 管理的内置(builtin)和自定义(user\_defined)模型,模型类别(model\_type)也作为不可重复的唯一标识。即,要注册的模型类别不得与任何已存在的模型类型重复,通过微调创建的模型将继承原模型的模型类别。 + + **V2.0.9.3 起** + > 参数 model_type 非必填 + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // 指定模型 Config 类 + "AutoModelForCausalLM": "model.Chronos2Model" // 指定模型类 + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // 指定模型的推理流水线 + } + ``` + * 必须通过 auto\_map 指定模型的 Config 类和模型类; + * 必须集成并指定推理流水线类; + + 4. 确保要注册的模型目录包含以下文件,且模型配置文件名称和权重文件名称不支持自定义: * 模型配置文件:config.json; * 模型权重文件:model.safetensors; diff --git a/src/zh/UserGuide/latest-Table/AI-capability/AINode_Upgrade_timecho.md b/src/zh/UserGuide/latest-Table/AI-capability/AINode_Upgrade_timecho.md index 3f8171ebd..a578df0c2 100644 --- a/src/zh/UserGuide/latest-Table/AI-capability/AINode_Upgrade_timecho.md +++ b/src/zh/UserGuide/latest-Table/AI-capability/AINode_Upgrade_timecho.md @@ -493,87 +493,177 @@ IoTDB> show models 2. 模型需继承一类 AINode 的推理任务流水线(当前支持预测流水线): * iotdb-core/ainode/iotdb/ainode/core/inference/pipeline/basic\_pipeline.py - ```Python - class BasicPipeline(ABC): - def __init__(self, model_id, **model_kwargs): - self.model_info = model_info - self.device = model_kwargs.get("device", "cpu") - self.model = load_model(model_info, device_map=self.device, **model_kwargs) + **V2.0.9.3 之前** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) - @abstractmethod - def preprocess(self, inputs, **infer_kwargs): - """ - 在推理任务开始前对输入数据进行前处理,包括形状验证和数值转换。 - """ - pass + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + 在推理任务开始前对输入数据进行前处理,包括形状验证和数值转换。 + """ + pass - @abstractmethod - def postprocess(self, output, **infer_kwargs): - """ - 在推理任务结束后对输出结果进行后处理。 - """ - pass + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + 在推理任务结束后对输出结果进行后处理。 + """ + pass - class ForecastPipeline(BasicPipeline): - def __init__(self, model_info, **model_kwargs): - super().__init__(model_info, model_kwargs=model_kwargs) + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) - def preprocess(self, inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], **infer_kwargs): - """ - 在将输入数据传递给模型进行推理之前进行预处理,验证输入数据的形状和类型。 + def preprocess(self, inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], **infer_kwargs): + """ + 在将输入数据传递给模型进行推理之前进行预处理,验证输入数据的形状和类型。 - Args: - inputs (list[dict]): - 输入数据,字典列表,每个字典包含: - - 'targets': 形状为 (input_length,) 或 (target_count, input_length) 的张量。 - - 'past_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 - - 'future_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 + Args: + inputs (list[dict]): + 输入数据,字典列表,每个字典包含: + - 'targets': 形状为 (input_length,) 或 (target_count, input_length) 的张量。 + - 'past_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 + - 'future_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 - infer_kwargs (dict, optional): 推理的额外关键字参数,如: - - `output_length`(int): 如果提供'future_covariates',用于验证其有效性。 + infer_kwargs (dict, optional): 推理的额外关键字参数,如: + - `output_length`(int): 如果提供'future_covariates',用于验证其有效性。 - Raises: - ValueError: 如果输入格式不正确(例如,缺少键、张量形状无效)。 + Raises: + ValueError: 如果输入格式不正确(例如,缺少键、张量形状无效)。 - Returns: - 经过预处理和验证的输入数据,可直接用于模型推理。 - """ - pass + Returns: + 经过预处理和验证的输入数据,可直接用于模型推理。 + """ + pass - def forecast(self, inputs, **infer_kwargs): - """ - 对给定输入执行预测。 + def forecast(self, inputs, **infer_kwargs): + """ + 对给定输入执行预测。 - Parameters: - inputs: 用于进行预测的输入数据。类型和结构取决于模型的具体实现。 - **infer_kwargs: 额外的推理参数,例如: - - `output_length`(int): 模型应该生成的时间点数量。 + Parameters: + inputs: 用于进行预测的输入数据。类型和结构取决于模型的具体实现。 + **infer_kwargs: 额外的推理参数,例如: + - `output_length`(int): 模型应该生成的时间点数量。 - Returns: - 预测输出,具体形式取决于模型的具体实现。 - """ - pass + Returns: + 预测输出,具体形式取决于模型的具体实现。 + """ + pass - def postprocess(self, outputs: list[torch.Tensor], **infer_kwargs) -> list[torch.Tensor]: - """ - 在推理后对模型输出进行后处理,验证输出数据的形状并确保其符合预期维度。 + def postprocess(self, outputs: list[torch.Tensor], **infer_kwargs) -> list[torch.Tensor]: + """ + 在推理后对模型输出进行后处理,验证输出数据的形状并确保其符合预期维度。 - Args: - outputs: - 模型输出,2D张量列表,每个张量形状为 `[target_count, output_length]`。 + Args: + outputs: + 模型输出,2D张量列表,每个张量形状为 `[target_count, output_length]`。 - Raises: - InferenceModelInternalException: 如果输出张量形状无效(例如,维数错误)。 - ValueError: 如果输出格式不正确。 + Raises: + InferenceModelInternalException: 如果输出张量形状无效(例如,维数错误)。 + ValueError: 如果输出格式不正确。 - Returns: - list[torch.Tensor]: - 后处理后的输出,将是一个2D张量列表。 - """ - pass - ``` + Returns: + list[torch.Tensor]: + 后处理后的输出,将是一个2D张量列表。 + """ + pass + ``` + + **V2.0.9.3 起** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + 在推理任务开始前对输入数据进行前处理,包括形状验证和数值转换。 + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + 在推理任务结束后对输出结果进行后处理。 + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def _preprocess( + self, + inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], + **infer_kwargs, + ): + """ + 在将输入数据传递给模型进行推理之前进行预处理,验证输入数据的形状和类型。 + + Args: + inputs (list[dict[str, dict[str, torch.Tensor] | torch.Tensor]]): + 输入数据,字典列表,每个字典包含: + - 'targets': 形状为 (input_length,) 或 (target_count, input_length) 的张量。 + - 'past_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 + - 'future_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 + + infer_kwargs (dict, optional): 推理的额外关键字参数,如: + - `output_length`(int): 如果提供'future_covariates',用于验证其有效性。 + + Raises: + ValueError: 如果输入格式不正确(例如,缺少键、张量形状无效)。 + + Returns: + 经过预处理和验证的输入数据,可直接用于模型推理。 + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + 对给定输入执行预测。 + + Parameters: + inputs: 用于进行预测的输入数据。类型和结构取决于模型的具体实现。 + **infer_kwargs: 额外的推理参数,例如: + - `output_length`(int): 模型应该生成的时间点数量。 + + Returns: + 预测输出,具体形式取决于模型的具体实现。 + """ + pass + + def _postprocess(self, outputs, **infer_kwargs) -> list[torch.Tensor]: + """ + 在推理后对模型输出进行后处理,验证输出数据的形状并确保其符合预期维度。 + + Args: + outputs: + 模型输出,2D张量列表,每个张量形状为 `[target_count, output_length]`。 + + Raises: + InferenceModelInternalException: 如果输出张量形状无效(例如,维数错误)。 + ValueError: 如果输出格式不正确。 + + Returns: + list[torch.Tensor]: + 后处理后的输出,将是一个2D张量列表。 + """ + pass + ``` + 3. 修改模型配置文件 config.json,确保包含以下字段: + + **V2.0.9.3 之前** ```JSON { "auto_map": { @@ -585,9 +675,25 @@ IoTDB> show models } ``` - * 必须通过 auto\_map 指定模型的 Config 类和模型类; - * 必须集成并指定推理流水线类; - * 对于 AINode 管理的内置(builtin)和自定义(user\_defined)模型,模型类别(model\_type)也作为不可重复的唯一标识。即,要注册的模型类别不得与任何已存在的模型类型重复,通过微调创建的模型将继承原模型的模型类别。 + * 必须通过 auto\_map 指定模型的 Config 类和模型类; + * 必须集成并指定推理流水线类; + * 对于 AINode 管理的内置(builtin)和自定义(user\_defined)模型,模型类别(model\_type)也作为不可重复的唯一标识。即,要注册的模型类别不得与任何已存在的模型类型重复,通过微调创建的模型将继承原模型的模型类别。 + + **V2.0.9.3 起** + > 参数 model_type 非必填 + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // 指定模型 Config 类 + "AutoModelForCausalLM": "model.Chronos2Model" // 指定模型类 + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // 指定模型的推理流水线 + } + ``` + * 必须通过 auto\_map 指定模型的 Config 类和模型类; + * 必须集成并指定推理流水线类; + + 4. 确保要注册的模型目录包含以下文件,且模型配置文件名称和权重文件名称不支持自定义: * 模型配置文件:config.json; * 模型权重文件:model.safetensors; diff --git a/src/zh/UserGuide/latest/AI-capability/AINode_Upgrade_apache.md b/src/zh/UserGuide/latest/AI-capability/AINode_Upgrade_apache.md index 95356315b..3af7a5e99 100644 --- a/src/zh/UserGuide/latest/AI-capability/AINode_Upgrade_apache.md +++ b/src/zh/UserGuide/latest/AI-capability/AINode_Upgrade_apache.md @@ -140,6 +140,7 @@ Total line number = 48 2. 模型需继承一类 AINode 的推理任务流水线(当前支持预测流水线): * iotdb-core/ainode/iotdb/ainode/core/inference/pipeline/basic\_pipeline.py + **V2.0.9.3 之前** ```Python class BasicPipeline(ABC): def __init__(self, model_id, **model_kwargs): @@ -220,7 +221,96 @@ Total line number = 48 """ pass ``` + + **V2.0.9.3 起** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + 在推理任务开始前对输入数据进行前处理,包括形状验证和数值转换。 + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + 在推理任务结束后对输出结果进行后处理。 + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def _preprocess( + self, + inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], + **infer_kwargs, + ): + """ + 在将输入数据传递给模型进行推理之前进行预处理,验证输入数据的形状和类型。 + + Args: + inputs (list[dict[str, dict[str, torch.Tensor] | torch.Tensor]]): + 输入数据,字典列表,每个字典包含: + - 'targets': 形状为 (input_length,) 或 (target_count, input_length) 的张量。 + - 'past_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 + - 'future_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 + + infer_kwargs (dict, optional): 推理的额外关键字参数,如: + - `output_length`(int): 如果提供'future_covariates',用于验证其有效性。 + + Raises: + ValueError: 如果输入格式不正确(例如,缺少键、张量形状无效)。 + + Returns: + 经过预处理和验证的输入数据,可直接用于模型推理。 + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + 对给定输入执行预测。 + + Parameters: + inputs: 用于进行预测的输入数据。类型和结构取决于模型的具体实现。 + **infer_kwargs: 额外的推理参数,例如: + - `output_length`(int): 模型应该生成的时间点数量。 + + Returns: + 预测输出,具体形式取决于模型的具体实现。 + """ + pass + + def _postprocess(self, outputs, **infer_kwargs) -> list[torch.Tensor]: + """ + 在推理后对模型输出进行后处理,验证输出数据的形状并确保其符合预期维度。 + + Args: + outputs: + 模型输出,2D张量列表,每个张量形状为 `[target_count, output_length]`。 + + Raises: + InferenceModelInternalException: 如果输出张量形状无效(例如,维数错误)。 + ValueError: 如果输出格式不正确。 + + Returns: + list[torch.Tensor]: + 后处理后的输出,将是一个2D张量列表。 + """ + pass + ``` + 3. 修改模型配置文件 config.json,确保包含以下字段: + + **V2.0.9.3 之前** ```JSON { "auto_map": { @@ -232,9 +322,25 @@ Total line number = 48 } ``` - * 必须通过 auto\_map 指定模型的 Config 类和模型类; - * 必须集成并指定推理流水线类; - * 对于 AINode 管理的内置(builtin)和自定义(user\_defined)模型,模型类别(model\_type)也作为不可重复的唯一标识。即,要注册的模型类别不得与任何已存在的模型类型重复。 + * 必须通过 auto\_map 指定模型的 Config 类和模型类; + * 必须集成并指定推理流水线类; + * 对于 AINode 管理的内置(builtin)和自定义(user\_defined)模型,模型类别(model\_type)也作为不可重复的唯一标识。即,要注册的模型类别不得与任何已存在的模型类型重复,通过微调创建的模型将继承原模型的模型类别。 + + **V2.0.9.3 起** + > 参数 model_type 非必填 + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // 指定模型 Config 类 + "AutoModelForCausalLM": "model.Chronos2Model" // 指定模型类 + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // 指定模型的推理流水线 + } + ``` + * 必须通过 auto\_map 指定模型的 Config 类和模型类; + * 必须集成并指定推理流水线类; + + 4. 确保要注册的模型目录包含以下文件,且模型配置文件名称和权重文件名称不支持自定义: * 模型配置文件:config.json; * 模型权重文件:model.safetensors; diff --git a/src/zh/UserGuide/latest/AI-capability/AINode_Upgrade_timecho.md b/src/zh/UserGuide/latest/AI-capability/AINode_Upgrade_timecho.md index 1cffb75ce..e7464bc7f 100644 --- a/src/zh/UserGuide/latest/AI-capability/AINode_Upgrade_timecho.md +++ b/src/zh/UserGuide/latest/AI-capability/AINode_Upgrade_timecho.md @@ -221,6 +221,7 @@ IoTDB> show models 2. 模型需继承一类 AINode 的推理任务流水线(当前支持预测流水线): * iotdb-core/ainode/iotdb/ainode/core/inference/pipeline/basic\_pipeline.py + **V2.0.9.3 之前** ```Python class BasicPipeline(ABC): def __init__(self, model_id, **model_kwargs): @@ -301,7 +302,96 @@ IoTDB> show models """ pass ``` + + **V2.0.9.3 起** + ```Python + class BasicPipeline(ABC): + def __init__(self, model_id, **model_kwargs): + self.model_info = model_info + self.device = model_kwargs.get("device", "cpu") + self.model = load_model(model_info, device_map=self.device, **model_kwargs) + + @abstractmethod + def preprocess(self, inputs, **infer_kwargs): + """ + 在推理任务开始前对输入数据进行前处理,包括形状验证和数值转换。 + """ + pass + + @abstractmethod + def postprocess(self, output, **infer_kwargs): + """ + 在推理任务结束后对输出结果进行后处理。 + """ + pass + + + class ForecastPipeline(BasicPipeline): + def __init__(self, model_info, **model_kwargs): + super().__init__(model_info, model_kwargs=model_kwargs) + + def _preprocess( + self, + inputs: list[dict[str, dict[str, torch.Tensor] | torch.Tensor]], + **infer_kwargs, + ): + """ + 在将输入数据传递给模型进行推理之前进行预处理,验证输入数据的形状和类型。 + + Args: + inputs (list[dict[str, dict[str, torch.Tensor] | torch.Tensor]]): + 输入数据,字典列表,每个字典包含: + - 'targets': 形状为 (input_length,) 或 (target_count, input_length) 的张量。 + - 'past_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 + - 'future_covariates': 可选,张量字典,每个张量形状为 (input_length,)。 + + infer_kwargs (dict, optional): 推理的额外关键字参数,如: + - `output_length`(int): 如果提供'future_covariates',用于验证其有效性。 + + Raises: + ValueError: 如果输入格式不正确(例如,缺少键、张量形状无效)。 + + Returns: + 经过预处理和验证的输入数据,可直接用于模型推理。 + """ + pass + + def forecast(self, inputs, **infer_kwargs): + """ + 对给定输入执行预测。 + + Parameters: + inputs: 用于进行预测的输入数据。类型和结构取决于模型的具体实现。 + **infer_kwargs: 额外的推理参数,例如: + - `output_length`(int): 模型应该生成的时间点数量。 + + Returns: + 预测输出,具体形式取决于模型的具体实现。 + """ + pass + + def _postprocess(self, outputs, **infer_kwargs) -> list[torch.Tensor]: + """ + 在推理后对模型输出进行后处理,验证输出数据的形状并确保其符合预期维度。 + + Args: + outputs: + 模型输出,2D张量列表,每个张量形状为 `[target_count, output_length]`。 + + Raises: + InferenceModelInternalException: 如果输出张量形状无效(例如,维数错误)。 + ValueError: 如果输出格式不正确。 + + Returns: + list[torch.Tensor]: + 后处理后的输出,将是一个2D张量列表。 + """ + pass + ``` + 3. 修改模型配置文件 config.json,确保包含以下字段: + + **V2.0.9.3 之前** ```JSON { "auto_map": { @@ -316,6 +406,22 @@ IoTDB> show models * 必须通过 auto\_map 指定模型的 Config 类和模型类; * 必须集成并指定推理流水线类; * 对于 AINode 管理的内置(builtin)和自定义(user\_defined)模型,模型类别(model\_type)也作为不可重复的唯一标识。即,要注册的模型类别不得与任何已存在的模型类型重复,通过微调创建的模型将继承原模型的模型类别。 + + **V2.0.9.3 起** + > 参数 model_type 非必填 + ```JSON + { + "auto_map": { + "AutoConfig": "config.Chronos2CoreConfig", // 指定模型 Config 类 + "AutoModelForCausalLM": "model.Chronos2Model" // 指定模型类 + }, + "pipeline_cls": "pipeline_chronos2.Chronos2Pipeline", // 指定模型的推理流水线 + } + ``` + * 必须通过 auto\_map 指定模型的 Config 类和模型类; + * 必须集成并指定推理流水线类; + + 4. 确保要注册的模型目录包含以下文件,且模型配置文件名称和权重文件名称不支持自定义: * 模型配置文件:config.json; * 模型权重文件:model.safetensors;