mlflow / mlflow

Open source platform for the machine learning lifecycle
https://mlflow.org
Apache License 2.0
18k stars 4.06k forks source link

[BUG] mlflow-artifacts path prefix cause error in docker #6500

Closed Chesh1re closed 1 year ago

Chesh1re commented 1 year ago

Willingness to contribute

Yes. I would be willing to contribute a fix for this bug with guidance from the MLflow community.

MLflow version

1.28.0

System information

Describe the problem

Logging metrics and parameters works in the container, but the artifacts can not be logged.

Code works fine outside container with artifact path: "./mlruns/0/3277fd0623aa487ab732f2465b921aea/artifacts". However, inside the container, the artifact path weirdly changed to "mlflow-artifacts:/0/3277fd0623aa487ab732f2465b921aea/artifacts" automatically.

And I get the following error: mlflow.exceptions.MlflowException: The configured tracking uri scheme: 'sqlite' is invalid for use with the proxy mlflow-artifact scheme. The allowed tracking schemes are: {'https', 'http'} FileNotFoundError: [Errno 2] No such file or directory: 'mlflow-artifacts:/0/3277fd0623aa487ab732f2465b921aea/artifacts'

Tracking information

No response

Code to reproduce issue

Tracking server setup: mlflow server --host 0.0.0.0 --port 5000 --backend-store-uri sqlite:////app/MLconfigs/mlruns.db --artifacts-destination ./mlruns --serve-artifacts

Logging code: def log_artifact(self, artifact_path): """ Log artifact for each run. """ self.logger.info('Logging artifact now.') self.utils.load_tracking_uri() return mlflow.log_artifact(artifact_path)

Error happens at: Traceback (most recent call last): File "/app/src/kaiops_run.py", line 172, in ml_configs.run(runner.run_trials) File "/app/src/mlops/config_parser.py", line 63, in run _func(*_args) File "/app/src/kaiops_run.py", line 95, in run_trials dir_items = os.listdir(best_run.info.artifact_uri) FileNotFoundError: [Errno 2] No such file or directory: 'mlflow-artifacts:/0/0a808df7ac4f42ecbdd17d0542dd282c/artifacts'

Stack trace

None

Other info / logs

No response

What component(s) does this bug affect?

What interface(s) does this bug affect?

What language(s) does this bug affect?

What integration(s) does this bug affect?

harupy commented 1 year ago

@Chesh1re Please provide the code to reproduce the issue.

Chesh1re commented 1 year ago

@Chesh1re Please provide the code to reproduce the issue. Tracking server setup: mlflow server --host 0.0.0.0 --port 5000 --backend-store-uri sqlite:////app/MLconfigs/mlruns.db --artifacts-destination ./mlruns --serve-artifacts

Logging code: def log_artifact(self, artifact_path): """ Log artifact for each run. """ self.logger.info('Logging artifact now.') self.utils.load_tracking_uri() return mlflow.log_artifact(artifact_path)

Error happens at: Traceback (most recent call last): File "/app/src/kaiops_run.py", line 172, in ml_configs.run(runner.run_trials) File "/app/src/mlops/config_parser.py", line 63, in run _func(*_args) File "/app/src/kaiops_run.py", line 95, in run_trials dir_items = os.listdir(best_run.info.artifact_uri) FileNotFoundError: [Errno 2] No such file or directory: 'mlflow-artifacts:/0/0a808df7ac4f42ecbdd17d0542dd282c/artifacts'

And the mlruns directory is empty. Maybe all i need to know is which API is related to "mlflow-artifacts:" this term.

harupy commented 1 year ago

mlflow-artifacts:/0/0a808df7ac4f42ecbdd17d0542dd282c/artifacts is not a file path. dir_items = os.listdir(best_run.info.artifact_uri) needs to be fixed. mlflow.artifacts.download_artifacts might help.

Chesh1re commented 1 year ago

Thank you for the supplement. Yet, I still do not know how to address this problem. Maybe I put it wrong. The problem is that "best_run.info.artifact_uri" return a "./mlflow/0/" path outside the container, yet return a "mlflow-artifacts:/0/" inside the container. Also, the "mlflow.log_artifact(local_file_path)" is not working, therefore my "./mlruns/" directory is empty.

And I don't know what cause the following MlflowException too. mlflow.exceptions.MlflowException: The configured tracking uri scheme: 'sqlite' is invalid for use with the proxy mlflow-artifact scheme. The allowed tracking schemes are: {'http', 'https'}

harupy commented 1 year ago

@Chesh1re Can you share the full code?

harupy commented 1 year ago

btw if you just want to log artifacts in mlruns, you can just run mlflow server --host 0.0.0.0 --port 5000 --backend-store-uri sqlite:////app/MLconfigs/mlruns.db.

Chesh1re commented 1 year ago

btw if you just want to log artifacts in mlruns, you can just run mlflow server --host 0.0.0.0 --port 5000 --backend-store-uri sqlite:////app/MLconfigs/mlruns.db.

Thank you. I address this issue by adding a no cache tag after the docker build command: " docker build -t test -f Dockerfile . --no-cache".