From 5446a2fa6fc938ab4fbb4a38ebafcd88f101f3cc Mon Sep 17 00:00:00 2001 From: Aakash Suresh Date: Tue, 17 Nov 2026 00:24:48 -0800 Subject: [PATCH] style: lint the train test files now that train/ is in scope #209 removed `train` from the ruff exclude list, and #205/#206 added these two test files while it was still excluded, so they had never been checked. Together on main they fail CI: train/tests/test_loss_world_size.py:26:33: RUF100 Unused `noqa` directive 2 files would be reformatted Each PR was green on its own; the combination was what nobody ran. Fixed with `ruff check --fix` and `ruff format` over train/tests/ only. Co-Authored-By: Claude Opus 5 --- train/tests/test_loss_fn_wiring.py | 8 ++++++-- train/tests/test_loss_world_size.py | 11 +++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/train/tests/test_loss_fn_wiring.py b/train/tests/test_loss_fn_wiring.py index 9dab708..43b558f 100644 --- a/train/tests/test_loss_fn_wiring.py +++ b/train/tests/test_loss_fn_wiring.py @@ -16,7 +16,9 @@ def grad_cache_calls_in_main(): tree = ast.parse(SOURCE.read_text()) main = next( - node for node in tree.body if isinstance(node, ast.FunctionDef) and node.name == "main" + node + for node in tree.body + if isinstance(node, ast.FunctionDef) and node.name == "main" ) return [ node @@ -37,7 +39,9 @@ def test_every_grad_cache_call_passes_the_selected_loss(): call.lineno for call in grad_cache_calls_in_main() if not any( - kw.arg == "loss_fn" and isinstance(kw.value, ast.Name) and kw.value.id == "active_loss_fn" + kw.arg == "loss_fn" + and isinstance(kw.value, ast.Name) + and kw.value.id == "active_loss_fn" for kw in call.keywords ) ] diff --git a/train/tests/test_loss_world_size.py b/train/tests/test_loss_world_size.py index 7f5e01f..58fa04b 100644 --- a/train/tests/test_loss_world_size.py +++ b/train/tests/test_loss_world_size.py @@ -23,7 +23,7 @@ TRAIN_DIR = str(Path(__file__).resolve().parent.parent) sys.path.insert(0, TRAIN_DIR) -import train_contrastors as tc # noqa: E402 +import train_contrastors as tc WORLD = 2 QUERIES_PER_RANK = 4 @@ -79,8 +79,8 @@ def _worker(rank, port, case, out_dir): loss_fn, hard_negatives = CASES[case] q, d = global_batch(hard_negatives) per_doc = QUERIES_PER_RANK * (1 + hard_negatives) - q = q[rank * QUERIES_PER_RANK:(rank + 1) * QUERIES_PER_RANK] - d = d[rank * per_doc:(rank + 1) * per_doc] + q = q[rank * QUERIES_PER_RANK : (rank + 1) * QUERIES_PER_RANK] + d = d[rank * per_doc : (rank + 1) * per_doc] model = DDP(Tower(), broadcast_buffers=False) scale = make_logit_scale() @@ -107,7 +107,10 @@ def free_port(): @pytest.mark.parametrize("case", list(CASES)) def test_data_parallel_grads_match_global_batch(case, tmp_path): mp.start_processes( - _worker, args=(free_port(), case, str(tmp_path)), nprocs=WORLD, start_method="spawn" + _worker, + args=(free_port(), case, str(tmp_path)), + nprocs=WORLD, + start_method="spawn", ) loss_fn, hard_negatives = CASES[case]