Skip to content

[BUG] tests-optdeps has failed at collection since Sept 25: test_trainer.py imports Hydra unconditionally #4680

Closed

Description

@sramireddy2

Describe the bug

The tests-optdeps (3.12, 13.0) job in test-linux.yml has failed on every push to main since 2026-09-25. The last green run was on bc199cd1.
It never gets past collection, so the job has run no tests since then:

ERROR collecting test/test_trainer.py
E   ModuleNotFoundError: No module named 'hydra'
!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!

test/test_trainer.py imports hydra.core.config_store.ConfigStore and hydra.utils.instantiate at module level (added with the FQL benchmark commit 5e402a4e, #4459). It also imports FQLLossConfig and FQLTrainerConfig from torchrl.trainers.algorithms.configs, which raises ImportError on purpose when Hydra is missing. The optdeps environment doesn't install Hydra.

To Reproduce

In an environment without hydra-core:

python -m pytest --collect-only -q test/test_trainer.py
E   ModuleNotFoundError: No module named 'hydra'
!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
no tests collected, 1 error in 0.62s

Expected behavior

test_trainer.py collects without Hydra, and the Hydra-dependent tests are skipped, like the _has_hydra / skipif tests in test/test_configs.py. Then tests-optdeps runs the suite again.

System info

Installed from source (main at 1084821), Python 3.12.10, torch 2.14.1+cpu, tensordict 0.15.4, numpy 2.5.4, win32. The same collection error shows in the Linux tests-optdeps job log on main.

import torchrl, numpy, sys
print(torchrl.__version__, numpy.__version__, sys.version, sys.platform)
# None 2.5.4 3.12.10 win32  (source checkout, no version file)

Reason and Possible fixes

Use _has_hydra = importlib.util.find_spec("hydra") is not None at module top, import Hydra and the config classes inside the tests that use them, and skip those tests without Hydra.
Once the file collects, TestTdMpc2OptimizationStepper, TestTdMpc2Trainer and TestLogReward::test_log_reward_normalizes_hydra_nested_key also fail without Hydra/omegaconf, because their helpers import Hydra lazily without a skip. They need the same guard.

Fix proposed in #4679.

Checklist

  • I have checked that there is no similar issue in the repo (required)
  • I have read the documentation (required)
  • I have provided a minimal working example to reproduce the bug (required)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions