pytorch-lightning icon indicating copy to clipboard operation
pytorch-lightning copied to clipboard

`isinstance(treespec, LeafSpec)` is deprecated, use `isinstance(treespec, TreeSpec) and treespec.is_leaf()` instead

Open mscheltienne opened this issue 1 month ago • 2 comments

Bug description

The following FutureWarning appeared in our CIs:

tests/integration/lightning/test_training_integration.py:415: in test_training_with_different_optimizers
    trainer.fit(model, train_loader, val_loader)
.venv/lib/python3.13/site-packages/lightning/pytorch/trainer/trainer.py:560: in fit
    call._call_and_handle_interrupt(
.venv/lib/python3.13/site-packages/lightning/pytorch/trainer/call.py:49: in _call_and_handle_interrupt
    return trainer_fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/lightning/pytorch/trainer/trainer.py:598: in _fit_impl
    self._run(model, ckpt_path=ckpt_path)
.venv/lib/python3.13/site-packages/lightning/pytorch/trainer/trainer.py:1011: in _run
    results = self._run_stage()
              ^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/lightning/pytorch/trainer/trainer.py:1053: in _run_stage
    self._run_sanity_check()
.venv/lib/python3.13/site-packages/lightning/pytorch/trainer/trainer.py:1082: in _run_sanity_check
    val_loop.run()
.venv/lib/python3.13/site-packages/lightning/pytorch/loops/utilities.py:179: in _decorator
    return loop_run(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/lightning/pytorch/loops/evaluation_loop.py:120: in run
    self.setup_data()
.venv/lib/python3.13/site-packages/lightning/pytorch/loops/evaluation_loop.py:180: in setup_data
    combined_loader = CombinedLoader(dataloaders, "sequential")
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/lightning/pytorch/utilities/combined_loader.py:288: in __init__
    self._flattened, self._spec = _tree_flatten(iterables)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/lightning/pytorch/utilities/_pytree.py:21: in _tree_flatten
    return [pytree], LeafSpec()
                     ^^^^^^^^^^
../../_temp/uv-python-dir/cpython-3.13.9-linux-x86_64-gnu/lib/python3.13/warnings.py:594: in __new__
    warn(msg, category=category, stacklevel=stacklevel + 1)
E   FutureWarning: `isinstance(treespec, LeafSpec)` is deprecated, use `isinstance(treespec, TreeSpec) and treespec.is_leaf()` instead.

What version are you seeing the problem on?

v2.5

Reproduced in studio

N/A

How to reproduce the bug

N/A

Error messages and logs

N/A

Environment

Current environment
lightning:              2.5.5
torch:                  2.10.0.dev20251103+cpu

More info

N/A

cc @ethanwharris

mscheltienne avatar Nov 03 '25 10:11 mscheltienne

Hi @mscheltienne, thanks for raising this issue. I am trying to reproduce the issue and is not able to do. However, I can see you are running torch 2.10 (dev branch) so this is probably the reason, I will investigate further.

SkafteNicki avatar Nov 07 '25 13:11 SkafteNicki

Yes, this warning appeared in our pre-release CI which tests our dependencies against their nightly release. I suspect torch changed something that is now yielding this warning.

mscheltienne avatar Nov 07 '25 13:11 mscheltienne