Skip to content

Commit

Permalink
adds mlflow example
Browse files Browse the repository at this point in the history
  • Loading branch information
edublancas committed Mar 13, 2024
1 parent 4afc980 commit bdaa8e7
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 4 deletions.
1 change: 1 addition & 0 deletions doc/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ parts:
- file: apps/dash
- file: apps/django
- file: apps/jupyterlab
- file: apps/mlflow
- file: apps/quarto
- file: apps/docker
- file: apps/chalk-it
Expand Down
8 changes: 4 additions & 4 deletions doc/apps/jupyterlab.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@


```{important}
If you're on a free account, always back up your work because your app can be terminated due to inactivity. If you need JupyterLab deployed with production settings, contact us [[email protected]](mailto:contact.ploomber.io)
If you're on a free account, always back up your work because your app can be terminated if inactive. If you need JupyterLab deployed with production settings, contact us [[email protected]](mailto:contact.ploomber.io)
```

You can deploy JupyterLab to Ploomber Cloud and use it as a development environment.


To do so, download the files from the
[example](https://github.com/ploomber/doc/tree/main/examples/docker/jupyterlab),
and follow the instructions for [Docker deployments.](docker.md)
[example](https://github.com/ploomber/doc/tree/main/examples/docker/jupyterlab), create a `.zip` file and deploy it using the Docker option:

![](../static/docker.png)

Once the deployment finishes, go to `WEBSERVICE LOGS` and copy the token:

Expand Down
92 changes: 92 additions & 0 deletions doc/apps/mlflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# MLflow

```{important}
If you're on a free account, always back up your work because your app can be terminated if inactive. If you need MLflow deployed with production settings, contact us [[email protected]](mailto:contact.ploomber.io)
```

To deploy MLflow download the Dockerfile from the
[example](https://github.com/ploomber/doc/tree/main/examples/docker/mlflow), create a `.zip` file and deploy it using the Docker option:

![](../static/docker.png)

Once the deployment finishes, open the app by clicking on `VIEW APPLICATION`, if all
went well you'll be prompted for a user and a password:

Use: admin
Password: password

## Changing the default password


For safety, let's change the credentials. Install the `requests` package:

```sh
pip install requests
```

And run the following in a Python session:

```python
import requests
from getpass import getpass

host = input("Enter your {id}.ploomberapp.io URL: ")
password_new = getpass("Enter new password:")

response = requests.patch(
f"{host}/api/2.0/mlflow/users/update-password",
auth=("admin", "password"),
json={"username": "admin", "password": password_new},
)

response.raise_for_status()

print("Your new password is:", password_new)
```

You'll be prompted for your MLflow host (e.g., `something.ploomberapp.io`), you can
get this from the Ploomber UI:

![](../static/docker/mlflow/host.png)

Then, enter the new password.

To confirm that the password was changed, open the MLflow dashboard again and enter the new password.


## Tracking experiments

To start tracking experiments, install mlflow locally:

```sh
pip install mlflow
```

Set your credentials as environment variables:

```sh
export MLFLOW_TRACKING_USERNAME=admin
export MLFLOW_TRACKING_PASSWORD=yourpassword
```

And run the following (replace the first line with your host!):

```python
import mlflow

mlflow.set_tracking_uri(uri="https://someid.ploomberapp.io")

mlflow.set_experiment("first-experiment")

with mlflow.start_run():
mlflow.log_params({"a": 21, "b": 21})
mlflow.log_metric("accuracy", 0.91)
```

If all goes well, you'll see:

```
2024/03/12 19:44:39 INFO mlflow.tracking.fluent: Experiment with name 'first-experiment' does not exist. Creating a new experiment.
```

And the experiment will be visible from MLflow's dashboard.
Binary file added doc/static/docker/mlflow/host.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions examples/docker/mlflow/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.11-slim

RUN pip install mlflow



ENTRYPOINT ["mlflow", "server", "--host", "0.0.0.0", "--port", "80", "--app-name", "basic-auth"]

0 comments on commit bdaa8e7

Please sign in to comment.