Skip to content

Commit

Permalink
Update existing examples. Added multiple Pytorch examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Jethro Gaglione committed Nov 23, 2023
1 parent c232a7f commit df5ac24
Show file tree
Hide file tree
Showing 49 changed files with 618 additions and 5 deletions.
11 changes: 11 additions & 0 deletions mlruns/0/62ce60957a5a4e93b8182918697230cf/artifacts/estimator.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
</head>
<body>
<style>#sk-container-id-1 {color: black;}#sk-container-id-1 pre{padding: 0;}#sk-container-id-1 div.sk-toggleable {background-color: white;}#sk-container-id-1 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-1 label.sk-toggleable__label-arrow:before {content: "▸";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-1 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-1 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: "▾";}#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-1 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-1 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-1 div.sk-parallel-item::after {content: "";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-serial::before {content: "";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-1 div.sk-item {position: relative;z-index: 1;}#sk-container-id-1 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-1 div.sk-item::before, #sk-container-id-1 div.sk-parallel-item::before {content: "";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-1 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-1 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-1 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-1 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-1 div.sk-label-container {text-align: center;}#sk-container-id-1 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-1 div.sk-text-repr-fallback {display: none;}</style><div id="sk-container-id-1" class="sk-top-container"><div class="sk-text-repr-fallback"><pre>RandomForestRegressor(max_depth=6, max_features=3)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class="sk-container" hidden><div class="sk-item"><div class="sk-estimator sk-toggleable"><input class="sk-toggleable__control sk-hidden--visually" id="sk-estimator-id-1" type="checkbox" checked><label for="sk-estimator-id-1" class="sk-toggleable__label sk-toggleable__label-arrow">RandomForestRegressor</label><div class="sk-toggleable__content"><pre>RandomForestRegressor(max_depth=6, max_features=3)</pre></div></div></div></div></div>
</body>
</html>

