-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from neuro-ml/develop
v0.1.2
- Loading branch information
Showing
16 changed files
with
515 additions
and
154 deletions.
There are no files selected for viewing
This file contains 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,38 @@ | ||
name: Release | ||
|
||
on: | ||
release: | ||
types: [ released ] | ||
|
||
env: | ||
MODULE_NAME: deep-pipe | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.9 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.9 | ||
|
||
- id: get_version | ||
name: Get the release version | ||
uses: battila7/get-version-action@v2 | ||
|
||
- name: Check the version and build the package | ||
run: | | ||
RELEASE=${{ steps.get_version.outputs.version-without-v }} | ||
VERSION=$(python -c "from pathlib import Path; import runpy; folder, = {d.parent for d in Path().resolve().glob('*/__init__.py')}; print(runpy.run_path(folder / '__init__.py')['__version__'])") | ||
MATCH=$(pip index versions $MODULE_NAME | grep "Available versions:" | grep $VERSION) || echo | ||
echo $MATCH | ||
if [ "$GITHUB_BASE_REF" = "master" ] && [ "$MATCH" != "" ]; then echo "Version $VERSION already present" && exit 1; fi | ||
if [ "$VERSION" != "$RELEASE" ]; then echo "$VERSION vs $RELEASE" && exit 1; fi | ||
python setup.py sdist | ||
- name: Publish to PyPi | ||
uses: pypa/gh-action-pypi-publish@master | ||
with: | ||
password: ${{ secrets.PYPI_API_TOKEN }} |
This file contains 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 +1 @@ | ||
__version__ = '0.1.1' | ||
__version__ = '0.1.2' |
This file contains 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 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 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 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 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 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,4 @@ | ||
This marker file declares that the package supports type checking. | ||
For details, you can refer to: | ||
- PEP561: https://www.python.org/dev/peps/pep-0561/ | ||
- mypy docs: https://mypy.readthedocs.io/en/stable/installed_packages.html |
This file contains 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,76 @@ | ||
import pytest | ||
|
||
import torch | ||
import numpy as np | ||
from torch import nn | ||
from dpipe.torch import train_step | ||
from dpipe.train import train | ||
|
||
|
||
@pytest.mark.parametrize('batch_size', [4, 16, 64]) | ||
def test_train(batch_size): | ||
net1 = nn.Sequential( | ||
nn.Conv2d(3, 4, kernel_size=3, padding=1), | ||
nn.LayerNorm([28, 28]), | ||
nn.GELU(), | ||
nn.Conv2d(4, 8, kernel_size=3, padding=1), | ||
nn.LayerNorm([28, 28]), | ||
nn.GELU(), | ||
nn.Conv2d(8, 16, kernel_size=3, padding=1), | ||
nn.LayerNorm([28, 28]), | ||
nn.GELU(), | ||
) | ||
net2 = nn.Sequential( | ||
nn.Conv2d(3, 4, kernel_size=3, padding=1), | ||
nn.LayerNorm([28, 28]), | ||
nn.GELU(), | ||
nn.Conv2d(4, 8, kernel_size=3, padding=1), | ||
nn.LayerNorm([28, 28]), | ||
nn.GELU(), | ||
nn.Conv2d(8, 16, kernel_size=3, padding=1), | ||
nn.LayerNorm([28, 28]), | ||
nn.GELU(), | ||
) | ||
net2.load_state_dict(net1.state_dict()) | ||
|
||
opt1 = torch.optim.SGD(net1.parameters(), lr=3e-4) | ||
opt2 = torch.optim.SGD(net2.parameters(), lr=3e-4) | ||
|
||
n_epochs = 10 | ||
n_batches = 10 | ||
|
||
data = np.random.randn(n_batches, batch_size, 3, 28, 28).astype(np.float32) | ||
|
||
def batch_iter1(): | ||
for x in data: | ||
yield x, 0 | ||
|
||
def batch_iter2(): | ||
for x in data: | ||
for batch_el in x: | ||
yield batch_el[None], 0 | ||
|
||
def criterion(x, y): | ||
return x.mean() | ||
|
||
train( | ||
train_step, | ||
batch_iter1, | ||
n_epochs=n_epochs, | ||
architecture=net1, | ||
optimizer=opt1, | ||
criterion=criterion, | ||
) | ||
|
||
train( | ||
train_step, | ||
batch_iter2, | ||
n_epochs=n_epochs, | ||
architecture=net2, | ||
optimizer=opt2, | ||
criterion=criterion, | ||
gradient_accumulation_steps=batch_size, | ||
) | ||
|
||
for param1, param2 in zip(net1.parameters(), net2.parameters()): | ||
assert torch.allclose(param1, param2) |
This file contains 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
Oops, something went wrong.