Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
dbe3ec2
add get_clearml_task method and test cases
sallycaoyu Mar 22, 2023
b557a21
fix doc
sallycaoyu Mar 22, 2023
8f93dd2
fix doc
sallycaoyu Mar 22, 2023
f322dc2
remove local files
sallycaoyu Mar 22, 2023
7b7eca3
modified get_task and added point1
sallycaoyu Mar 22, 2023
d579afe
remove local files
sallycaoyu Mar 22, 2023
fe90e71
add get_task_bypass test
sallycaoyu Mar 23, 2023
7d1dd2b
modify docstring
sallycaoyu Mar 23, 2023
a782373
fix types
sallycaoyu Mar 23, 2023
0aadcba
add pytest warning context manager
sallycaoyu Mar 23, 2023
c628a28
change task in bypass mode from _Stub to an offline Task
sallycaoyu Mar 24, 2023
f5b87dd
change link docstring fmt
sallycaoyu Mar 24, 2023
47dca59
change docstring fmt
sallycaoyu Mar 24, 2023
be97cde
Merge branch 'master' into clearmllogger-task
vfdev-5 Mar 28, 2023
e972faa
Merge branch 'master' of github.com:pytorch/ignite into clearmllogger…
sallycaoyu Mar 28, 2023
3819618
delete return
sallycaoyu Mar 28, 2023
67ed056
Merge branch 'clearmllogger-task' of github.com:sallycaoyu/ignite int…
sallycaoyu Mar 28, 2023
bb5d49b
Merge branch 'master' into clearmllogger-task
vfdev-5 Mar 30, 2023
2c211d4
Merge branch 'master' into clearmllogger-task
vfdev-5 Mar 30, 2023
8ab771a
remove the mock projects of Task.current() from test_clearml_logger.py
sallycaoyu Mar 30, 2023
7aa7959
change previous mocked Task.current() to create real Task objects
sallycaoyu Mar 30, 2023
3d7b219
remove extra files
sallycaoyu Mar 30, 2023
67f38f9
changed Task.current() to magicmock in test_clearml_logger
sallycaoyu Mar 30, 2023
e0329c1
Merge branch 'master' into clearmllogger-task
vfdev-5 Mar 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions ignite/contrib/handlers/clearml_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from enum import Enum
from typing import Any, Callable, DefaultDict, List, Mapping, Optional, Tuple, Type, Union

from clearml import Task
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


from torch.optim import Optimizer

import ignite.distributed as idist
Expand Down Expand Up @@ -178,6 +180,20 @@ def bypass_mode(cls) -> bool:
"""
return getattr(cls, "_bypass", bool(os.environ.get("CI")))

def get_clearml_task(self) -> Union[None, Task]:
"""
Returns the ClearML Task.

Return:
If bypass mode state is ``True``, all outside communication is skipped,
and ``get_task`` will return ``None``.
If bypass mode state is ``False``, this method will return the ClearML Task.
"""
if self.bypass_mode():
return None

return self._task

def close(self) -> None:
self.clearml_logger.flush()

Expand Down
30 changes: 30 additions & 0 deletions tests/ignite/contrib/handlers/test_clearml_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import clearml
import pytest
import torch
from clearml import Task
from clearml.binding.frameworks import WeightsFileHandler
from clearml.model import Framework

Expand All @@ -26,6 +27,35 @@
from ignite.handlers import Checkpoint


def test_clearml_logger_get_clearml_task_bypass(dirname):

with pytest.warns(UserWarning, match="ClearMLSaver: running in bypass mode"):
ClearMLLogger.set_bypass_mode(True)
with ClearMLLogger(output_uri=dirname) as clearml_logger:
assert clearml_logger.get_clearml_task() is None


def test_clearml_logger_get_clearml_task_not_bypass_create_task():

ClearMLLogger.set_bypass_mode(False)
with ClearMLLogger() as clearml_logger:
res_task = clearml_logger.get_clearml_task()
assert res_task == Task.current_task()
res_task.close()


def test_clearml_logger_get_clearml_task_not_bypass_task_already_exists():

user_created_task = Task.init(project_name="experiment", task_name="experiment")

ClearMLLogger.set_bypass_mode(False)
with ClearMLLogger(project_name="experiment", task_name="experiment") as clearml_logger:
res_task = clearml_logger.get_clearml_task()
assert res_task == user_created_task
res_task.close()
user_created_task.close()


def test_no_clearml():
with patch.dict("sys.modules", {"clearml": None, "trains": None}):
with pytest.raises(ModuleNotFoundError, match=r"This contrib module requires clearml to be installed."):
Expand Down