24 changes: 24 additions & 0 deletions mlruns/0/62ce60957a5a4e93b8182918697230cf/artifacts/model/MLmodel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
artifact_path: model
flavors:
python_function:
env:
conda: conda.yaml
virtualenv: python_env.yaml
loader_module: mlflow.sklearn
model_path: model.pkl
predict_fn: predict
python_version: 3.10.4
sklearn:
code: null
pickled_model: model.pkl
serialization_format: cloudpickle
sklearn_version: 1.3.2
mlflow_version: 2.8.0
model_size_bytes: 700268
model_uuid: 3b20b6daf07646699898ed732dc45419
run_id: 62ce60957a5a4e93b8182918697230cf
signature:
inputs: '[{"type": "tensor", "tensor-spec": {"dtype": "float64", "shape": [-1, 10]}}]'
outputs: '[{"type": "tensor", "tensor-spec": {"dtype": "float64", "shape": [-1]}}]'
params: null
utc_time_created: '2023-11-22 00:45:00.460319'
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
channels:
- conda-forge
dependencies:
- python=3.10.4
- pip<=23.3.1
- pip:
- mlflow==2.8.0
- cloudpickle==2.2.1
- numpy==1.26.1
- packaging==23.2
- psutil==5.9.6
- pyyaml==6.0.1
- scikit-learn==1.3.2
- scipy==1.11.3
name: mlflow-env
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
python: 3.10.4
build_dependencies:
- pip==23.3.1
- setuptools==58.1.0
- wheel==0.41.3
dependencies:
- -r requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mlflow==2.8.0
cloudpickle==2.2.1
numpy==1.26.1
packaging==23.2
psutil==5.9.6
pyyaml==6.0.1
scikit-learn==1.3.2
scipy==1.11.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
destination_id: 21f6d9f0ac284309fa124c33fea309a0
destination_type: RUN
source_id: 21f6d9f0ac284309fa124c33fea309a0
source_type: DATASET
tags:
mlflow.data.context: train
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
destination_id: 2d8f1b90af563814f690eb250ad83166
destination_type: RUN
source_id: 2d8f1b90af563814f690eb250ad83166
source_type: DATASET
tags:
mlflow.data.context: eval
15 changes: 15 additions & 0 deletions mlruns/0/62ce60957a5a4e93b8182918697230cf/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
artifact_uri: file:///panfs/accrepfs.vampire/home/gaglijt1/mltf/mlruns/0/62ce60957a5a4e93b8182918697230cf/artifacts
end_time: 1700613971729
entry_point_name: ''
experiment_id: '0'
lifecycle_stage: active
run_id: 62ce60957a5a4e93b8182918697230cf
run_name: charming-bat-405
run_uuid: 62ce60957a5a4e93b8182918697230cf
source_name: ''
source_type: 4
source_version: ''
start_time: 1700613892216
status: 3
tags: []
user_id: gaglijt1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1700613897968 29.21843005290767 0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1700613897968 1234.9272165506097 0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1700613897968 0.7821139716953788 0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1700613897968 35.14153122091594 0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1700613899185 0.7821139716953788 0
1 change: 1 addition & 0 deletions mlruns/0/62ce60957a5a4e93b8182918697230cf/params/bootstrap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
True
1 change: 1 addition & 0 deletions mlruns/0/62ce60957a5a4e93b8182918697230cf/params/ccp_alpha
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0
1 change: 1 addition & 0 deletions mlruns/0/62ce60957a5a4e93b8182918697230cf/params/criterion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
squared_error
1 change: 1 addition & 0 deletions mlruns/0/62ce60957a5a4e93b8182918697230cf/params/max_depth
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
None
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
None
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
100
1 change: 1 addition & 0 deletions mlruns/0/62ce60957a5a4e93b8182918697230cf/params/n_jobs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
None
1 change: 1 addition & 0 deletions mlruns/0/62ce60957a5a4e93b8182918697230cf/params/oob_score
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
False
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
None
1 change: 1 addition & 0 deletions mlruns/0/62ce60957a5a4e93b8182918697230cf/params/verbose
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
False
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sklearn.ensemble._forest.RandomForestRegressor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RandomForestRegressor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sklearn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"run_id": "62ce60957a5a4e93b8182918697230cf", "artifact_path": "model", "utc_time_created": "2023-11-22 00:45:00.460319", "flavors": {"python_function": {"model_path": "model.pkl", "predict_fn": "predict", "loader_module": "mlflow.sklearn", "python_version": "3.10.4", "env": {"conda": "conda.yaml", "virtualenv": "python_env.yaml"}}, "sklearn": {"pickled_model": "model.pkl", "sklearn_version": "1.3.2", "serialization_format": "cloudpickle", "code": null}}, "model_uuid": "3b20b6daf07646699898ed732dc45419", "mlflow_version": "2.8.0", "signature": {"inputs": "[{\"type\": \"tensor\", \"tensor-spec\": {\"dtype\": \"float64\", \"shape\": [-1, 10]}}]", "outputs": "[{\"type\": \"tensor\", \"tensor-spec\": {\"dtype\": \"float64\", \"shape\": [-1]}}]", "params": null}, "model_size_bytes": 700268}]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
charming-bat-405
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2cf5575fae20e2b2e89a661ea42a68d57d318647
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
train_skl_rf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LOCAL
1 change: 1 addition & 0 deletions mlruns/0/62ce60957a5a4e93b8182918697230cf/tags/mlflow.user
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gaglijt1
10 changes: 10 additions & 0 deletions mlruns/0/datasets/21f6d9f0ac284309fa124c33fea309a0/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
digest: a297e3e6
name: dataset
profile: '{"features_shape": [331, 10], "features_size": 3310, "features_nbytes":
26480, "targets_shape": [331], "targets_size": 331, "targets_nbytes": 2648}'
schema: '{"mlflow_tensorspec": {"features": "[{\"type\": \"tensor\", \"tensor-spec\":
{\"dtype\": \"float64\", \"shape\": [-1, 10]}}]", "targets": "[{\"type\": \"tensor\",
\"tensor-spec\": {\"dtype\": \"float64\", \"shape\": [-1]}}]"}}'
source: '{"tags": {"mlflow.user": "gaglijt1", "mlflow.source.name": "train_skl_rf.py",
"mlflow.source.type": "LOCAL", "mlflow.source.git.commit": "2cf5575fae20e2b2e89a661ea42a68d57d318647"}}'
source_type: code
9 changes: 9 additions & 0 deletions mlruns/0/datasets/2d8f1b90af563814f690eb250ad83166/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
digest: fdd80d1b
name: dataset
profile: '{"features_shape": [111, 10], "features_size": 1110, "features_nbytes":
8880}'
schema: '{"mlflow_tensorspec": {"features": "[{\"type\": \"tensor\", \"tensor-spec\":
{\"dtype\": \"float64\", \"shape\": [-1, 10]}}]", "targets": null}}'
source: '{"tags": {"mlflow.user": "gaglijt1", "mlflow.source.name": "train_skl_rf.py",
"mlflow.source.type": "LOCAL", "mlflow.source.git.commit": "2cf5575fae20e2b2e89a661ea42a68d57d318647"}}'
source_type: code
6 changes: 6 additions & 0 deletions mlruns/0/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
artifact_location: file:///panfs/accrepfs.vampire/home/gaglijt1/mltf/mlruns/0
creation_time: 1700613890473
experiment_id: '0'
last_update_time: 1700613890473
lifecycle_stage: active
name: Default
73 changes: 73 additions & 0 deletions train_pytorch_lightning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Sequential NN example using the PyTorch Lightning API.
# Lightning modules must be used to activate MLflow autolog capabilities.
# Lightning will autodetect and run on a GPU, if availble, without explicit code.
import torch
import mlflow
from torch.utils.data import Dataset
from torchvision import datasets
from torchvision.transforms import ToTensor
from torch.utils.data import DataLoader
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
import pytorch_lightning as L

