-
Notifications
You must be signed in to change notification settings - Fork 0
Add lightweight tests and CI automation #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
emredeveloper
merged 2 commits into
main
from
codex/add-unit-tests-and-ci-configuration
Oct 19, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main ] | ||
| pull_request: | ||
|
|
||
| jobs: | ||
| tests: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: '3.10' | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install torch --index-url https://download.pytorch.org/whl/cpu | ||
| pip install numpy pandas scikit-learn | ||
| pip install -r requirements-dev.txt | ||
|
|
||
| - name: Ruff (tests only) | ||
| run: ruff check tests | ||
|
|
||
| - name: Black (tests only) | ||
| run: black --check tests | ||
|
|
||
| - name: Run tests | ||
| run: pytest | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [pytest] | ||
| testpaths = tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| # Development and Training Utilities | ||
| jupyter>=1.0.0 | ||
| notebook>=6.5.0 | ||
| fairscale>=0.4.0 | ||
| deepspeed>=0.9.0 | ||
| # Optional development dependencies | ||
| pytest>=7.4.0 | ||
| black>=23.9.0 | ||
| ruff>=0.1.9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import importlib.util | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| torch = pytest.importorskip("torch") | ||
|
|
||
|
|
||
| def load_rope_module(unique_name: str): | ||
| base_dir = Path(__file__).resolve().parents[1] | ||
| module_path = base_dir / "Architecture" / "partial-rope-full-rope.py" | ||
| spec = importlib.util.spec_from_file_location(unique_name, module_path) | ||
| module = importlib.util.module_from_spec(spec) | ||
| assert spec.loader is not None | ||
| spec.loader.exec_module(module) | ||
| return module | ||
|
|
||
|
|
||
| def test_partial_rope_preserves_non_rotary_dimensions(): | ||
| module = load_rope_module("rope_partial_module") | ||
| dim = 12 | ||
| partial_factor = 0.5 | ||
| rope = module.PartialRoPE(dim=dim, partial_rotary_factor=partial_factor) | ||
|
|
||
| torch.manual_seed(0) | ||
| q = torch.randn(1, 2, 3, dim) | ||
| k = torch.randn(1, 2, 3, dim) | ||
|
|
||
| q_embed, k_embed = rope(q.clone(), k.clone()) | ||
|
|
||
| assert q_embed.shape == q.shape | ||
| assert k_embed.shape == k.shape | ||
|
|
||
| rotary_dim = int(dim * partial_factor) | ||
| assert torch.allclose(q_embed[..., rotary_dim:], q[..., rotary_dim:]) | ||
| assert torch.allclose(k_embed[..., rotary_dim:], k[..., rotary_dim:]) | ||
|
|
||
|
|
||
| def test_attention_with_rope_output_shape(): | ||
| module = load_rope_module("rope_attention_module") | ||
| dim = 16 | ||
| num_heads = 4 | ||
| head_dim = dim // num_heads | ||
| rope = module.FullRoPE(dim=head_dim) | ||
| attention = module.AttentionWithRoPE(dim=dim, num_heads=num_heads, rope_module=rope) | ||
|
|
||
| torch.manual_seed(1) | ||
| dummy_input = torch.randn(2, 5, dim) | ||
|
|
||
| output = attention(dummy_input) | ||
|
|
||
| assert output.shape == dummy_input.shape | ||
| assert torch.isfinite(output).all() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import importlib.util | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| import numpy as np | ||
| import pandas as pd | ||
| import pytest | ||
|
|
||
| torch = pytest.importorskip("torch") | ||
|
|
||
|
|
||
| def load_time_series_module(unique_name: str): | ||
| base_dir = Path(__file__).resolve().parents[1] | ||
| module_path = base_dir / "Time series - Transformers" / "train.py" | ||
| spec = importlib.util.spec_from_file_location(unique_name, module_path) | ||
| module = importlib.util.module_from_spec(spec) | ||
| assert spec.loader is not None | ||
| spec.loader.exec_module(module) | ||
| return module | ||
|
|
||
|
|
||
| def test_time_series_transformer_forward_output_shape(): | ||
| module = load_time_series_module("time_series_train_forward") | ||
| model = module.TimeSeriesTransformer( | ||
| input_dim=3, d_model=12, n_heads=3, num_layers=1 | ||
| ) | ||
|
|
||
| dummy_batch = torch.randn(2, 5, 3) | ||
| output = model(dummy_batch) | ||
|
|
||
| assert output.shape == (2, 1) | ||
| assert torch.isfinite(output).all() | ||
|
|
||
|
|
||
| def test_train_creates_model_artifact(tmp_path, monkeypatch): | ||
| module = load_time_series_module("time_series_train_exec") | ||
|
|
||
| data = pd.DataFrame({"value": np.linspace(0, 1, 40)}) | ||
| data_path = tmp_path / "synthetic.csv" | ||
| data.to_csv(data_path, index=False) | ||
|
|
||
| model_path = tmp_path / "model.pth" | ||
|
|
||
| monkeypatch.setattr( | ||
| sys, | ||
| "argv", | ||
| [ | ||
| "train.py", | ||
| "--data", | ||
| str(data_path), | ||
| "--seq_length", | ||
| "5", | ||
| "--batch_size", | ||
| "4", | ||
| "--epochs", | ||
| "1", | ||
| "--lr", | ||
| "0.01", | ||
| "--model_path", | ||
| str(model_path), | ||
| ], | ||
| ) | ||
|
|
||
| module.train() | ||
|
|
||
| assert model_path.exists() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The workflow only installs torch, numpy, pandas, scikit‑learn and the dev tools, but the added tests import modules such as
Architecture/partial-rope-full-rope.py, which executesfrom transformers import AutoTokenizerand other dependencies that live inrequirements.txt. Because those packages aren’t installed here,pytestwill raiseModuleNotFoundErrorbefore any test runs, causing the CI job to fail deterministically. Install the regular project requirements (or otherwise skip the tests when optional dependencies are missing) before executing linting and pytest.Useful? React with 👍 / 👎.