Hướng Dẫn Xây Dựng Hệ Thống Machine Learning Hiệu Quả

Hệ thống Machine Learning (ML systems) là một ý tưởng cực kỳ giá trị — bởi nhiều người học ML nhưng lại thiếu kiến thức về cách xây dựng, triển khai và vận hành một hệ thống ML hoàn chỉnh ngoài thực tế.

Cuốn sách này sẽ hướng dẫn người đọc hiểu thế nào để truyển khai một hệ thống Machine Learning hoàn chỉnh từ cơ bản đến nâng cao

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

Giới Thiệu

Trong kỷ nguyên dữ liệu hiện đại, các mô hình Machine Learning không chỉ tồn tại trong phòng thí nghiệm hay notebook Jupyter — chúng đang vận hành trong thế giới thực, đưa ra quyết định hàng ngày cho hàng triệu người dùng. Tuy nhiên, giữa một mô hình đạt độ chính xác ấn tượng trong quá trình huấn luyện và một hệ thống ML đáng tin cậy trong sản xuất là một hành trình dài, phức tạp và thường bị bỏ quên.

Cuốn sách này được viết ra để thu hẹp khoảng cách đó.

Mục tiêu của sách

Mục tiêu của cuốn sách không chỉ là giúp bạn hiểu cách xây dựng mô hình ML, mà còn hướng dẫn bạn xây dựng một hệ thống Machine Learning hoàn chỉnh – từ thu thập dữ liệu, huấn luyện mô hình, triển khai (deployment), đến giám sát và duy trì mô hình trong môi trường sản xuất.

Bạn sẽ học được gì?

Đối tượng độc giả

Cuốn sách này dành cho:

Phương pháp tiếp cận

Cuốn sách sẽ đi theo phương pháp thực chiến – dựa trên ví dụ thực tế, từng bước xây dựng một hệ thống ML từ đầu đến khi vận hành sản phẩm. Với cách tiếp cận này, bạn không chỉ nắm lý thuyết mà còn có thể ứng dụng được ngay vào công việc.

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

Giới thiệu Metaflow, Evidently AI và Keras

I. Metaflow – Orchestrating ML Workflows Made Simple

Metaflow là một framework mạnh mẽ được phát triển bởi Netflix, giúp đơn giản hóa quá trình xây dựng và quản lý pipeline machine learning. Với cú pháp thân thiện, khả năng tích hợp tốt với AWS, Kubernetes, và versioning rõ ràng cho cả dữ liệu và mô hình, Metaflow là công cụ lý tưởng để tổ chức, theo dõi và tái sử dụng các bước trong quy trình ML một cách dễ dàng và có hệ thống.

Trong các project của cuốn sách này, Metaflow sẽ đóng vai trò là xương sống của hệ thống ML pipeline, giúp bạn cấu trúc các bước như thu thập dữ liệu, huấn luyện mô hình, đánh giá và triển khai — tất cả trong một luồng rõ ràng và có thể mở rộng.

Metaflow giúp được gì

Cách hoạt động

Bạn định nghĩa các bước trong pipeline bằng cú pháp Python rất thân thiện. Ví dụ:

from metaflow import FlowSpec, step

class HelloFlow(FlowSpec):

    @step
    def start(self):
        print("Hello from Metaflow!")
        self.next(self.end)

    @step
    def end(self):
        print("Flow finished.")

if __name__ == '__main__':
    HelloFlow()

Chạy bằng dòng lệnh:

python hello_flow.py run

Tính năng nổi bật

Tính năng Mô tả ngắn
@step decorator Xác định các bước trong pipeline.
FlowSpec Khai báo cấu trúc của flow.
self.next() Xác định bước tiếp theo trong luồng xử lý.
metaflow run Chạy pipeline.
metaflow resume Tiếp tục pipeline từ bước bị lỗi.
Tích hợp MLFlow, Argo Có thể tích hợp thêm các hệ thống orchestration.

II. Evidently AI

Evidently AI là một thư viện mã nguồn mở giúp theo dõi hiệu suất của mô hình machine learning trong môi trường sản xuất. Nó cung cấp các báo cáo trực quan về drift dữ liệu, độ lệch phân phối đầu vào/đầu ra, độ chính xác, và nhiều chỉ số quan trọng khác mà bạn cần để đảm bảo mô hình hoạt động ổn định theo thời gian.

Trong các project của sách, Evidently AI sẽ được sử dụng để thiết lập các bước kiểm tra và giám sát mô hình, giúp bạn nhanh chóng phát hiện và xử lý các vấn đề như concept drift, data quality issues, và sai lệch hiệu suất trong môi trường thực tế.

