CRZbulabula commented on code in PR #16819: URL: https://github.com/apache/iotdb/pull/16819#discussion_r2584308024
########## iotdb-core/ainode/iotdb/ainode/core/model/sundial/pipeline_sundial.py: ########## @@ -0,0 +1,46 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +import torch + +from iotdb.ainode.core.inference.pipeline.basic_pipeline import ForecastPipeline + + +class SundialPipeline(ForecastPipeline): + def __init__(self, model_info, **infer_kwargs): + super().__init__(model_info, infer_kwargs=infer_kwargs) + + def _preprocess(self, inputs): + return super()._preprocess(inputs) + + def infer(self, inputs, **infer_kwargs): Review Comment: Integrate `infer` or `forecast`? ########## iotdb-core/ainode/iotdb/ainode/core/model/timer_xl/pipeline_timer.py: ########## @@ -0,0 +1,42 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +import torch + +from iotdb.ainode.core.inference.pipeline.basic_pipeline import ForecastPipeline + + +class TimerPipeline(ForecastPipeline): + def __init__(self, model_info, **infer_kwargs): + super().__init__(model_info, infer_kwargs=infer_kwargs) + + def _preprocess(self, inputs): + return super()._preprocess(inputs) + + def infer(self, inputs, **infer_kwargs): Review Comment: Integrate `infer` or `forecast`? ########## iotdb-core/ainode/iotdb/ainode/core/inference/inference_request_pool.py: ########## @@ -123,66 +116,32 @@ def _step(self): for requests in grouped_requests: batch_inputs = self._batcher.batch_request(requests).to(self.device) - if self.model_info.model_type == BuiltInModelType.SUNDIAL.value: - batch_output = self._model.generate( - batch_inputs, - max_new_tokens=requests[0].max_new_tokens, - num_samples=10, - revin=True, - ) - - offset = 0 - for request in requests: - request.output_tensor = request.output_tensor.to(self.device) - cur_batch_size = request.batch_size - cur_output = batch_output[offset : offset + cur_batch_size] - offset += cur_batch_size - request.write_step_output(cur_output.mean(dim=1)) - - request.inference_pipeline.post_decode() - if request.is_finished(): - request.inference_pipeline.post_inference() - self._logger.debug( - f"[Inference][Device-{self.device}][Pool-{self.pool_id}][ID-{request.req_id}] Request is finished" - ) - # ensure the output tensor is on CPU before sending to result queue - request.output_tensor = request.output_tensor.cpu() - self._finished_queue.put(request) - else: - self._logger.debug( - f"[Inference][Device-{self.device}][Pool-{self.pool_id}][ID-{request.req_id}] Request is not finished, re-queueing" - ) - self._waiting_queue.put(request) - - elif self.model_info.model_type == BuiltInModelType.TIMER_XL.value: - batch_output = self._model.generate( - batch_inputs, - max_new_tokens=requests[0].max_new_tokens, - revin=True, - ) - - offset = 0 - for request in requests: - request.output_tensor = request.output_tensor.to(self.device) - cur_batch_size = request.batch_size - cur_output = batch_output[offset : offset + cur_batch_size] - offset += cur_batch_size - request.write_step_output(cur_output) - - request.inference_pipeline.post_decode() - if request.is_finished(): - request.inference_pipeline.post_inference() - self._logger.debug( - f"[Inference][Device-{self.device}][Pool-{self.pool_id}][ID-{request.req_id}] Request is finished" - ) - # ensure the output tensor is on CPU before sending to result queue - request.output_tensor = request.output_tensor.cpu() - self._finished_queue.put(request) - else: - self._logger.debug( - f"[Inference][Device-{self.device}][Pool-{self.pool_id}][ID-{request.req_id}] Request is not finished, re-queueing" - ) - self._waiting_queue.put(request) + batch_output = self._inference_pipeline.infer( + batch_inputs, + predict_length=requests[0].max_new_tokens, + revin=True, + ) Review Comment: Plz check for how to unify the pipeline entrance. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
