Skip to content

Commit

Permalink
fix(torch): update torch.meshgrid; update CI (#12)
Browse files Browse the repository at this point in the history
* fix(torch): update torch.meshgrid; update CI

* fix(ci): no cache pip

* fix(ci): correct install
  • Loading branch information
kengz authored Jul 4, 2022
1 parent 1c4a444 commit be00f9f
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 51 deletions.
37 changes: 13 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:

steps:
- name: Check out Git repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.9

- uses: liskin/gh-problem-matcher-wrap@v1
with:
Expand All @@ -40,38 +40,27 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Cache Conda
uses: actions/cache@v2
with:
path: /usr/share/miniconda/envs/torcharc
key: ${{ runner.os }}-conda-${{ hashFiles('environment.yml') }}
restore-keys: |
${{ runner.os }}-conda-
- name: Setup Conda dependencies
uses: conda-incubator/setup-miniconda@v2
- name: Set up Python
uses: actions/setup-python@v4
with:
activate-environment: torcharc
environment-file: environment.yml
python-version: 3.8
auto-activate-base: false
python-version: 3.9

- name: Conda info
shell: bash -l {0}
- name: Install repo
run: |
conda info
conda list
pip install torch
pip install -e .
- uses: liskin/gh-problem-matcher-wrap@v1
with:
action: add
linters: pytest

- name: Run tests
shell: bash -l {0}
run: python setup.py test | tee pytest-coverage.txt
run: |
pip install wheel
python setup.py test | tee pytest-coverage.txt
- name: Post coverage to PR comment
uses: coroo/[email protected]
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Publish to PyPI

on:
push:
branches: [main]

jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Install repo
run: pip install -e .

- name: Build a binary wheel
run: |
pip install wheel
python setup.py bdist_wheel
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/tag-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Bump version and push tag
id: tag_version
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tag_prefix: ''
tag_prefix: ""

- name: Create a GitHub release
uses: actions/create-release@v1
Expand Down
2 changes: 1 addition & 1 deletion bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ echo "--- Installing Conda environment ---"
if conda env list | grep "^torcharc " >/dev/null; then
echo "conda env torcharc is already installed"
else
conda create -n torcharc python=3.8.2 -y
conda create -n torcharc python=3.9.0 -y
# Install ipykernel
conda activate torcharc
conda install ipykernel -y
Expand Down
15 changes: 0 additions & 15 deletions environment.yml

This file was deleted.

6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
'--log-level=INFO',
'--log-cli-level=INFO',
'--log-file-level=INFO',
'--no-flaky-report',
'--timeout=300',
'--cov=torcharc',
'test',
Expand All @@ -32,7 +31,7 @@ def run_tests(self):

setup(
name='torcharc',
version='1.2.0',
version='1.2.1',
description='Build PyTorch networks by specifying architectures.',
long_description='https://github.com/kengz/torcharc',
keywords='torcharc',
Expand All @@ -53,8 +52,7 @@ def run_tests(self):
tests_require=[
'autopep8==1.5.3',
'flake8==3.8.3',
'flaky==3.6.1',
'pytest==5.4.1',
'pytest',
'pytest-cov==2.8.1',
'pytest-timeout==1.3.4',
],
Expand Down
3 changes: 1 addition & 2 deletions test/module/perceiver_io/test_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
def test_text_preprocessor(batch, vocab_size, embed_dim, max_seq_len):
x = torch.randint(vocab_size, (batch, max_seq_len))
module = preprocessor.TextPreprocessor(vocab_size, embed_dim, max_seq_len)
assert embed_dim == module.output_dim
out = module(x)
assert [max_seq_len, embed_dim] == module.out_shape
assert list(out.shape) == [batch, *module.out_shape]
Expand All @@ -26,7 +25,7 @@ def test_text_preprocessor(batch, vocab_size, embed_dim, max_seq_len):
[64, 64, 64, 3] # volume
])
@pytest.mark.parametrize('num_freq_bands', [32])
def test_text_preprocessor(batch, in_shape, num_freq_bands):
def test_fourier_preprocessor(batch, in_shape, num_freq_bands):
x = torch.rand(batch, *in_shape)
max_reso = [2 * r for r in in_shape[:-1]] # max resolution twice the input size
module = preprocessor.FourierPreprocessor(in_shape, num_freq_bands, max_reso)
Expand Down
1 change: 0 additions & 1 deletion test/module/test_merge.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from torcharc import net_util
from torcharc.module.merge import ConcatMerge, FiLMMerge, Merge
import pytest
import torch
Expand Down
1 change: 0 additions & 1 deletion torcharc/module/perceiver_io/perceiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from torcharc.module.perceiver_io import encoder, decoder, postprocessor, preprocessor
from torcharc.module.perceiver_io.attention import SpreadSequential
from torcharc.net_util import build_component
from typing import Union
import pydash as ps


Expand Down
2 changes: 1 addition & 1 deletion torcharc/module/perceiver_io/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(self, in_shape: list, num_freq_bands: int, max_reso: list = None, c
def build_positions(self, start: float = -1.0, end: float = 1.0):
'''Build spatial coordinates as a meshgrid, i.e. coordinates laid out such that values along the channel is a point in coordinate, e.g. shape = (x, y, 2)'''
x_y = [torch.linspace(start, end, steps=s) for s in self.spatial_shape]
return torch.stack(torch.meshgrid(*x_y), dim=len(self.spatial_shape))
return torch.stack(torch.meshgrid(*x_y, indexing='xy'), dim=len(self.spatial_shape))

def build_pos_encoding(self, pos: torch.Tensor, max_reso: list = None) -> torch.Tensor:
'''
Expand Down

0 comments on commit be00f9f

Please sign in to comment.