Skip to content

Commit

Permalink
fix and setup python publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
caillonantoine committed May 30, 2023
1 parent 4932526 commit 5a42c50
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 28 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/python-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Upload Python Package

on:
push:
tags:
- "v*"

permissions:
contents: read

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel build
python -m pip install -r requirements.txt
- name: Build package
run: NN_TILDE_VERSION=${{ github.ref_name }} python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ src/tests
*libtorch
*DS_Store*
src/docs
*.ts
*.ts
dist/
*.egg-info*
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include requirements.txt
49 changes: 28 additions & 21 deletions python_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
from typing import Any, Callable, Optional, Sequence, Tuple, Union

import cached_conv as cc
import torch

TYPE_HASH = {bool: 0, int: 1, float: 2, str: 3, torch.Tensor: 4}
Expand Down Expand Up @@ -93,27 +94,33 @@ def register_method(
f"expected {test_buffer_size//out_ratio} "
f"got {y.shape[2]}"))

logging.info(f"Testing method {method_name} with mc.nn~ API")
x = torch.zeros(4, in_channels, test_buffer_size // in_ratio)
y = getattr(self, method_name)(x)

if len(y.shape) != 3:
raise ValueError(
("Output tensor must have exactly 3 dimensions, "
f"got {len(y.shape)}"))
if y.shape[0] != 4:
raise ValueError(f"Expecting 4 batch output, got {y.shape[0]}")
if y.shape[1] != out_channels:
raise ValueError((
f"Wrong number of output channels for method \"{method_name}\", "
f"expected {out_channels} got {y.shape[1]}"))
if y.shape[2] != test_buffer_size // out_ratio:
raise ValueError(
(f"Wrong output length for method \"{method_name}\", "
f"expected {test_buffer_size//out_ratio} "
f"got {y.shape[2]}"))
logging.info((f"Added method \"{method_name}\" "
f"tested with buffer size {test_buffer_size}"))
if cc.MAX_BATCH_SIZE > 1:
logging.info(f"Testing method {method_name} with mc.nn~ API")
x = torch.zeros(4, in_channels, test_buffer_size // in_ratio)
y = getattr(self, method_name)(x)

if len(y.shape) != 3:
raise ValueError(
("Output tensor must have exactly 3 dimensions, "
f"got {len(y.shape)}"))
if y.shape[0] != 4:
raise ValueError(
f"Expecting 4 batch output, got {y.shape[0]}")
if y.shape[1] != out_channels:
raise ValueError((
f"Wrong number of output channels for method \"{method_name}\", "
f"expected {out_channels} got {y.shape[1]}"))
if y.shape[2] != test_buffer_size // out_ratio:
raise ValueError(
(f"Wrong output length for method \"{method_name}\", "
f"expected {test_buffer_size//out_ratio} "
f"got {y.shape[2]}"))
logging.info((f"Added method \"{method_name}\" "
f"tested with buffer size {test_buffer_size}"))
else:
logging.info(
f"Skiping method {method_name} with mc.nn~ API as cc.MAX_BATCH_SIZE={cc.MAX_BATCH_SIZE}"
)
else:
logging.warn(f"Added method \"{method_name}\" without testing it.")

Expand Down
10 changes: 4 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import subprocess
import os

import setuptools

VERSION = os.environ["NN_TILDE_VERSION"]

with open("README.md", "r") as readme:
readme = readme.read()

Expand All @@ -10,11 +12,7 @@

setuptools.setup(
name="nn_tilde",
version=subprocess.check_output([
"git",
"describe",
"--abbrev=0",
]).strip().decode(),
version=VERSION,
author="Antoine CAILLON",
author_email="caillon@ircam.fr",
description="Set of tools to create nn_tilde compatible models.",
Expand Down

0 comments on commit 5a42c50

Please sign in to comment.