Skip to content

Commit bbd28a1

Browse files
SkafteNickipre-commit-ci[bot]Borda
authored
update integration with Tensorflow (#119)
* Apply suggestions from code review --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jirka Borovec <[email protected]>
1 parent e9075da commit bbd28a1

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/litmodels/io/utils.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1+
import os
12
import pickle
3+
from contextlib import contextmanager
24
from pathlib import Path
35
from typing import Any, Union
46

57
from lightning_utilities import module_available
68
from lightning_utilities.core.imports import RequirementCache
79

10+
11+
@contextmanager
12+
def _suppress_os_stderr():
13+
devnull_fd = os.open(os.devnull, os.O_WRONLY)
14+
old_stderr_fd = os.dup(2)
15+
os.dup2(devnull_fd, 2) # redirect stderr (fd 2) to /dev/null
16+
os.close(devnull_fd)
17+
try:
18+
yield
19+
finally:
20+
os.dup2(old_stderr_fd, 2) # restore stderr
21+
os.close(old_stderr_fd)
22+
23+
824
_JOBLIB_AVAILABLE = module_available("joblib")
925
_PYTORCH_AVAILABLE = module_available("torch")
10-
_TENSORFLOW_AVAILABLE = module_available("tensorflow")
11-
_KERAS_AVAILABLE = RequirementCache("tensorflow >=2.0.0")
26+
with _suppress_os_stderr():
27+
_TENSORFLOW_AVAILABLE = module_available("tensorflow")
28+
_KERAS_AVAILABLE = RequirementCache("tensorflow >=2.0.0")
1229

1330
if _JOBLIB_AVAILABLE:
1431
import joblib

0 commit comments

Comments
 (0)