mlflow.pytorch.autolog()

#In order to take advantage of MLflow autolog capabilities, we need a LightningModule
class SeqNet(L.LightningModule):
def __init__(self, input_size, hidden_size1, hidden_size2, output_size, lr):
super().__init__()

self.lin1 = nn.Linear(input_size, hidden_size1)
self.lin2 = nn.Linear(hidden_size1, hidden_size2)
self.lin3 = nn.Linear(hidden_size2, output_size)


def forward(self, x):
x = torch.flatten(x,1)
x = self.lin1(x)
x = F.sigmoid(x)
x = self.lin2(x)
x = F.log_softmax(x, dim=1)
out = self.lin3(x)
return out
# training_step must be defined to use Lightning
def training_step(self, batch, batchidx):
images, labels = batch
output = self(images)
loss_func = nn.CrossEntropyLoss()
loss = loss_func(output, labels)

#Using PyTorch, logging your loss in MLflow requires the following line:
self.log("train_loss", loss, prog_bar=True, on_step=False, on_epoch=True)
return loss

def configure_optimizers(self):
optimizer = torch.optim.SGD(self.parameters(), lr=lr)
return optimizer


input_size = 784
hidden_size1 = 200
hidden_size2 = 200
output_size = 10
num_epochs = 20
batch_size = 100
lr = 0.01

model = SeqNet(input_size, hidden_size1, hidden_size2, output_size, lr)


fmnist_train = datasets.FashionMNIST(root="data", train=True, download=True, transform=ToTensor())
fmnist_test = datasets.FashionMNIST(root="data", train=False, download=True, transform=ToTensor())

fmnist_train_loader = DataLoader(fmnist_train)
fmnist_test_loader = DataLoader(fmnist_test)

#MLflow autologs runs from calls to Lighning "Trainers":
trainer = L.Trainer(limit_train_batches=batch_size, max_epochs=num_epochs)
trainer.fit(model=model, train_dataloaders=fmnist_train_loader)



Loading

0 comments on commit df5ac24

Please sign in to comment.