Fine-tune LLMs from one YAML. Layer streaming trains an 8B model on a 4 GB laptop GPU.
Python cliconsumer-gpudpofine-tuningggufhuggingfacellmllmopslocal-ailocal-llmloralow-vrammachine-learningollamapeftpythonpytorchqlorasfttransformers
fix(expect): name at most ten unknown suite keys, then count the rest (#1570)
Srinivasan R305a4476c5dd
diff --git a/changelog.d/0.75.1/1570.fixed.md b/changelog.d/0.75.1/1570.fixed.mdnew file mode 100644index 00000000..d5cef99c--- /dev/null+++ b/changelog.d/0.75.1/1570.fixed.md@@ -0,0 +1 @@+- **`soup expect` names at most ten unknown suite keys in a refusal, then counts the rest (by @Srinivasan8888 in #1570).** The refusals #1461 and #1499 added for a key beside `name` / `args` and for a key beside `expectations:` named every offending key, so a suite under the 1 MiB cap with tens of thousands of unknown keys produced a message nearly as large as the file. The first ten are named and the remainder reported as `and N more`; messages with ten keys or fewer are unchanged.diff --git a/src/soup_cli/utils/expectations.py b/src/soup_cli/utils/expectations.pyindex b11cf9a3..698c1837 100644--- a/src/soup_cli/utils/expectations.py+++ b/src/soup_cli/utils/expectations.py@@ -817,6 +817,17 @@ def _key_repr(key: object) -> str:return repr(str(key)[:_MAX_NAME_LEN])+_MAX_KEYS_NAMED = 10+++def _key_list(keys: Sequence[object]) -> str:+ # Ten keys and a count: a 1 MiB suite can carry tens of thousands of unknown keys,+ # and naming them all made the message nearly as large as the file.+ shown = ", ".join(map(_key_repr, keys[:_MAX_KEYS_NAMED]))+ rest = len(keys) - _MAX_KEYS_NAMED+ return f"{shown} and {rest} more" if rest > 0 else shown++def _validate_entry_keys(index: int, name: str, entry: Mapping[str, Any]) -> None:extra = [key for key in entry if key not in _ENTRY_KEYS]if not extra:@@ -824,11 +835,11 @@ def _validate_entry_keys(index: int, name: str, entry: Mapping[str, Any]) -> Nonmisplaced = [key for key in extra if key in _EXPECTATION_ARGS[name]]if misplaced:raise ValueError(- f"expectations[{index}]: {', '.join(map(_key_repr, misplaced))} "+ f"expectations[{index}]: {_key_list(misplaced)} "f"must go under 'args:' for {name}, not beside 'name'")raise ValueError(- f"expectations[{index}]: unknown key(s) {', '.join(map(_key_repr, extra))}; "+ f"expectations[{index}]: unknown key(s) {_key_list(extra)}; ""an entry takes only 'name' and 'args'")@@ -873,7 +884,7 @@ def parse_suite_spec(raw: Any) -> SuiteSpec:extra = [key for key in raw if key != "expectations"]if extra: # #1483: a top-level key is a typo or an option that does not existraise ValueError(- f"unknown top-level key(s) {', '.join(map(_key_repr, extra))}; "+ f"unknown top-level key(s) {_key_list(extra)}; ""a suite takes only 'expectations'")raw_expectations = raw.get("expectations")diff --git a/tests/test_expect_unknown_key_lists_are_bounded.py b/tests/test_expect_unknown_key_lists_are_bounded.pynew file mode 100644index 00000000..052af5ed--- /dev/null+++ b/tests/test_expect_unknown_key_lists_are_bounded.py@@ -0,0 +1,58 @@+"""Follow-up to #1461 / #1499: the unknown-key messages name at most ten keys.++A suite under the 1 MiB cap can carry tens of thousands of top-level or entry keys;+naming every one of them produced a message close to a megabyte. The first ten are+named and the rest counted as "and N more"; ten or fewer keys read exactly as before.+"""++from __future__ import annotations++import pytest++from soup_cli.utils.expectations import parse_suite_yaml++_KEYS = [f"k{i:02d}" for i in range(50)]+++def _top_level(n: int) -> str:+ return "".join(f"{k}: 1\n" for k in _KEYS[:n]) + "expectations:\n - name: expect_no_pii\n"+++def _entry_level(n: int) -> str:+ return "expectations:\n - name: expect_no_pii\n" + "".join(f" {k}: 1\n" for k in _KEYS[:n])++[email protected]("suite", [_top_level, _entry_level], ids=["top-level", "entry"])+def test_fifty_unknown_keys_name_ten_and_count_the_rest(suite) -> None:+ with pytest.raises(ValueError) as info:+ parse_suite_yaml(suite(50))+ message = str(info.value)+ assert all(f"'{k}'" in message for k in _KEYS[:10])+ assert "'k10'" not in message+ assert "and 40 more" in message+ assert len(message) < 400++[email protected]("suite", [_top_level, _entry_level], ids=["top-level", "entry"])[email protected]("n", [9, 10, 11])+def test_the_boundary_at_ten_keys(suite, n: int) -> None:+ # 9 and 10 name every key with no "more"; 11 names ten, counts one, and the+ # eleventh key is absent. A cap moved by one (`rest > 1`) fails the 11 case.+ with pytest.raises(ValueError) as info:+ parse_suite_yaml(suite(n))+ message = str(info.value)+ assert all(f"'{k}'" in message for k in _KEYS[:min(n, 10)])+ if n <= 10:+ assert "more" not in message+ else:+ assert "'k10'" not in message+ assert "and 1 more" in message++[email protected]("suite", [_top_level, _entry_level], ids=["top-level", "entry"])+def test_control_ten_or_fewer_keys_are_all_named(suite) -> None:+ with pytest.raises(ValueError) as info:+ parse_suite_yaml(suite(10))+ message = str(info.value)+ assert all(f"'{k}'" in message for k in _KEYS[:10])+ assert "more" not in message