Được thiết kế để hoạt động trước, trong, và sau khi triển khai mô hình ML.

Evidently AI làm được gì?

Tính năng Mô tả
Data Drift Detection Phát hiện khi dữ liệu đầu vào thay đổi so với training data.
Model Performance Monitoring Theo dõi accuracy, precision, recall,... theo thời gian.
Data Quality Checks Kiểm tra sự thiếu hụt, phân bố, outliers,... trong dữ liệu.
Tạo báo cáo HTML trực quan Tạo dashboard HTML dễ hiểu, chia sẻ dễ dàng cho đội ngũ.
Tích hợp dễ dàng Chạy tốt cùng với Pandas, Jupyter, Airflow, MLflow, v.v.

Một số use-case phổ biến

Ví dụ dùng trong Jupyter Notebook

import pandas as pd
from evidently.report import Report
from evidently.metric_preset import DataDriftPreset

# Giả sử bạn có training data và current data
train_df = pd.read_csv("train.csv")
current_df = pd.read_csv("current.csv")

report = Report(metrics=[
    DataDriftPreset()
])

report.run(reference_data=train_df, current_data=current_df)
report.show(mode="inline")  # hiển thị trong Jupyter
report.save_html("data_drift_report.html")  # xuất báo cáo

Cài đặt

pip install evidently

Evidently rất hữu ích nếu bạn là...

Tích hợp với các công cụ khác

II. Keras và Backend

Vì sao chọn JAX làm backend?

JAX là một thư viện từ Google cho tính toán khoa học, nổi bật với các tính năng:

  1. Tính toán tự động đạo hàm (autograd).

  2. Tính toán song song và phân tán với GPU/TPU.

  3. Vectorization – thực hiện tính toán trên nhiều phần tử cùng lúc.

  4. Hỗ trợ tối ưu hóa và gradient-based learning cực kỳ mạnh mẽ.

Khi bạn đặt KERAS_BACKEND=jax, bạn yêu cầu Keras sử dụng JAX để thực hiện các phép toán, thay vì TensorFlow

Cách thức hoạt động với JAX

Khi sử dụng JAX làm backend cho Keras, bạn sẽ được hưởng các ưu điểm nổi bật của JAX, như:

Cài đặt JAX và Keras với JAX backend

Để sử dụng JAX làm backend cho Keras, bạn cần cài đặt các thư viện cần thiết:

1. Cài đặt Keras Core và JAX:

pip install keras-core jax jaxlib

2. Sau đó, đặt biến môi trường KERAS_BACKEND thành jax:

export KERAS_BACKEND=jax

Bây giờ Keras sẽ sử dụng JAX làm backend khi bạn xây dựng và huấn luyện mô hình.

Ví dụ

Ví dụ, nếu bạn muốn sử dụng Keras với JAX làm backend, bạn có thể tạo mô hình như sau:

from keras import layers, models
from keras.datasets import mnist

# Tải dữ liệu MNIST
(x_train, y_train), (x_test, y_test) = mnist.load_data()

# Chuẩn bị dữ liệu
x_train, x_test = x_train / 255.0, x_test / 255.0

# Xây dựng mô hình
model = models.Sequential([
    layers.Flatten(input_shape=(28, 28)),
    layers.Dense(128, activation='relu'),
    layers.Dropout(0.2),
    layers.Dense(10)
])

# Biên dịch và huấn luyện
model.compile(optimizer='adam', loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True), metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5)

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


 

 

Cơ bản về MLFlow

Cơ bản về MLFlow

Bài thực hành cơ bản nhất

Dưới đây là một bài thực hành MLflow cơ bản nhất, cùng với hướng dẫn cách xem giao diện MLflow UI.

Mục tiêu:

I. Cài đặt MLflow

python3 -m venv venv
source venv/bin/activate

pip install mlflow scikit-learn pandas

II. Tạo file mlflow_basic.py

# mlflow_basic.py

import mlflow
import mlflow.sklearn
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error
from sklearn.datasets import load_diabetes
from sklearn.model_selection import train_test_split
import pandas as pd

# Load dataset
data = load_diabetes()
X = pd.DataFrame(data.data, columns=data.feature_names)
y = pd.Series(data.target)

