New RunLLM response generated: >>>*# Question* Hi...
# runllm-flyte-trial
a
New RunLLM response generated: >>>*# Question* Hi community, I am new to flyte and use sandbox to explore things, now I want to log some metrics to mlflow (it is on http://localhost:8080). What I should I config to make them connected? Thanks ahead! # Answer To connect Flyte to an MLflow server running at
http://localhost:8080
and log metrics, you need to set the
MLFLOW_TRACKING_URI
environment variable in the Flyte propeller configuration. Here are the steps: 1. Install the Flyte MLflow Plugin:
Copy code
pip install flytekitplugins-mlflow
2. Edit the Flyte Propeller Config Map: Update the Flyte propeller configuration to include the
MLFLOW_TRACKING_URI
environment variable pointing to your MLflow server.
Copy code
kubectl edit cm flyte-propeller-config
Add the following to the config map:
Copy code
plugins:
      k8s:
        default-cpus: 100m
        default-env-vars:
        - MLFLOW_TRACKING_URI: http://localhost:8080
3. Log Metrics in Your Flyte Task: Use the
@mlflow_autolog
decorator to automatically log metrics and parameters to the MLflow server.
Copy code
import mlflow.keras
    import tensorflow as tf
    from flytekit import task, workflow
    from flytekitplugins.mlflow import mlflow_autolog

    @task(disable_deck=False)
    @mlflow_autolog(framework=mlflow.keras)
    def train_model(epochs: int):
        fashion_mnist = tf.keras.datasets.fashion_mnist
        (train_images, train_labels), (_, _) = fashion_mnist.load_data()
        train_images = train_images / 255.0

        model = tf.keras.Sequential([
            tf.keras.layers.Flatten(input_shape=(28, 28)),
            tf.keras.layers.Dense(128, activation='relu'),
            tf.keras.layers.Dense(10)
        ])
        model.compile(optimizer='adam',
                      loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
                      metrics=['accuracy'])
        model.fit(train_images, train_labels, epochs=epochs)

    @workflow
    def ml_pipeline(epochs: int):
        train_model(epochs=epochs)

    if __name__ == "__main__":
        ml_pipeline(epochs=5)
Would you like more details on any of these steps? Sources: - Flyte MLflow Plugin Installation - Flyte MLflow Plugin Configuration - Flyte MLflow Example Slack Link https://flyte-org.slack.com/archives/CP2HDHKE1/p1720017314.659659 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.