Skip to content

Commit 6317a8c

Browse files
garciadiasclaude
andcommitted
fix: address Dependabot security alerts for mlflow, transformers, setuptools
- mlflow: bump floor to >=3.11.1 (drops the <3.0 cap), closing CVEs across the 2.x/early-3.x line. The cap existed for a Python 3.12 packaging bug in mlflow.utils.uv_utils that is no longer present in current releases. mlflow>=3.13 also turns the local file-store warning into a hard error (#8891); MLFlowHandler now sets MLFLOW_ALLOW_FILE_STORE=true by default since it documents and relies on that local store. Documented the side effect in the class docstring and added tests covering both the unset-defaults-to-true and existing-value-is-preserved cases. - transformers: bump floor to >=5.5.0 (drops the <5.0 cap), closing two HIGH severity CVEs. The cap existed because transformers>=5.x broke Transchex: BertConfig was previously a bare ad-hoc class missing `_attn_implementation`, and BertLayer's forward() return type changed from a tuple to a bare Tensor (the latter was already handled). Fixed both in transchex.py and verified against transformers 4.36-4.40 and 5.5-5.14. The previous <5.0 cap's stated reason (torch.float8_e8m0fnu missing from the nv25.03 Docker image's PyTorch 2.7 build) is unrelated to transchex.py and should be re-verified against the current NGC base image before merging, since it wasn't reproducible against a stock PyPI torch>=2.8.0 install. - setuptools: bump requirements-min.txt floor to >=78.1.1, closing one HIGH severity CVE. Still capped at <=79.0.1 because setuptools>=80 breaks MONAI's own setup.py CLI usage (#8439); a MEDIUM severity CVE fixed in 83.0.0 remains open until that's resolved. Also drop requirements-dev.txt's separate `setuptools<71` cap, which conflicted with that floor and broke CI dependency installation (mypy, hyena-dep, full-dep): it was added for MetricsReloaded's legacy pkg_resources-based setup.py, but the `monai-support` branch already has that import commented out, and the pinned segment-anything commit never used pkg_resources either, so the cap is no longer needed. Verified via targeted venv testing against the actual pinned versions (transformers==5.5.0, mlflow==3.11.1): tests/networks/nets/test_transchex.py and tests/handlers/test_handler_mlflow.py both pass. CodeRabbit flagged MultiModal.__init__ (transchex.py) for allegedly calling transformers' PreTrainedModel.__init__() without a config, which 5.5.0 requires. That's a false positive: MultiModal subclasses transchex.py's own local `BertPreTrainedModel(nn.Module)` shim, not transformers' class, so HF's config-in-super().__init__() requirement doesn't apply. Confirmed by running the test suite unchanged against transformers 5.5.0 (3 passed). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Signed-off-by: R. Garcia-Dias <rafaelagd@gmail.com>
1 parent ed76cd5 commit 6317a8c

6 files changed

Lines changed: 56 additions & 8 deletions

File tree

docs/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ sphinxcontrib-serializinghtml
2020
sphinx-autodoc-typehints==1.11.1
2121
pandas
2222
einops
23-
transformers>=4.53.0
24-
mlflow>=2.12.2,<3.13
23+
transformers>=5.5.0
24+
mlflow>=3.11.1 # see requirements-dev.txt for why the previous <3.0/<3.13 caps are no longer needed
2525
clearml>=1.10.0rc0
2626
tensorboardX
2727
imagecodecs; platform_system == "Linux" or platform_system == "Darwin"

monai/handlers/mlflow_handler.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ class MLFlowHandler:
6060
``engine.state.metrics`` in MLFlow.
6161
- When ITERATION_COMPLETED, track expected item in
6262
``self.output_transform(engine.state.output)`` in MLFlow, default to `Loss`.
63+
- On construction, sets the ``MLFLOW_ALLOW_FILE_STORE`` environment variable to
64+
``"true"`` if it is not already set, since ``MLFlowHandler`` defaults to (and
65+
documents) tracking to the local filesystem store, which mlflow>=3.13 otherwise
66+
refuses to use. Any value the user has already set is left untouched.
6367
6468
Usage example is available in the tutorial:
6569
https://github.com/Project-MONAI/tutorials/blob/master/3d_segmentation/unet_segmentation_3d_ignite.ipynb.
@@ -156,6 +160,11 @@ def __init__(
156160
self.experiment_param = experiment_param
157161
self.artifacts = ensure_tuple(artifacts)
158162
self.optimizer_param_names = ensure_tuple(optimizer_param_names)
163+
# mlflow>=3.13 raises instead of warning when the tracking URI resolves to the local
164+
# filesystem store (e.g. the default `mlruns` directory), see
165+
# https://github.com/Project-MONAI/MONAI/issues/8891. MLFlowHandler documents and relies
166+
# on this local file store as its default, so opt back into it unless the user overrode it.
167+
os.environ.setdefault("MLFLOW_ALLOW_FILE_STORE", "true")
159168
self.client = mlflow.MlflowClient(tracking_uri=tracking_uri if tracking_uri else None)
160169
self.run_finish_status = mlflow.entities.RunStatus.to_string(mlflow.entities.RunStatus.FINISHED)
161170
self.close_on_complete = close_on_complete

monai/networks/nets/transchex.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
transformers = optional_import("transformers")
2424
load_tf_weights_in_bert = optional_import("transformers", name="load_tf_weights_in_bert")[0]
2525
cached_file = optional_import("transformers.utils", name="cached_file")[0]
26+
BertConfig = optional_import("transformers", name="BertConfig")[0]
2627
BertEmbeddings = optional_import("transformers.models.bert.modeling_bert", name="BertEmbeddings")[0]
2728
BertLayer = optional_import("transformers.models.bert.modeling_bert", name="BertLayer")[0]
2829

@@ -219,7 +220,11 @@ def __init__(
219220
220221
"""
221222
super().__init__()
222-
self.config = type("obj", (object,), bert_config)
223+
self.config = BertConfig(**bert_config)
224+
# explicitly select the eager attention path: transformers>=4.48 dispatches attention
225+
# implementations via `config._attn_implementation`, which is otherwise left unset since
226+
# `bert_config` above does not come from a `from_pretrained` call.
227+
self.config._attn_implementation = "eager"
223228
self.embeddings = BertEmbeddings(self.config)
224229
self.language_encoder = nn.ModuleList([BertLayer(self.config) for _ in range(num_language_layers)])
225230
self.vision_encoder = nn.ModuleList([BertLayer(self.config) for _ in range(num_vision_layers)])

requirements-dev.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ black>=26.3.1
1818
isort>=5.1, <6, !=6.0.0
1919
ruff>=0.14.11,<0.15
2020
pybind11
21-
setuptools<71 # pkg_resources removed in setuptools>=71; needed by MetricsReloaded setup.py
2221
types-setuptools
2322
mypy>=1.5.0, <1.12.0
2423
ninja
@@ -34,8 +33,15 @@ tifffile; platform_system == "Linux" or platform_system == "Darwin"
3433
pandas
3534
requests
3635
einops
37-
transformers>=4.53.0, <5.0 # 5.x references torch.float8_e8m0fnu absent in older PyTorch builds
38-
mlflow>=2.12.2, <3.0 # 3.x broken on Python 3.12 (relative import in mlflow.utils.uv_utils)
36+
transformers>=5.5.0 # 4.x/early-5.x are vulnerable (GHSA-fgcw-684q-jj6r, GHSA-29pf-2h5f-8g72); the
37+
# previous <5.0 cap was needed because the nv25.03 Docker image's PyTorch 2.7 build lacked
38+
# `torch.float8_e8m0fnu`; the PyPI `torch>=2.8.0` floor this repo declares has it, and
39+
# `monai/networks/nets/transchex.py` has been updated for transformers>=5's BertLayer/BertConfig
40+
# API changes. Re-verify against the current NGC base image before merging.
41+
mlflow>=3.11.1 # <3.4.0rc0 through <=3.10.1 versions have several CVEs; the previous <3.0 cap was
42+
# for a Python 3.12 packaging bug in mlflow.utils.uv_utils, no longer present in current releases.
43+
# mlflow>=3.13 also hard-errors on the local file-store backend unless MLFLOW_ALLOW_FILE_STORE=true
44+
# (see monai/handlers/mlflow_handler.py and https://github.com/Project-MONAI/MONAI/issues/8891).
3945
clearml>=1.10.0rc0
4046
matplotlib>=3.6.3
4147
tensorboardX

requirements-min.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Requirements for minimal tests
22
-r requirements.txt
3-
setuptools>=50.3.0,<66.0.0,!=60.6.0 ; python_version < "3.12"
4-
setuptools>=70.2.0,<=79.0.1; python_version >= "3.12"
3+
# <78.1.1 is vulnerable to GHSA-5rjg-fvgr-3xxf (path traversal / arbitrary file write). The
4+
# upper bound is unrelated to the CVE: setuptools>=80 dropped the legacy `setup.py` CLI
5+
# invocation MONAI's own build script relies on (Project-MONAI/MONAI#8439), so this can't yet
6+
# go as high as 83.0.0, which would also fix GHSA-h35f-9h28-mq5c (MANIFEST.in exclusion bypass).
7+
setuptools>=78.1.1,<=79.0.1
58
coverage>=5.5
69
parameterized
710
packaging

tests/handlers/test_handler_mlflow.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,31 @@ def _update_metric(engine):
106106
# the run count should equal to the times of creating engine
107107
self.assertEqual(create_engine_times, run_cnt)
108108

109+
def test_allow_file_store_env_var_defaults_true(self):
110+
original = os.environ.pop("MLFLOW_ALLOW_FILE_STORE", None)
111+
try:
112+
with tempfile.TemporaryDirectory() as tempdir:
113+
MLFlowHandler(tracking_uri=path_to_uri(os.path.join(tempdir, "mlflow_test")))
114+
self.assertEqual(os.environ["MLFLOW_ALLOW_FILE_STORE"], "true")
115+
finally:
116+
if original is None:
117+
os.environ.pop("MLFLOW_ALLOW_FILE_STORE", None)
118+
else:
119+
os.environ["MLFLOW_ALLOW_FILE_STORE"] = original
120+
121+
def test_allow_file_store_env_var_preserves_existing(self):
122+
original = os.environ.get("MLFLOW_ALLOW_FILE_STORE")
123+
os.environ["MLFLOW_ALLOW_FILE_STORE"] = "false"
124+
try:
125+
with tempfile.TemporaryDirectory() as tempdir:
126+
MLFlowHandler(tracking_uri=path_to_uri(os.path.join(tempdir, "mlflow_test")))
127+
self.assertEqual(os.environ["MLFLOW_ALLOW_FILE_STORE"], "false")
128+
finally:
129+
if original is None:
130+
os.environ.pop("MLFLOW_ALLOW_FILE_STORE", None)
131+
else:
132+
os.environ["MLFLOW_ALLOW_FILE_STORE"] = original
133+
109134
def test_metrics_track(self):
110135
experiment_param = {"backbone": "efficientnet_b0"}
111136
with tempfile.TemporaryDirectory() as tempdir:

0 commit comments

Comments
 (0)