Skip to content

Commit a711efe

Browse files
authored
Merge pull request #37 from chanind/pypi-package
feat: pypi packaging and auto-release with semantic release
2 parents 43421f5 + 0ff8888 commit a711efe

27 files changed

+298
-26
lines changed

.github/workflows/build.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
python-version: ["3.10", "3.11", "3.12"]
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
- name: Cache Huggingface assets
25+
uses: actions/cache@v4
26+
with:
27+
key: huggingface-0-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}
28+
path: ~/.cache/huggingface
29+
restore-keys: |
30+
huggingface-0-${{ runner.os }}-${{ matrix.python-version }}-
31+
- name: Load cached Poetry installation
32+
id: cached-poetry
33+
uses: actions/cache@v4
34+
with:
35+
path: ~/.local # the path depends on the OS
36+
key: poetry-${{ runner.os }}-${{ matrix.python-version }}-1 # increment to reset cache
37+
- name: Install Poetry
38+
if: steps.cached-poetry.outputs.cache-hit != 'true'
39+
uses: snok/install-poetry@v1
40+
with:
41+
virtualenvs-create: true
42+
virtualenvs-in-project: true
43+
installer-parallel: true
44+
- name: Load cached venv
45+
id: cached-poetry-dependencies
46+
uses: actions/cache@v4
47+
with:
48+
path: .venv
49+
key: venv-0-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}
50+
restore-keys: |
51+
venv-0-${{ runner.os }}-${{ matrix.python-version }}-
52+
- name: Install dependencies
53+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
54+
run: poetry install --no-interaction
55+
- name: Run Unit Tests
56+
run: poetry run pytest tests/unit
57+
- name: Build package
58+
run: poetry build
59+
60+
release:
61+
needs: build
62+
permissions:
63+
contents: write
64+
id-token: write
65+
# https://github.community/t/how-do-i-specify-job-dependency-running-in-another-workflow/16482
66+
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, 'chore(release):')
67+
runs-on: ubuntu-latest
68+
concurrency: release
69+
environment:
70+
name: pypi
71+
steps:
72+
- uses: actions/checkout@v4
73+
with:
74+
fetch-depth: 0
75+
- uses: actions/setup-python@v5
76+
with:
77+
python-version: "3.11"
78+
- name: Semantic Release
79+
id: release
80+
uses: python-semantic-release/[email protected]
81+
with:
82+
github_token: ${{ secrets.GITHUB_TOKEN }}
83+
- name: Publish package distributions to PyPI
84+
uses: pypa/gh-action-pypi-publish@release/v1
85+
if: steps.release.outputs.released == 'true'
86+
- name: Publish package distributions to GitHub Releases
87+
uses: python-semantic-release/upload-to-gh-release@main
88+
if: steps.release.outputs.released == 'true'
89+
with:
90+
github_token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ ipython_config.py
9999
# This is especially recommended for binary packages to ensure reproducibility, and is more
100100
# commonly ignored for libraries.
101101
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102-
#poetry.lock
102+
poetry.lock
103103

104104
# pdm
105105
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@ Some dictionaries trained using this repository (and associated training checkpo
88

99
Navigate to the to the location where you would like to clone this repo, clone and enter the repo, and install the requirements.
1010
```bash
11-
git clone https://github.com/saprmarks/dictionary_learning
12-
cd dictionary_learning
13-
pip install -r requirements.txt
11+
pip install dictionary-learning
1412
```
1513

16-
To use `dictionary_learning`, include it as a subdirectory in some project's directory and import it; see the examples below.
17-
1814
We also provide a [demonstration](https://github.com/adamkarvonen/dictionary_learning_demo), which trains and evaluates 2 SAEs in ~30 minutes before plotting the results.
1915

2016
# Using trained dictionaries

__init__.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

dictionary_learning/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
__version__ = "0.1.0"
2+
3+
from .dictionary import AutoEncoder, GatedAutoEncoder, JumpReluAutoEncoder
4+
from .buffer import ActivationBuffer
5+
6+
__all__ = ["AutoEncoder", "GatedAutoEncoder", "JumpReluAutoEncoder", "ActivationBuffer"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)