# Train-test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Bắt đầu một MLflow run
with mlflow.start_run():

    # Tham số mô hình
    n_estimators = 100
    max_depth = 4

    # Log parameters
    mlflow.log_param("n_estimators", n_estimators)
    mlflow.log_param("max_depth", max_depth)

    # Train model
    model = RandomForestRegressor(n_estimators=n_estimators, max_depth=max_depth)
    model.fit(X_train, y_train)

    # Predict & evaluate
    predictions = model.predict(X_test)
    rmse = mean_squared_error(y_test, predictions, squared=False)

    # Log metrics
    mlflow.log_metric("rmse", rmse)

    # Log mô hình
    mlflow.sklearn.log_model(model, "model")

    print(f"Done! RMSE: {rmse}")

III. Chạy file

python mlflow_basic.py
MLflow lưu trữ các kết quả trong thư mục mlruns (mặc định)

Nếu gặp cảnh báo
warnings.warn( 2025/04/23 00:10:40 WARNING mlflow.models.model: Model logged without a signature and input example. Please set input_example parameter when logging the model to auto infer the model signature.

Cập nhật đoạn log_model() như sau:

import numpy as np

# Log mô hình kèm input_example
mlflow.sklearn.log_model(
    model,
    artifact_path="model",
    input_example=X_test.iloc[:5],  # hoặc: X_test[:1]
    signature=mlflow.models.infer_signature(X_test, predictions)
)

Giải thích:

IV. Xem giao diện MLflow UI

mlflow ui

MLflow sẽ chạy trên http://127.0.0.1:5000 (mặc định). Mở trình duyệt và truy cập vào địa chỉ đó.

image.png

Click vào treasured-stag-117, bạn sẽ thấy

image.png

 

V. Tổng quan: "Log" trong MLflow nghĩa là gì?

Trong MLflow, "log" nghĩa là ghi lại và lưu trữ các thông tin như:

Loại thông tin Ví dụ MLflow gọi là
Tham số (số lớp, số cây, learning rate, v.v.) n_estimators=100 log_param
Kết quả đánh giá mô hình rmse=54.772 log_metric
Mô hình đã huấn luyện file .pkl hoặc .joblib log_model

 

Ở ví dụ trên dùng RandomForestRegressor, mình sẽ ghi lại:

1. Tham số (Parameters)
mlflow.log_param("n_estimators", n_estimators)
mlflow.log_param("max_depth", max_depth)

Ghi lại cấu hình mô hình để sau này dễ tái hiện.

2. Metric (hiệu suất mô hình)

rmse = mean_squared_error(y_test, predictions, squared=False)
mlflow.log_metric("rmse", rmse)

Ghi lại giá trị RMSE để so sánh nhiều mô hình với nhau.

3. Ghi lại mô hình đã huấn luyện

mlflow.sklearn.log_model(model, "model")

MLflow sẽ lưu mô hình để sau này có thể load lại, dùng để deploy, hoặc tái huấn luyện.

Tất cả đặt trong 1 "Run"

MLflow cần phải có 1 "chạy thử nghiệm" (run) để lưu trữ thông tin:

with mlflow.start_run():
    # log_param()
    # log_metric()
    # log_model()

 

Tóm tắt chúng ta đã học

Bạn muốn... Dùng hàm...
Ghi lại một tham số mlflow.log_param(name, value)
Ghi lại một kết quả đánh giá mlflow.log_metric(name, value)
Ghi lại mô hình đã huấn luyện mlflow.sklearn.log_model(model, "model")
Bắt đầu một "chạy thử nghiệm" with mlflow.start_run():

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

 

 

 

 

MLFlow nâng cao

MLFlow nâng cao

High-level Architecture

image.png

Mối quan hệ giữa các thành phần

  1. Training Pipeline tạo ra mô hình → đẩy vào Model Registry.

  2. Deployment Pipeline lấy mô hình từ registry → triển khai trên AWS → cung cấp API inference.

  3. Traffic Data cập nhật ground truth → dùng để cải thiện mô hình qua feedback loop.

Dưới đây là giải thích chi tiết từng thành phần trong kiến trúc bạn cung cấp, được chia theo 3 pipeline chính:

1. Training Pipeline (Quy trình huấn luyện mô hình)

Dataset
Data processing
Training
Evaluation
Registration

2. Deployment Pipeline (Quy trình triển khai mô hình)

Data capturing
Inference endpoint
AWS
Model
Model Registry

3. Traffic Data (Dữ liệu giao thông)

Ground truth
Traffic data and labels
Testing
Reports & Metrics and reports

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

MLFlow nâng cao

Cài đặt môi trường

Đảm bảo trên máy đã cài Python 3.12 hoặc cao hơn

python3 -m venv .venv
source .venv/bin/activate
pip3 install -U pip && pip3 install -r requirements.txt

file requirements.txt download tại https://github.com/vhtsoft/machine-learning.git

Tại thời điểm này, bạn sẽ có một môi trường Python đang hoạt động với tất cả các phụ thuộc cần thiết. Bước cuối cùng là tạo một tệp .env bên trong thư mục gốc của kho lưu trữ. Chúng ta sẽ sử dụng tệp này để xác định các biến môi trường cần thiết để chạy các pipeline

echo "KERAS_BACKEND=jax" >> .env

Chạy MLflow

mlflow server --host 127.0.0.1 --port 5000

image.png

Tại Browser

http://localhost:5000/

image.png

Theo mặc định, MLflow theo dõi các thử nghiệm và lưu trữ dữ liệu trong các tệp bên trong thư mục ./mlruns cục bộ. Bạn có thể thay đổi vị trí của thư mục theo dõi hoặc sử dụng cơ sở dữ liệu SQLite bằng tham số --backend-store-uri. Ví dụ sau sử dụng cơ sở dữ liệu SQLite để lưu trữ dữ liệu theo dõi:

mlflow server --host 127.0.0.1 --port 5000 --backend-store-uri sqlite:///mlflow.db

Để biết thêm thông tin, hãy kiểm tra một số cách phổ biến để thiết lập MLflow. Bạn cũng có thể chạy lệnh sau để biết thêm thông tin về máy chủ:

mlflow server --help

Sau khi máy chủ chạy, hãy sửa đổi tệp .env bên trong thư mục gốc của kho lưu trữ để thêm biến môi trường MLFLOW_TRACKING_URI trỏ đến URI theo dõi của máy chủ MLflow. Lệnh sau sẽ thêm biến vào tệp và xuất nó trong shell hiện tại của bạn:

export $((echo "MLFLOW_TRACKING_URI=http://127.0.0.1:5000" >> .env; cat .env) | xargs)

image.png

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

 

MLFlow nâng cao

Tổng Quan Qui Trình Pipeline Huấn Luyện Mô Hình

image.png

Đây là một quy trình (pipeline) huấn luyện mô hình học máy theo phương pháp Cross-Validation (kiểm tra chéo), thường được sử dụng để đánh giá hiệu suất mô hình một cách ổn định. Dưới đây là giải thích chi tiết từng bước:


1. Tổng quan

Pipeline này mô tả quy trình K-Fold Cross-Validation, trong đó:


2. Giải thích từng thành phần

a. Split dataset
b. For each fold...
c. Transform dataset
d. Train model
e. Evaluate model
f. Model assets
g. Register model
h. Model registry

3. Luồng hoạt động của pipeline

  1. Chia dữ liệu → K folds.

  2. Với mỗi fold:

    • Transform dữ liệu train/validation.

    • Train mô hình trên train set.

    • Evaluate trên validation set.

  3. Tổng hợp kết quả từ K lần evaluate để tính độ ổn định của mô hình (ví dụ: mean accuracy ± độ lệch chuẩn).

  4. Lưu mô hình tốt nhất vào Model Registry để triển khai.


4. Ứng dụng thực tế

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

MLFlow nâng cao

Xây Dựng Hàm Phụ Trợ PipeLine

Trong bài này sử dụng tập dữ liệu Penguins để đào tạo một mô hình phân loại các loài chim cánh cụt.

I. DatasetMixin Class

tại thư mục gốc tạo pipelines/common.py

import logging
import logging.config
import sys
import time
from io import StringIO
from pathlib import Path

import pandas as pd
from metaflow import IncludeFile, current

PYTHON = "3.12.8"

PACKAGES = {
    "keras": "3.8.0",
    "scikit-learn": "1.6.1",
    "mlflow": "2.20.2",
    "tensorflow": "2.18.0",
}


class DatasetMixin:
    """A mixin for loading and preparing a dataset.

    This mixin is designed to be combined with any pipeline that requires accessing
    a dataset.
    """

    dataset = IncludeFile(
        "dataset",
        is_text=True,
        help="Dataset that will be used to train the model.",
        default="data/penguins.csv",
    )

    def load_dataset(self):
        """Load and prepare the dataset."""
        import numpy as np

        # The raw data is passed as a string, so we need to convert it into a DataFrame.
        data = pd.read_csv(StringIO(self.dataset))

        # Replace extraneous values in the sex column with NaN. We can handle missing
        # values later in the pipeline.
        data["sex"] = data["sex"].replace(".", np.nan)

        # We want to shuffle the dataset. For reproducibility, we can fix the seed value
        # when running in development mode. When running in production mode, we can use
        # the current time as the seed to ensure a different shuffle each time the
        # pipeline is executed.
        seed = int(time.time() * 1000) if current.is_production else 42
        generator = np.random.default_rng(seed=seed)
        data = data.sample(frac=1, random_state=generator)

        logging.info("Loaded dataset with %d samples", len(data))

        return data


def packages(*names: str):
    """Return a dictionary of the specified packages and their corresponding version.

    This function is useful to set up the different pipelines while keeping the
    package versions consistent and centralized in a single location.

    Any packages that should be locked to a specific version will be part of the
    `PACKAGES` dictionary. If a package is not present in the dictionary, it will be
    installed using the latest version available.
    """
    return {name: PACKAGES.get(name, "") for name in names}


def configure_logging():
    """Configure logging handlers and return a logger instance."""
    if Path("logging.conf").exists():
        logging.config.fileConfig("logging.conf")
    else:
        logging.basicConfig(
            format="%(asctime)s [%(levelname)s] %(message)s",
            handlers=[logging.StreamHandler(sys.stdout)],
            level=logging.INFO,
        )


def build_features_transformer():
    """Build a Scikit-Learn transformer to preprocess the feature columns."""
    from sklearn.compose import ColumnTransformer, make_column_selector
    from sklearn.impute import SimpleImputer
    from sklearn.pipeline import make_pipeline
    from sklearn.preprocessing import OneHotEncoder, StandardScaler

    numeric_transformer = make_pipeline(
        SimpleImputer(strategy="mean"),
        StandardScaler(),
    )

    categorical_transformer = make_pipeline(
        SimpleImputer(strategy="most_frequent"),
        # We can use the `handle_unknown="ignore"` parameter to ignore unseen categories
        # during inference. When encoding an unknown category, the transformer will
        # return an all-zero vector.
        OneHotEncoder(handle_unknown="ignore"),
    )

    return ColumnTransformer(
        transformers=[
            (
                "numeric",
                numeric_transformer,
                # We'll apply the numeric transformer to all columns that are not
                # categorical (object).
                make_column_selector(dtype_exclude="object"),
            ),
            (
                "categorical",
                categorical_transformer,
                # We want to make sure we ignore the target column which is also a
                # categorical column. To accomplish this, we can specify the column
                # names we only want to encode.
                ["island", "sex"],
            ),
        ],
    )


def build_target_transformer():
    """Build a Scikit-Learn transformer to preprocess the target column."""
    from sklearn.compose import ColumnTransformer
    from sklearn.preprocessing import OrdinalEncoder

    return ColumnTransformer(
        transformers=[("species", OrdinalEncoder(), ["species"])],
    )


def build_model(input_shape, learning_rate=0.01):
    """Build and compile the neural network to predict the species of a penguin."""
    from keras import Input, layers, models, optimizers

    model = models.Sequential(
        [
            Input(shape=(input_shape,)),
            layers.Dense(10, activation="relu"),
            layers.Dense(8, activation="relu"),
            layers.Dense(3, activation="softmax"),
        ],
    )

    model.compile(
        optimizer=optimizers.SGD(learning_rate=learning_rate),
        loss="sparse_categorical_crossentropy",
        metrics=["accuracy"],
    )

    return model

Class DatasetMixin

Là một mixin — class phụ dùng để thêm khả năng load_dataset() vào các pipeline Metaflow.

dataset = IncludeFile(
    "dataset",
    is_text=True,
    help="Dataset that will be used to train the model.",
    default="data/penguins.csv",
)

load_dataset()

def load_dataset(self):
    ...

Hàm packages(*names)

def packages(*names: str):
    return {name: PACKAGES.get(name, "") for name in names}

Khi bạn viết Metaflow @conda_base hoặc @conda decorator, bạn có thể truyền gọn:

@conda(packages=packages("keras", "scikit-learn"))

Hàm configure_logging()

def configure_logging():
    ...

build_features_transformer()

def build_features_transformer():
    ...

Trả về một ColumnTransformer để xử lý:

["island", "sex"]  # là các cột categorical cụ thể

handle_unknown="ignore" giúp model không crash khi gặp category mới trong inference.

build_target_transformer()

def build_target_transformer():
    ...

build_model(input_shape, learning_rate)

def build_model(input_shape, learning_rate=0.01):
    ...

Tổng Kết

Phần Mục đích
DatasetMixin Load CSV dataset dùng IncludeFile, shuffle, xử lý giá trị thiếu
packages() Tập trung quản lý version package
configure_logging() Ghi log ra terminal hoặc file
build_features_transformer() Chuẩn hóa, encode dữ liệu đầu vào
build_target_transformer() Encode target sang số
build_model() Khởi tạo mô hình MLP với Keras

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

MLFlow nâng cao

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