Skip to content

Commit

Permalink
Merge branch 'main' of github.com:FelixBenning/pyrfd
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixBenning committed Jan 21, 2025
2 parents 18c58c5 + 50af6e4 commit 9b9ecfa
Show file tree
Hide file tree
Showing 88 changed files with 12,092 additions and 2,195 deletions.
5 changes: 4 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[flake8]
max-line-length = 120
max-line-length = 120

# E266: too many leading '#' for block commment
extend-ignore = E266
123 changes: 123 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI

on: push

jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- name: Install library
run: poetry install --no-interaction

- name: Build distribution 📦
run: poetry build

- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/pyrfd # Replace <package-name> with your PyPI project name
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
needs:
- publish-to-pypi
runs-on: ubuntu-latest

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- build
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/pyrfd

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
15 changes: 15 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,18 @@ jobs:
poetry run pylint pyrfd
poetry run flake8 pyrfd
poetry run black --check pyrfd
- name: Run Tests
run: poetry run pytest --cov-report xml --cov-report html --cov=pyrfd tests/


- name: Upload results to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: Upload HTML results
uses: actions/upload-artifact@v4
with:
name: Test Coverage Report ${{matrix.python-version}}
path: htmlcov
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,17 @@ cython_debug/

# Apple junk
.DS_Store


# Caches
# cache/*
logs/*
!logs/MNIST_CNN7_b=1024
!logs/MNIST_CNN7_b=128
!logs/MNIST_AlgoPerf_b=128
!logs/FashionMNIST_CNN5_b=128
!logs/MNIST_CNN3_b=128
data/*
slurm-*
wandb
plot/*.pdf
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debugger: Benchmarking Module",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/benchmarking/classification/__main__.py",
"args": "${command:pickArgs}"
},
{
"name": "debug pyrfd",
"type": "debugpy",
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"python.testing.pytestArgs": [
"."
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
Expand Down
32 changes: 26 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# pyrfd

Pytorch implementation of RFD
[![PyPI version](https://badge.fury.io/py/pyrfd.svg)](https://badge.fury.io/py/pyrfd)
[![codecov](https://codecov.io/gh/FelixBenning/pyrfd/graph/badge.svg?token=DaSPgLnZRc)](https://codecov.io/gh/FelixBenning/pyrfd)

Pytorch implementation of RFD (see [arXiv](https://arxiv.org/abs/2305.01377))

## Covariance model

Expand All @@ -22,8 +25,7 @@ pytorch optimizer interface. The end result can be used like `torch.optim.Adam`
## Example usage

```python
from mnistSimpleCNN.models.modelM3 import ModelM3
# cf. mnistSimpleCNN directory (example model)
from benchmaking.classification.mnist.models.cnn3 import CNN3

import torch
import torchvision as tv
Expand All @@ -32,7 +34,7 @@ from pyrfd import RFD, SquaredExponential

cov_model = SquaredExponential()
cov_model.auto_fit(
model_factory=ModelM3,
model_factory=CNN3,
loss=torch.nn.functional.nll_loss,
data= tv.datasets.MNIST(
root="mnistSimpleCNN/data",
Expand All @@ -43,7 +45,25 @@ cov_model.auto_fit(
# should be unique for (models, data, loss)
)
rfd = RFD(
ModelM3().parameters(),
CNN3().parameters(),
covariance_model=cov_model
)
```
```

## How to cite


```bibtex
@inproceedings{benningRandomFunctionDescent2024,
title = {Random {{Function Descent}}},
booktitle = {Advances in {{Neural Information Processing Systems}}},
author = {Benning, Felix and D{\"o}ring, Leif},
year = {2024},
month = dec,
volume = {37},
primaryclass = {cs, math, stat},
publisher = {Curran Associates, Inc.},
address = {Vancouver, Canada},
}
```

File renamed without changes.
6 changes: 6 additions & 0 deletions benchmarking/classification/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
""" Classification examples. """

from .classifier import Classifier
from . import mnist

__all__ = ["Classifier", "mnist"]
Loading

0 comments on commit 9b9ecfa

Please sign in to comment.