diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 00000000..1e8e5b2c --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,21 @@ +# pull requests + +1. make a branch + - if it relates to an existing issue + - go to the issue page and click *Create a branch* under *Development* + - if the default name is not very long, keep it; otherwise, make it shorter, but keep the issue number in the front + - otherwise pick a short but descriptive name, a few hyphen-separated-words +2. make your changes + - include unit tests + - update README if needed +3. make a pull request + - if it isn't ready for review yet, mark it as draft + - check if CI is passing + - if the change is big, try to keep the commit history clean using interactive rebase + - don't push more often than it's needed, we're running github actions on a free tier + - if there were any changes to the main branch, rebase on top of it + - explain the change + - provide short description; focus on things that were not mentioned in the relevant issue + - comment important sections of the code in *Files changed* tab + - when it's ready, add the relevant stakeholders as reviewers +4. after the comments are resolved and PR is approved, merge it using *Squash and merge* diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 00000000..39c0acbf --- /dev/null +++ b/.github/workflows/checks.yml @@ -0,0 +1,28 @@ +name: checks + +on: [push, pull_request] + +permissions: + actions: write + +jobs: + checks: + name: checks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: setup python + uses: actions/setup-python@v5 + with: + python-version: "3.10" + - name: dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -e . + - name: black + run: black --check . + - name: isort + run: isort --check . + - name: pytest + run: pytest \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..84fc89ad --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,11 @@ +repos: + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 23.12.1 + hooks: + - id: black + language_version: python3.10 + - repo: https://github.com/pycqa/isort + rev: 5.13.2 + hooks: + - id: isort + name: isort (python) \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 00000000..acbfa7ff --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,9 @@ +{ + "recommendations": [ + "ms-python.python", + "ms-python.vscode-pylance", + "ms-python.black-formatter", + "ms-python.isort", + "github.copilot", + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..934a143e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,10 @@ +{ + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter", + }, + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.organizeImports": "explicit" + }, + "python.analysis.typeCheckingMode": "basic", +} \ No newline at end of file diff --git a/README.md b/README.md index 68a28314..1325de3e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,17 @@ -# delphi -Delphi: Interpreting Small Language Models Across Time and Scale +# Delphi +Interpreting Small Language Models Across Time and Scale + +# setup +1. make python 3.10 virtual env in `.venv` +2. install dependencies `pip install -r requirements.txt` +3. install the project in editable state `pip install -e .` +4. run tests `pytest` + +# formatting +We're using black & isort to format the code. To make sure your changes adhere to the rules: + +1. follow setup instructions above +2. install pre-commit `pre-commit install` +3. install recommended vscode extensions + +When you save a file vscode should automatically format it. Otherwise, pre-commit will do that, but you will need to add the changes and commit again. diff --git a/notebooks/.gitkeep b/notebooks/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..65b457a4 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,12 @@ +torch==2.1.2 +datasets==2.16.1 +transformers==4.36.2 +tqdm==4.66.1 +ipywidgets==8.1.1 +nbformat==5.9.2 +pytest==7.4.4 +black==23.12.1 +jaxtyping==0.2.25 +beartype==0.16.4 +pre-commit==3.6.0 +isort==5.13.2 \ No newline at end of file diff --git a/scripts/.gitkeep b/scripts/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..d775e872 --- /dev/null +++ b/setup.py @@ -0,0 +1,9 @@ +from setuptools import find_packages, setup + + +setup( + name="delphi", + version="0.1", + packages=find_packages(where='src'), + package_dir={"": "src"} +) diff --git a/src/delphi/__init__.py b/src/delphi/__init__.py new file mode 100644 index 00000000..b9b115cf --- /dev/null +++ b/src/delphi/__init__.py @@ -0,0 +1,3 @@ +from beartype.claw import beartype_this_package # <-- hype comes + +beartype_this_package() # <-- hype goes diff --git a/src/delphi/dataset/__init__.py b/src/delphi/dataset/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/delphi/dummy.py b/src/delphi/dummy.py new file mode 100644 index 00000000..028ff372 --- /dev/null +++ b/src/delphi/dummy.py @@ -0,0 +1,12 @@ +import torch +from jaxtyping import Float, Int + +Type1 = Float[torch.Tensor, "dim"] +Type2 = Int[torch.Tensor, "batch dim"] + + +def dummy(arg: Type1 | Type2) -> Type1: + if isinstance(arg, Type1): + return arg + 1 + elif isinstance(arg, Type2): + return arg[0] - 0.1 diff --git a/src/delphi/eval/__init__.py b/src/delphi/eval/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/delphi/interp/__init__.py b/src/delphi/interp/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/delphi/train/__init__.py b/src/delphi/train/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_dummy.py b/tests/test_dummy.py new file mode 100644 index 00000000..88261b12 --- /dev/null +++ b/tests/test_dummy.py @@ -0,0 +1,15 @@ +import pytest +import torch +from beartype.roar import BeartypeCallHintViolation + +from delphi.dummy import dummy + + +def test_dummy(): + tensor1 = torch.tensor([1.0, 2.0, 3.0]) + tensor2 = torch.tensor([[1, 2, 3], [4, 5, 6]]) + assert torch.allclose(dummy(tensor1), torch.tensor([2.0, 3.0, 4.0])) + assert torch.allclose(dummy(tensor2), torch.tensor([0.9, 1.9, 2.9])) + tensor3 = torch.tensor([1, 2, 3]) + with pytest.raises(BeartypeCallHintViolation): + dummy(tensor3)