From b2fd5c3da27523f3d767819ff673ef2d2c3b1672 Mon Sep 17 00:00:00 2001 From: Yuxuan Hu Date: Fri, 5 Sep 2025 09:50:58 -0700 Subject: [PATCH 1/8] move the test that doesn't run on CI to a new folder --- tests/{unit_tests => unit_tests_noci}/test_replay_buffer.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{unit_tests => unit_tests_noci}/test_replay_buffer.py (100%) diff --git a/tests/unit_tests/test_replay_buffer.py b/tests/unit_tests_noci/test_replay_buffer.py similarity index 100% rename from tests/unit_tests/test_replay_buffer.py rename to tests/unit_tests_noci/test_replay_buffer.py From 1bfe2ab2e5fd77fcd6b02cb20d3dcc405bba37f8 Mon Sep 17 00:00:00 2001 From: Yuxuan Hu Date: Fri, 5 Sep 2025 09:54:41 -0700 Subject: [PATCH 2/8] Revert "move the test that doesn't run on CI to a new folder" This reverts commit b2fd5c3da27523f3d767819ff673ef2d2c3b1672. --- tests/{unit_tests_noci => unit_tests}/test_replay_buffer.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{unit_tests_noci => unit_tests}/test_replay_buffer.py (100%) diff --git a/tests/unit_tests_noci/test_replay_buffer.py b/tests/unit_tests/test_replay_buffer.py similarity index 100% rename from tests/unit_tests_noci/test_replay_buffer.py rename to tests/unit_tests/test_replay_buffer.py From eb7cebaaacc3d58980a4c559ce11981bfd1fcec6 Mon Sep 17 00:00:00 2001 From: Yuxuan Hu Date: Fri, 5 Sep 2025 09:56:13 -0700 Subject: [PATCH 3/8] move the right file... --- .../actors => unit_tests_noci}/test_reference_actor.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{unit_tests/actors => unit_tests_noci}/test_reference_actor.py (100%) diff --git a/tests/unit_tests/actors/test_reference_actor.py b/tests/unit_tests_noci/test_reference_actor.py similarity index 100% rename from tests/unit_tests/actors/test_reference_actor.py rename to tests/unit_tests_noci/test_reference_actor.py From 278a2996a9b7c49dd87f2f3fab7053328d860d2e Mon Sep 17 00:00:00 2001 From: Yuxuan Hu Date: Mon, 8 Sep 2025 14:43:28 -0700 Subject: [PATCH 4/8] use pytest skipif --- .../test_reference_actor.py | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) rename tests/{unit_tests_noci => unit_tests}/test_reference_actor.py (71%) diff --git a/tests/unit_tests_noci/test_reference_actor.py b/tests/unit_tests/test_reference_actor.py similarity index 71% rename from tests/unit_tests_noci/test_reference_actor.py rename to tests/unit_tests/test_reference_actor.py index 9a8c8d35b..d0caf10de 100644 --- a/tests/unit_tests_noci/test_reference_actor.py +++ b/tests/unit_tests/test_reference_actor.py @@ -8,17 +8,32 @@ Tests for reference_actor.py - compute_logprobs function """ +import unittest + import pytest import torch -from forge.actors.reference_actor import compute_logprobs +def _module_not_found(): + try: + import forge.actors.reference_actor # noqa: F401 + + return False + except ModuleNotFoundError: + return True -class TestComputeLogprobs: + +class TestComputeLogprobs(unittest.TestCase): """Test the compute_logprobs utility function.""" + @pytest.mark.skipif( + _module_not_found(), + reason="Moduel not found error, likely due to missing dependencies on CI.", + ) def test_compute_logprobs_basic(self): """Test basic logprobs computation.""" + from forge.actors.reference_actor import compute_logprobs + batch_size = 1 seq_len = 5 vocab_size = 1000 @@ -36,8 +51,14 @@ def test_compute_logprobs_basic(self): assert result.shape == (batch_size, response_len) assert torch.all(result <= 0) # Log probabilities should be <= 0 + @pytest.mark.skipif( + _module_not_found(), + reason="Moduel not found error, likely due to missing dependencies on CI.", + ) def test_compute_logprobs_with_temperature(self): """Test logprobs computation with temperature scaling.""" + from forge.actors.reference_actor import compute_logprobs + batch_size = 1 seq_len = 5 vocab_size = 1000 @@ -55,8 +76,14 @@ def test_compute_logprobs_with_temperature(self): default_result = compute_logprobs(logits, input_ids) assert not torch.allclose(result, default_result) + @pytest.mark.skipif( + _module_not_found(), + reason="Moduel not found error, likely due to missing dependencies on CI.", + ) def test_compute_logprobs_single_token(self): """Test logprobs computation with single token response.""" + from forge.actors.reference_actor import compute_logprobs + batch_size = 1 seq_len = 5 vocab_size = 1000 @@ -70,8 +97,14 @@ def test_compute_logprobs_single_token(self): assert result.shape == (batch_size, response_len) assert result.numel() == 1 # Single element + @pytest.mark.skipif( + _module_not_found(), + reason="Moduel not found error, likely due to missing dependencies on CI.", + ) def test_compute_logprobs_empty_response(self): """Test logprobs computation with empty response.""" + from forge.actors.reference_actor import compute_logprobs + batch_size = 1 seq_len = 5 vocab_size = 1000 @@ -84,8 +117,14 @@ def test_compute_logprobs_empty_response(self): assert result.shape == (batch_size, response_len) + @pytest.mark.skipif( + _module_not_found(), + reason="Moduel not found error, likely due to missing dependencies on CI.", + ) def test_compute_logprobs_empty_prompt(self): """Test logprobs computation with empty prompt.""" + from forge.actors.reference_actor import compute_logprobs + batch_size = 1 vocab_size = 1000 prompt_len = 0 From 9303bfda45c6db72aeb40a409a783444f85d11bd Mon Sep 17 00:00:00 2001 From: Yuxuan Hu Date: Mon, 8 Sep 2025 14:47:40 -0700 Subject: [PATCH 5/8] catch all exceptions --- tests/unit_tests/test_reference_actor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/test_reference_actor.py b/tests/unit_tests/test_reference_actor.py index d0caf10de..58283df40 100644 --- a/tests/unit_tests/test_reference_actor.py +++ b/tests/unit_tests/test_reference_actor.py @@ -19,7 +19,7 @@ def _module_not_found(): import forge.actors.reference_actor # noqa: F401 return False - except ModuleNotFoundError: + except Exception: return True From b7913d770b3269a78c79640778c443a6e3677bf8 Mon Sep 17 00:00:00 2001 From: Yuxuan Hu Date: Mon, 8 Sep 2025 15:02:45 -0700 Subject: [PATCH 6/8] change function name --- tests/unit_tests/test_reference_actor.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/unit_tests/test_reference_actor.py b/tests/unit_tests/test_reference_actor.py index 58283df40..d2e18deec 100644 --- a/tests/unit_tests/test_reference_actor.py +++ b/tests/unit_tests/test_reference_actor.py @@ -14,7 +14,7 @@ import torch -def _module_not_found(): +def _import_error(): try: import forge.actors.reference_actor # noqa: F401 @@ -27,7 +27,7 @@ class TestComputeLogprobs(unittest.TestCase): """Test the compute_logprobs utility function.""" @pytest.mark.skipif( - _module_not_found(), + _import_error, reason="Moduel not found error, likely due to missing dependencies on CI.", ) def test_compute_logprobs_basic(self): @@ -52,7 +52,7 @@ def test_compute_logprobs_basic(self): assert torch.all(result <= 0) # Log probabilities should be <= 0 @pytest.mark.skipif( - _module_not_found(), + _import_error, reason="Moduel not found error, likely due to missing dependencies on CI.", ) def test_compute_logprobs_with_temperature(self): @@ -77,7 +77,7 @@ def test_compute_logprobs_with_temperature(self): assert not torch.allclose(result, default_result) @pytest.mark.skipif( - _module_not_found(), + _import_error, reason="Moduel not found error, likely due to missing dependencies on CI.", ) def test_compute_logprobs_single_token(self): @@ -98,7 +98,7 @@ def test_compute_logprobs_single_token(self): assert result.numel() == 1 # Single element @pytest.mark.skipif( - _module_not_found(), + _import_error, reason="Moduel not found error, likely due to missing dependencies on CI.", ) def test_compute_logprobs_empty_response(self): @@ -118,7 +118,7 @@ def test_compute_logprobs_empty_response(self): assert result.shape == (batch_size, response_len) @pytest.mark.skipif( - _module_not_found(), + _import_error, reason="Moduel not found error, likely due to missing dependencies on CI.", ) def test_compute_logprobs_empty_prompt(self): From 8be4e06ee05222d729daf9c5bbc25f26167afeef Mon Sep 17 00:00:00 2001 From: Yuxuan Hu Date: Mon, 8 Sep 2025 15:04:00 -0700 Subject: [PATCH 7/8] fix --- tests/unit_tests/test_reference_actor.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/unit_tests/test_reference_actor.py b/tests/unit_tests/test_reference_actor.py index d2e18deec..7647ef93c 100644 --- a/tests/unit_tests/test_reference_actor.py +++ b/tests/unit_tests/test_reference_actor.py @@ -27,7 +27,7 @@ class TestComputeLogprobs(unittest.TestCase): """Test the compute_logprobs utility function.""" @pytest.mark.skipif( - _import_error, + _import_error(), reason="Moduel not found error, likely due to missing dependencies on CI.", ) def test_compute_logprobs_basic(self): @@ -52,7 +52,7 @@ def test_compute_logprobs_basic(self): assert torch.all(result <= 0) # Log probabilities should be <= 0 @pytest.mark.skipif( - _import_error, + _import_error(), reason="Moduel not found error, likely due to missing dependencies on CI.", ) def test_compute_logprobs_with_temperature(self): @@ -77,7 +77,7 @@ def test_compute_logprobs_with_temperature(self): assert not torch.allclose(result, default_result) @pytest.mark.skipif( - _import_error, + _import_error(), reason="Moduel not found error, likely due to missing dependencies on CI.", ) def test_compute_logprobs_single_token(self): @@ -98,7 +98,7 @@ def test_compute_logprobs_single_token(self): assert result.numel() == 1 # Single element @pytest.mark.skipif( - _import_error, + _import_error(), reason="Moduel not found error, likely due to missing dependencies on CI.", ) def test_compute_logprobs_empty_response(self): @@ -118,7 +118,7 @@ def test_compute_logprobs_empty_response(self): assert result.shape == (batch_size, response_len) @pytest.mark.skipif( - _import_error, + _import_error(), reason="Moduel not found error, likely due to missing dependencies on CI.", ) def test_compute_logprobs_empty_prompt(self): From e0ecc7dc3cbc490d7d67cf086800596f73657537 Mon Sep 17 00:00:00 2001 From: Yuxuan Hu Date: Mon, 8 Sep 2025 15:05:07 -0700 Subject: [PATCH 8/8] typo --- tests/unit_tests/test_reference_actor.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/unit_tests/test_reference_actor.py b/tests/unit_tests/test_reference_actor.py index 7647ef93c..403da7169 100644 --- a/tests/unit_tests/test_reference_actor.py +++ b/tests/unit_tests/test_reference_actor.py @@ -28,7 +28,7 @@ class TestComputeLogprobs(unittest.TestCase): @pytest.mark.skipif( _import_error(), - reason="Moduel not found error, likely due to missing dependencies on CI.", + reason="Import error, likely due to missing dependencies on CI.", ) def test_compute_logprobs_basic(self): """Test basic logprobs computation.""" @@ -53,7 +53,7 @@ def test_compute_logprobs_basic(self): @pytest.mark.skipif( _import_error(), - reason="Moduel not found error, likely due to missing dependencies on CI.", + reason="Import error, likely due to missing dependencies on CI.", ) def test_compute_logprobs_with_temperature(self): """Test logprobs computation with temperature scaling.""" @@ -78,7 +78,7 @@ def test_compute_logprobs_with_temperature(self): @pytest.mark.skipif( _import_error(), - reason="Moduel not found error, likely due to missing dependencies on CI.", + reason="Import error, likely due to missing dependencies on CI.", ) def test_compute_logprobs_single_token(self): """Test logprobs computation with single token response.""" @@ -99,7 +99,7 @@ def test_compute_logprobs_single_token(self): @pytest.mark.skipif( _import_error(), - reason="Moduel not found error, likely due to missing dependencies on CI.", + reason="Import error, likely due to missing dependencies on CI.", ) def test_compute_logprobs_empty_response(self): """Test logprobs computation with empty response.""" @@ -119,7 +119,7 @@ def test_compute_logprobs_empty_response(self): @pytest.mark.skipif( _import_error(), - reason="Moduel not found error, likely due to missing dependencies on CI.", + reason="Import error, likely due to missing dependencies on CI.", ) def test_compute_logprobs_empty_prompt(self): """Test logprobs computation with empty prompt."""