Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
DAN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Automatic Text Recognition
DAN
Commits
3dca228f
Verified
Commit
3dca228f
authored
2 years ago
by
Yoann Schneider
Browse files
Options
Downloads
Patches
Plain Diff
encapsulate requests in try except
parent
f49eb518
No related branches found
No related tags found
1 merge request
!59
Robust mlflow requests
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dan/mlflow.py
+15
-3
15 additions, 3 deletions
dan/mlflow.py
with
15 additions
and
3 deletions
dan/mlflow.py
+
15
−
3
View file @
3dca228f
...
...
@@ -3,11 +3,19 @@ import os
from
contextlib
import
contextmanager
import
mlflow
import
requests
from
mlflow.exceptions
import
MlflowException
from
dan
import
logger
def
make_mlflow_request
(
mlflow_method
,
*
args
,
**
kwargs
):
try
:
mlflow_method
(
*
args
,
**
kwargs
)
except
requests
.
exceptions
.
ConnectionError
as
e
:
logger
.
error
(
f
"
Call to `
{
str
(
mlflow_method
)
}
` failed with error:
{
str
(
e
)
}
"
)
def
setup_environment
(
config
:
dict
):
"""
Get the necessary variables from the config file and put them in the environment variables
...
...
@@ -45,7 +53,9 @@ def logging_metrics(
mlflow_values
=
{
f
"
{
step
}
_
{
name
}
"
:
value
for
name
,
value
in
display_values
.
items
()
}
mlflow
.
log_metrics
(
mlflow_values
,
epoch
)
make_mlflow_request
(
mlflow_method
=
mlflow
.
log_metrics
,
metrics
=
mlflow_values
,
step
=
epoch
)
def
logging_tags_metrics
(
...
...
@@ -66,7 +76,7 @@ def logging_tags_metrics(
mlflow_values
=
{
f
"
{
step
}
_
{
name
}
"
:
value
for
name
,
value
in
display_values
.
items
()
}
mlflow
.
set_tags
(
mlflow_values
)
make_mlflow_request
(
mlflow_method
=
mlflow
.
set_tags
,
tags
=
mlflow_values
)
@contextmanager
...
...
@@ -84,7 +94,9 @@ def start_mlflow_run(config: dict):
experiment_id
=
config
.
get
(
"
experiment_id
"
)
assert
experiment_id
,
"
Missing MLflow experiment ID in the configuration
"
try
:
mlflow
.
set_experiment
(
experiment_id
=
experiment_id
)
make_mlflow_request
(
mlflow_method
=
mlflow
.
set_experiment
,
experiment_id
=
experiment_id
)
logger
.
info
(
f
"
Run Experiment ID :
{
experiment_id
}
on MLFlow
"
)
except
MlflowException
as
e
:
logger
.
error
(
f
"
Couldn
'
t set Mlflow experiment with ID:
{
experiment_id
}
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment