mlflow.config

mlflow.config.disable_system_metrics_logging()[source]

全局禁用系统指标日志记录。

调用此函数将全局禁用系统指标日志记录,但用户仍可通过 mlflow.start_run(log_system_metrics=True) 为单个运行选择加入系统指标日志记录。

mlflow.config.enable_async_logging(enable=True)[source]

启用或全局禁用异步日志记录。

参数

enable – bool,如果为 True,则启用异步日志记录。如果为 False,则禁用异步日志记录。

示例
import mlflow

mlflow.config.enable_async_logging(True)

with mlflow.start_run():
    mlflow.log_param("a", 1)  # This will be logged asynchronously

mlflow.config.enable_async_logging(False)
with mlflow.start_run():
    mlflow.log_param("a", 1)  # This will be logged synchronously
mlflow.config.enable_system_metrics_logging()[source]

全局启用系统指标日志记录。

调用此函数将全局启用系统指标日志记录,但用户仍可通过 mlflow.start_run(log_system_metrics=False) 为单个运行选择退出系统指标日志记录。

mlflow.config.get_registry_uri() str[source]

获取当前注册表 URI。如果未指定,则默认为跟踪 URI。

返回

注册表 URI。

# Get the current model registry uri
mr_uri = mlflow.get_registry_uri()
print(f"Current model registry uri: {mr_uri}")

# Get the current tracking uri
tracking_uri = mlflow.get_tracking_uri()
print(f"Current tracking uri: {tracking_uri}")

# They should be the same
assert mr_uri == tracking_uri
Current model registry uri: file:///.../mlruns
Current tracking uri: file:///.../mlruns
mlflow.config.get_tracking_uri() str[source]

获取当前跟踪 URI。这可能与当前活动运行的跟踪 URI 不符,因为跟踪 URI 可以通过 set_tracking_uri 进行更新。

返回

跟踪 URI。

import mlflow

# Get the current tracking uri
tracking_uri = mlflow.get_tracking_uri()
print(f"Current tracking uri: {tracking_uri}")
Current tracking uri: sqlite:///mlflow.db
mlflow.config.is_tracking_uri_set()[source]

如果已设置跟踪 URI,则返回 True,否则返回 False。

mlflow.config.set_registry_uri(uri: str) None[source]

设置注册表服务器 URI。当注册表服务器与跟踪服务器不同时,此方法特别有用。

参数

uri – 空字符串,或以 file:/ 为前缀的本地文件路径。数据将本地存储在提供的文件中(如果为空,则存储在 ./mlruns)。HTTP URI,例如 https://my-tracking-server:5000http://my-oss-uc-server:8080。Databricks 工作区,提供为字符串“databricks”或使用 Databricks CLI 配置文件,提供为“databricks://<profileName>”。

Example
import mflow

# Set model registry uri, fetch the set uri, and compare
# it with the tracking uri. They should be different
mlflow.set_registry_uri("sqlite:////tmp/registry.db")
mr_uri = mlflow.get_registry_uri()
print(f"Current registry uri: {mr_uri}")
tracking_uri = mlflow.get_tracking_uri()
print(f"Current tracking uri: {tracking_uri}")

# They should be different
assert tracking_uri != mr_uri
Output
Current registry uri: sqlite:////tmp/registry.db
Current tracking uri: file:///.../mlruns
mlflow.config.set_system_metrics_node_id(node_id)[source]

设置系统指标节点 ID。

node_id 是收集指标的机器的标识符。这在多节点(分布式训练)设置中很有用。

mlflow.config.set_system_metrics_samples_before_logging(samples)[source]

设置记录系统指标之前的采样数。

每次收集了 samples 个样本后,系统指标将记录到 mlflow。默认情况下 samples=1

mlflow.config.set_system_metrics_sampling_interval(interval)[source]

设置系统指标采样间隔。

interval 秒,将收集系统指标。默认情况下 interval=10

mlflow.config.set_tracking_uri(uri: str | pathlib.Path) None[source]

设置跟踪服务器 URI。这不会影响当前活动运行(如果存在),但对后续运行生效。

参数

uri

  • 空字符串,或以 file:/ 为前缀的本地文件路径。数据将本地存储在提供的文件中(如果为空,则存储在 ./mlruns)。

  • HTTP URI,例如 https://my-tracking-server:5000

  • Databricks 工作区,提供为字符串“databricks”或使用 Databricks CLI 配置文件,提供为“databricks://<profileName>”。

  • pathlib.Path 实例

Example
import mlflow

mlflow.set_tracking_uri("file:///tmp/my_tracking")
tracking_uri = mlflow.get_tracking_uri()
print(f"Current tracking uri: {tracking_uri}")
Output
Current tracking uri: file:///tmp/my_tracking