Repository navigation
[BugFix] Let test_trainer.py collect without Hydra so tests-optdeps runs again - #4679
Conversation
…uns again test_trainer.py imported hydra and torchrl.trainers.algorithms.configs at module level (since pytorch#4459). The configs package raises ImportError on purpose without Hydra, so in the tests-optdeps job pytest stopped at collection and the job has run no tests since 2026-09-25. Check for Hydra with _has_hydra at module top, import Hydra and the config classes inside the tests that use them, and skip those tests when Hydra is missing. This also skips the TdMpc2 trainer and stepper tests and the omegaconf-based LogReward test, which were masked by the collection error and fail with ModuleNotFoundError once the file collects.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4679
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 Cancelled JobAs of commit 01d4006 with merge base 1084821 ( CANCELLED JOB - The following job was cancelled. Please retry:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
theap06
left a comment
There was a problem hiding this comment.
Thanks for the PR! LGTM! This also resolves our failing windows optdeps job.
|
Thanks for the review and for adding A note on the cancelled The 59 failures are all outside
The job also runs close to its time limit now that it gets past collection (about 111 minutes of test time), so it may need a higher |
Thanks! Just looked at the log! the device-parametrized tests aren't marked as gpu. We should increase the timeout for ci as well. |
Description
tests-optdepshas failed on every push tomainsince Sept 25. The last green run wasbc199cd1.The job stops at collection, so it hasn't run any tests since then:
#4459 added module-level
from hydra.core.config_store import ConfigStoreandfrom hydra.utils import instantiatetotest/test_trainer.py.test_trainer.pyalso importsFQLLossConfig, FQLTrainerConfigfromtorchrl.trainers.algorithms.configs, which raisesImportErroron purpose when Hydra is missing.The optdeps environment doesn't install Hydra.
This PR follows the optional-dependency pattern from
CLAUDE.mdandtest/test_configs.py. It adds_has_hydra = importlib.util.find_spec("hydra") is not Noneat module top, moves the Hydra and config imports into the tests that use them, and skips those tests when Hydra is absent:test_fql_hydra_configsandtest_fql_config_constructor_parity;TestTdMpc2OptimizationStepperandTestTdMpc2Trainer, whose helpers already importedhydra.utils.instantiatelazily but weren't skipped. They were hidden behind the collection error and fail withModuleNotFoundErroronce the file collects;TestLogReward::test_log_reward_normalizes_hydra_nested_key, which importsomegaconf.No library code changes. With Hydra installed, the same tests run as before.
Could a maintainer add the
ci/optdepslabel so the full optdeps suite runs on this PR? It may surface failures elsewhere that have been masked since Sept 25.Motivation and Context
tests-optdepschecks that TorchRL works without optional dependencies, and it has been red on everymainpush since Sept 25 without running any tests.close #4680
Types of changes
Testing
CPU-only torch 2.14.1, tensordict 0.15.4, Python 3.12 on Windows, TorchRL from source (C++ extension not built):
python -m pytest --collect-only -q test/test_trainer.py:no tests collected, 1 error;278 tests collected.python -m pytest -q test/test_trainer.py -m "not gpu":hydra-coreinstalled, the same command gives identical results on this branch and onmain: 244 passed, 21 skipped.mainwith and without this change:TestRBwithprioritized=Trueneeds the compiled extension (SumSegmentTreeFp32 is not available);test_fql_update_matches_recipe[True-cpu]needs MSVC fortorch.compileon Windows;TestOnPolicyTelemetry::test_standard_telemetry_for_finite_ppo_update_with_nested_keys.pytest --collect-only test --ignore test/test_rlhf.py --ignore test/test_distributed.py --ignore test/llm) without Hydra gives 29372 tests collected.The only remaining errors are local:
scipyand the C++ extension, both of which the optdeps job installs.I used an AI assistant (Claude Code) to help find the cause and run the checks. I've read and tested every changed line.
Checklist