Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mlflow-cleanup
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dasharatha.vamshi
mlflow-cleanup
Commits
5f5eb49e
Commit
5f5eb49e
authored
Mar 20, 2023
by
dasharatha.vamshi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clenaup
parent
88061537
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
89 deletions
+17
-89
conf/application.conf
conf/application.conf
+0
-3
config.env
config.env
+0
-1
scripts/constants/app_configuration.py
scripts/constants/app_configuration.py
+0
-5
scripts/core/mlflow_util.py
scripts/core/mlflow_util.py
+17
-80
No files found.
conf/application.conf
View file @
5f5eb49e
[
TIMEZONE
]
required_tz
=$
REQUIRED_TZ
[
MLFLOW
]
mlflow_tracking_uri
=$
MLFLOW_TRACKING_URI
mlflow_tracking_username
=$
MLFLOW_TRACKING_USERNAME
...
...
config.env
View file @
5f5eb49e
REQUIRED_TZ=Asia/Kolkata
MLFLOW_TRACKING_URI=https://qa.unifytwin.com/mlflow/
MLFLOW_TRACKING_USERNAME=mlflow
MLFLOW_TRACKING_PASSWORD=MlFlOwQA#4321
...
...
scripts/constants/app_configuration.py
View file @
5f5eb49e
...
...
@@ -42,11 +42,6 @@ class Logging:
# Configuration Variables
REQUIRED_TZ
=
config
[
'TIMEZONE'
][
'required_tz'
]
class
MlflowMetaData
:
MLFLOW_TRACKING_URI
=
config
[
'MLFLOW'
][
'mlflow_tracking_uri'
]
MLFLOW_TRACKING_USERNAME
=
config
[
'MLFLOW'
][
'mlflow_tracking_username'
]
...
...
scripts/core/mlflow_util.py
View file @
5f5eb49e
import
os
import
re
from
datetime
import
datetime
import
mlflow
import
pandas
as
pd
import
pytz
from
dateutil
import
tz
from
loguru
import
logger
from
azure.storage.blob
import
BlobServiceClient
from
loguru
import
logger
from
scripts.constants.app_configuration
import
REQUIRED_TZ
,
MlflowMetaData
from
scripts.constants.app_configuration
import
MlflowMetaData
from
scripts.constants.app_constants
import
MODEL_NAME
mlflow_tracking_uri
=
MlflowMetaData
.
MLFLOW_TRACKING_URI
...
...
@@ -26,65 +21,6 @@ client = mlflow.tracking.MlflowClient()
class
MlFlowUtil
:
@
staticmethod
def
get_last_run_time_diff
(
run_info
):
try
:
logger
.
info
(
f
"Checking the time difference in days"
)
df_time
=
run_info
.
copy
()
df_time
[
'end_time'
]
=
pd
.
to_datetime
(
df_time
[
'end_time'
])
.
dt
.
tz_convert
(
REQUIRED_TZ
)
to_zone
=
tz
.
gettz
(
REQUIRED_TZ
)
df_time
[
"days"
]
=
df_time
[
'end_time'
]
.
dt
.
date
df_time
[
"hours"
]
=
df_time
[
'end_time'
]
.
dt
.
hour
last_model_time
=
list
(
df_time
[
'end_time'
])[
0
]
.
to_pydatetime
()
today
=
datetime
.
now
(
pytz
.
utc
)
central_current
=
today
.
astimezone
(
to_zone
)
time_diff
=
central_current
-
last_model_time
return
int
(
time_diff
.
days
)
except
Exception
as
e
:
logger
.
warning
(
f
"Exception while checking the last run time of the model - {e}"
)
return
0
@
staticmethod
def
log_model
(
model
,
model_name
):
try
:
mlflow
.
sklearn
.
log_model
(
model
,
model_name
)
logger
.
info
(
"logged the model"
)
return
True
except
Exception
as
e
:
logger
.
exception
(
str
(
e
))
@
staticmethod
def
log_metrics
(
metrics
):
try
:
updated_metric
=
{}
for
key
,
value
in
metrics
.
items
():
key
=
re
.
sub
(
r"[([{})\]]"
,
""
,
key
)
updated_metric
[
key
]
=
value
mlflow
.
log_metrics
(
updated_metric
)
return
True
except
Exception
as
e
:
logger
.
exception
(
str
(
e
))
@
staticmethod
def
log_hyper_param
(
hyper_params
):
try
:
mlflow
.
log_params
(
hyper_params
)
return
True
except
Exception
as
e
:
logger
.
exception
(
str
(
e
))
@
staticmethod
def
set_tag
(
child_run_id
,
key
,
value
):
try
:
client
.
set_tag
(
run_id
=
child_run_id
,
key
=
key
,
value
=
value
)
except
Exception
as
e
:
logger
.
exception
(
f
"Exception while setting the tag - {e}"
)
@
staticmethod
def
remove_file_if_exists
(
path
):
if
os
.
path
.
exists
(
path
):
os
.
remove
(
path
)
@
staticmethod
def
delete_artifact
(
run_id
,
parent_run_name
,
artifact_uri
,
file_path
,
model_name
):
logger
.
info
(
f
"Deleting artifact for {run_id} under {parent_run_name}"
)
...
...
@@ -167,20 +103,21 @@ class MlflowCleanUp:
experiment_id
=
self
.
check_experiment
()
if
experiment_id
is
not
None
:
runs_df
=
self
.
check_runs_data
(
experiment_id
)
if
runs_df
is
not
None
:
run_id_list
=
list
(
runs_df
[
'run_id'
])
run_name_list
=
list
(
runs_df
[
'tags.mlflow.runName'
])
run_name_mapping
=
{}
for
i
in
range
(
len
(
run_id_list
)):
run_name_mapping
[
run_id_list
[
i
]]
=
run_name_list
[
i
]
# getting runs who have a parent-id
df
=
runs_df
[
runs_df
[
self
.
model_parent_run_id_key
]
.
notna
()]
# getting runs who have a model logged
f_df
=
df
[
df
[
self
.
model_history_key
]
.
notna
()]
self
.
delete_run_model_data
(
f_df
,
run_name_mapping
)
if
self
.
model_parent_run_id_key
in
runs_df
.
columns
:
if
runs_df
is
not
None
:
run_id_list
=
list
(
runs_df
[
'run_id'
])
run_name_list
=
list
(
runs_df
[
'tags.mlflow.runName'
])
run_name_mapping
=
{}
for
i
in
range
(
len
(
run_id_list
)):
run_name_mapping
[
run_id_list
[
i
]]
=
run_name_list
[
i
]
# getting runs who have a parent-id
df
=
runs_df
[
runs_df
[
self
.
model_parent_run_id_key
]
.
notna
()]
# getting runs who have a model logged
f_df
=
df
[
df
[
self
.
model_history_key
]
.
notna
()]
self
.
delete_run_model_data
(
f_df
,
run_name_mapping
)
else
:
logger
.
info
(
'No runs found for experiment, so no cleanup'
)
else
:
logger
.
info
(
'No runs found for experiment, so no cleanup'
)
return
False
logger
.
info
(
'No parent runs found for experiment, so no cleanup'
)
else
:
logger
.
info
(
"Not a valid experiment..."
)
return
False
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment