From 2715a7e822b603520882790df7931240295b3e1d Mon Sep 17 00:00:00 2001 From: Michael Ivanitskiy Date: Tue, 17 Jun 2025 13:47:53 -0700 Subject: [PATCH 1/2] update torch dep for using set_submodule change the pytorch dependency to be '>2.4.1' because pytorch 2.4.1 does not have `nn.Module.set_submodule()`, running `lm_decomposition.py` gives the error: ``` File "~/apd/spd/experiments/lm/lm_decomposition.py", line 146, in main optimize( File "/home/miv/projects/MATS/apd/spd/run_spd.py", line 242, in optimize layerwise_random_recon_loss = calc_layerwise_recon_loss( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "~/apd/spd/losses.py", line 135, in calc_layerwise_recon_loss modified_out = model.forward_with_component( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "~/apd/spd/models/component_model.py", line 141, in forward_with_component self.model.set_submodule(module_name, component) ^^^^^^^^^^^^^^^^^^^^^^^^ File "~/apd/.venv/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1729, in __getattr__ raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'") AttributeError: 'GPTNeoForCausalLM' object has no attribute 'set_submodule' ``` --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2a4eb2f..f65b9c4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ description = "Sparse Parameter Decomposition" requires-python = ">=3.11" readme = "README.md" dependencies = [ - "torch<2.6.0", + "torch>2.4.1,<2.6.0", "torchvision", "pydantic", "wandb", From e4434eecfbba4068926cd9e324061caed063d016 Mon Sep 17 00:00:00 2001 From: Michael Ivanitskiy Date: Tue, 17 Jun 2025 13:56:14 -0700 Subject: [PATCH 2/2] fix loading pretrained models from hf due to pytorch vuln https://nvd.nist.gov/vuln/detail/CVE-2025-32434 huggingface transformers library doesn't allow loading with weights_only=True so, we add to `lm_decomposition.py:main()` a kwarg `weights_only` passed on to `load_pretrained()` --- spd/experiments/lm/lm_decomposition.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spd/experiments/lm/lm_decomposition.py b/spd/experiments/lm/lm_decomposition.py index 1d9a189..88892b5 100644 --- a/spd/experiments/lm/lm_decomposition.py +++ b/spd/experiments/lm/lm_decomposition.py @@ -49,7 +49,11 @@ def plot_lm_results( def main( - config_path_or_obj: Path | str | Config, sweep_config_path: Path | str | None = None + config_path_or_obj: Path | str | Config, + sweep_config_path: Path | str | None = None, + # due to pytorch vuln https://nvd.nist.gov/vuln/detail/CVE-2025-32434 + # hf `transformers` library doesn't allow loading with weights_only=True + weights_only: bool = True, ) -> None: config = load_config(config_path_or_obj, config_model=Config) @@ -72,6 +76,7 @@ def main( path_to_class=config.pretrained_model_class, model_path=None, model_name_hf=config.pretrained_model_name_hf, + weights_only=weights_only, ) # --- Setup Run Name and Output Dir --- #