Skip to content

armgit / Soup

Public Imported from GitHub
0

Fine-tune LLMs from one YAML. Layer streaming trains an 8B model on a 4 GB laptop GPU.

fix(deps): declare requests in the [train] extra (GRPO and online DPO stopped importing after datasets 5.1.0) (#1637)

Alpamys Makazhan2e3424f6e63e
diff --git a/changelog.d/0.75.1/1637.fixed.md b/changelog.d/0.75.1/1637.fixed.md
new file mode 100644
index 00000000..06006d74
--- /dev/null
+++ b/changelog.d/0.75.1/1637.fixed.md
@@ -0,0 +1,20 @@
+- **A fresh `pip install 'soup-cli[train]'` could no longer run `task: grpo` or
+ `task: online_dpo`: the trainer import stopped with `ModuleNotFoundError: No
+ module named 'requests'` (#1637).** trl imports `requests` at module scope in
+ `trl/generation/vllm_client.py`, and both `trl.trainer.grpo_trainer` and
+ `trl.experimental.online_dpo` import that module unconditionally, but trl
+ lists `requests` only under its optional `vllm` extra. A training install
+ received the package indirectly through `datasets`, until datasets 5.1.0
+ (2026-10-05) dropped that dependency. Environments created before that date
+ keep working because pip does not remove an installed package; environments
+ created after it were missing `requests`. On GRPO the failure surfaced as
+ `RuntimeError: Failed to import trl.trainer.grpo_trainer`, and on online DPO
+ as `installed trl 0.29.1 does not provide 'OnlineDPOConfig'`, with the real
+ cause at the end of the message. The `[train]` extra now declares
+ `requests>=2.32.2` itself — the floor `datasets` carried, so an existing
+ environment resolves to the same set. Trainers that do not load those two
+ trl modules were not affected: on trl 0.29.1 the SFT, DPO, KTO, ORPO, CPO,
+ BCO, PPO and reward trainer classes import without `requests`. On an
+ installed release without this change, `pip install "requests>=2.32.2"`
+ restores both tasks. `tests/test_train_extra_declares_requests.py` pins the
+ declaration.
diff --git a/pyproject.toml b/pyproject.toml
index 5afa740d..3852c9dd 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -110,6 +110,19 @@ train = [
# end-to-end preference tests are what surfaced it.
#
"trl>=0.29.0,<1.0.0",
+ # trl imports `requests` at module scope in trl/generation/vllm_client.py,
+ # and trl.trainer.grpo_trainer and trl.experimental.online_dpo import that
+ # module unconditionally — but trl declares `requests` only under its
+ # optional `vllm` extra (true of 0.29.1 and of 1.14.1). A training install
+ # got it by accident through datasets (`requests>=2.32.2`) until datasets
+ # 5.1.0 (2026-10-05) dropped the dependency; from then on a fresh
+ # `pip install 'soup-cli[train]'` could not import GRPOTrainer or the
+ # online-DPO trainer (`ModuleNotFoundError: No module named 'requests'`).
+ # Soup now declares what its trainers need instead of inheriting it. The
+ # floor is the one datasets carried, so the resolved set does not change.
+ # No ceiling: trl leaves it unbounded. Pinned by
+ # tests/test_train_extra_declares_requests.py.
+ "requests>=2.32.2",
"datasets>=2.14.0",
"bitsandbytes>=0.41.0",
# #352: 0.27.0 added `adapter_only` to `save_fsdp_model`/`load_fsdp_model`, which
diff --git a/tests/test_train_extra_declares_requests.py b/tests/test_train_extra_declares_requests.py
new file mode 100644
index 00000000..284b3e88
--- /dev/null
+++ b/tests/test_train_extra_declares_requests.py
@@ -0,0 +1,117 @@
+"""The ``[train]`` extra must declare ``requests`` itself.
+
+trl imports ``requests`` at module scope in ``trl/generation/vllm_client.py``
+and ``trl.trainer.grpo_trainer`` / ``trl.experimental.online_dpo`` import that
+module unconditionally, yet trl's metadata lists ``requests`` only under its
+optional ``vllm`` extra. A Soup training install therefore received ``requests``
+by accident, through ``datasets`` (``requests>=2.32.2``). datasets 5.1.0
+(2026-10-05) stopped depending on it, and from that moment a fresh
+``pip install 'soup-cli[train]'`` produced an environment in which
+``task: grpo`` and ``task: online_dpo`` fail at import with
+``ModuleNotFoundError: No module named 'requests'``.
+
+These tests pin the declaration, which is the part this repository owns. The
+runtime half is carried by the model-backed smoke tests (``tests/test_grpo.py``,
+``tests/test_issue300_online_dpo_train.py``): they import the real trl trainers
+in the environment pip resolved from this file.
+
+pyproject is parsed with regex rather than ``tomllib`` because ``tomllib`` is
+3.11+ and this repo supports 3.10 — the same convention as
+``tests/test_issue636_torch_floor.py``.
+"""
+
+from __future__ import annotations
+
+import importlib
+import pathlib
+import re
+
+import pytest
+from packaging.requirements import Requirement
+from packaging.version import Version
+
+ROOT = pathlib.Path(__file__).resolve().parents[1]
+PYPROJECT = ROOT / "pyproject.toml"
+
+# The floor datasets declared through 5.0.1, i.e. what every training install
+# resolved until the transitive route disappeared.
+_FLOOR_BEFORE_THE_ROUTE_WENT_AWAY = Version("2.32.2")
+
+
+def _train_extra_requirements() -> list[Requirement]:
+ text = PYPROJECT.read_text(encoding="utf-8")
+ table = re.search(
+ r"^\[project\.optional-dependencies\]\s*$(.*?)^\[", text, re.M | re.S
+ )
+ assert table, "pyproject.toml has no [project.optional-dependencies] table"
+ train = re.search(r"^train\s*=\s*\[(.*?)^\]", table.group(1), re.M | re.S)
+ assert train, "no train = [...] array in [project.optional-dependencies]"
+ # Either TOML string quote, an optional trailing comma and an optional
+ # trailing comment: a marker is normally written with the other quote
+ # inside ("requests; extra == 'vllm'"), so both spellings must parse.
+ entries = [
+ double or single
+ for double, single in re.findall(
+ r"""^\s*(?:"([^"]+)"|'([^']+)')\s*,?\s*(?:#.*)?$""", train.group(1), re.M
+ )
+ ]
+ assert entries, "the [train] extra parsed to no requirement strings"
+ return [Requirement(entry) for entry in entries]
+
+
+def _train_requirement(name: str) -> Requirement | None:
+ for requirement in _train_extra_requirements():
+ if requirement.name.lower() == name:
+ return requirement
+ return None
+
+
+class TestTrainExtraDeclaresRequests:
+ def test_the_parser_sees_the_known_entries(self) -> None:
+ # Guards the regex itself: a parser that silently returned one entry
+ # would make the assertions below vacuous in the passing direction.
+ names = {requirement.name.lower() for requirement in _train_extra_requirements()}
+ assert {"torch", "transformers", "peft", "trl", "datasets", "accelerate"} <= names
+
+ def test_requests_is_a_direct_requirement_of_the_train_extra(self) -> None:
+ # Mutation check: delete the "requests>=..." line from [train] and this
+ # fails by name.
+ requirement = _train_requirement("requests")
+ assert requirement is not None, (
+ "the [train] extra does not declare requests: trl's GRPO and online-DPO "
+ "trainers import it at module scope and no other [train] requirement "
+ "is guaranteed to bring it (datasets stopped at 5.1.0)"
+ )
+
+ def test_the_requirement_applies_to_every_train_install(self) -> None:
+ # A marker ("; extra == ...", "; sys_platform == ...") would bring the
+ # failure back for the installs it excludes.
+ requirement = _train_requirement("requests")
+ assert requirement is not None
+ assert requirement.marker is None, (
+ f"requests is declared with a marker ({requirement.marker}); it must be "
+ "unconditional inside [train]"
+ )
+ assert not requirement.extras
+
+ def test_the_floor_is_the_one_installs_already_resolved(self) -> None:
+ requirement = _train_requirement("requests")
+ assert requirement is not None
+ floors = [
+ Version(spec.version)
+ for spec in requirement.specifier
+ if spec.operator in (">=", "~=", "==")
+ ]
+ assert floors, f"requests is declared without a floor: {requirement}"
+ assert max(floors) >= _FLOOR_BEFORE_THE_ROUTE_WENT_AWAY
+ # No ceiling: trl 0.29 uses only requests.Session, adapters.HTTPAdapter
+ # and ConnectionError, and trl's own metadata leaves requests unbounded.
+ ceilings = [spec for spec in requirement.specifier if spec.operator in ("<", "<=")]
+ assert not ceilings, f"requests must not be capped in [train]: {requirement}"
+
+
+def test_requests_is_importable_wherever_trl_is() -> None:
+ """The symptom itself, from the report in #1634: with trl installed, ``requests``
+ must be present, whichever package used to bring it in."""
+ pytest.importorskip("trl")
+ importlib.import_module("requests")