Bắt đầu với Pipeline

 @card
    @step
    def start(self):
        """Start and prepare the Training pipeline."""
        import mlflow

        mlflow.set_tracking_uri(self.mlflow_tracking_uri)
        logging.info("MLflow tracking server: %s", self.mlflow_tracking_uri)

        self.mode = "production" if current.is_production else "development"
        logging.info("Running flow in %s mode.", self.mode)

        self.data = self.load_dataset()

        try:
            # Let's start a new MLflow run to track the execution of this flow. We want
            # to set the name of the MLflow run to the Metaflow run ID so we can easily
            # recognize how they relate to each other.
            run = mlflow.start_run(run_name=current.run_id)
            self.mlflow_run_id = run.info.run_id
        except Exception as e:
            message = f"Failed to connect to MLflow server {self.mlflow_tracking_uri}."
            raise RuntimeError(message) from e

        # Now that everything is set up, we want to run a cross-validation process
        # to evaluate the model and train a final model on the entire dataset. Since
        # these two steps are independent, we can run them in parallel.
        self.next(self.cross_validation, self.transform)

1. Decorators

@card
@step
def start(self):

2. Khởi tạo MLflow Tracking

 

import mlflow
mlflow.set_tracking_uri(self.mlflow_tracking_uri)
logging.info("MLflow tracking server: %s", self.mlflow_tracking_uri)

3. Xác định chế độ chạy

self.mode = "production" if current.is_production else "development"
logging.info("Running flow in %s mode.", self.mode)

4. Tải dữ liệu

self.data = self.load_dataset()
def load_dataset(self):
    return pd.read_csv("penguins.csv")

5. Thiết lập MLflow Run

try:
    run = mlflow.start_run(run_name=current.run_id)
    self.mlflow_run_id = run.info.run_id
except Exception as e:
    message = f"Failed to connect to MLflow server {self.mlflow_tracking_uri}."
    raise RuntimeError(message) from e

6. Chia nhánh pipeline

self.next(self.cross_validation, self.transform)

Tóm tắt luồng xử lý

  1. Thiết lập MLflow Tracking Server.

  2. Xác định chế độ chạy (production/development).

  3. Tải dữ liệu từ nguồn (CSV, database, API...).

  4. Bắt đầu MLflow Run và liên kết với Metaflow Run.

  5. Chia thành 2 nhánh song song: Cross-Validation và Transform.

 

Tác giả: Đỗ Ngọc Tú
Công Ty Phần Mềm VHTSoft

 


Phiên bản #1
Được tạo 19 tháng 4 2025 16:22:49 bởi Đỗ Ngọc Tú
Được cập nhật 22 tháng 4 2025 17:43:00 bởi Đỗ Ngọc Tú