Skip to content

Commit

Permalink
Merge pull request #8 from GilesStrong/py37_compat
Browse files Browse the repository at this point in the history
Remove slots attr
  • Loading branch information
GilesStrong authored Jun 29, 2021
2 parents ca6d44c + 908cbe8 commit dd427f3
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 21 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
py_version: ['3.6', '3.7']
allow_failure: [false]
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: '3.6'
python-version: ${{matrix.py_version}}
architecture: 'x64'
- name: Install the library
run: |
Expand Down
4 changes: 2 additions & 2 deletions docs/callback.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@


<div class="output_markdown rendered_html output_subarea ">
<h2 id="AbsCallback" class="doc_header"><code>class</code> <code>AbsCallback</code><a href="https://github.com/GilesStrong/pytorch_inferno/tree/master/pytorch_inferno/callback.py#L18" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>AbsCallback</code>() :: <code>ABC</code></p>
<h2 id="AbsCallback" class="doc_header"><code>class</code> <code>AbsCallback</code><a href="https://github.com/GilesStrong/pytorch_inferno/tree/master/pytorch_inferno/callback.py#L17" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>AbsCallback</code>()</p>
</blockquote>
<p>Abstract callback passing though all action points and indicating where callbacks can affect the model.
See <a href="/pytorch_inferno/model_wrapper.html#ModelWrapper"><code>ModelWrapper</code></a> etc. to see where exactly these action points are called.</p>
Expand Down Expand Up @@ -262,7 +262,7 @@ <h2 id="PaperSystMod" class="doc_header"><code>class</code> <code>PaperSystMod</


<div class="output_markdown rendered_html output_subarea ">
<h2 id="GradClip" class="doc_header"><code>class</code> <code>GradClip</code><a href="https://github.com/GilesStrong/pytorch_inferno/tree/master/pytorch_inferno/callback.py#L148" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>GradClip</code>(<strong><code>clip</code></strong>:<code>float</code>, <strong><code>clip_norm</code></strong>:<code>bool</code>=<em><code>True</code></em>) :: <a href="/pytorch_inferno/callback.html#AbsCallback"><code>AbsCallback</code></a></p>
<h2 id="GradClip" class="doc_header"><code>class</code> <code>GradClip</code><a href="https://github.com/GilesStrong/pytorch_inferno/tree/master/pytorch_inferno/callback.py#L149" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>GradClip</code>(<strong><code>clip</code></strong>:<code>float</code>, <strong><code>clip_norm</code></strong>:<code>bool</code>=<em><code>True</code></em>) :: <a href="/pytorch_inferno/callback.html#AbsCallback"><code>AbsCallback</code></a></p>
</blockquote>
<p>Training callback implementing gradient clipping</p>

Expand Down
4 changes: 2 additions & 2 deletions docs/inferno_exact.html
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ <h2 id="AbsInferno" class="doc_header"><code>class</code> <code>AbsInferno</code


<div class="output_markdown rendered_html output_subarea ">
<h2 id="PaperInferno" class="doc_header"><code>class</code> <code>PaperInferno</code><a href="https://github.com/GilesStrong/pytorch_inferno/tree/master/pytorch_inferno/inferno.py#L108" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>PaperInferno</code>(<strong><code>float_r</code></strong>:<code>bool</code>, <strong><code>float_l</code></strong>:<code>bool</code>, <strong><code>l_init</code></strong>:<code>float</code>=<em><code>3</code></em>, <strong><code>b_true</code></strong>:<code>float</code>=<em><code>1000</code></em>, <strong><code>mu_true</code></strong>:<code>float</code>=<em><code>50</code></em>, <strong><code>n_shape_alphas</code></strong>:<code>int</code>=<em><code>0</code></em>, <strong><code>nonaux_b_norm</code></strong>:<code>bool</code>=<em><code>False</code></em>, <strong><code>shape_aux</code></strong>:<code>Optional</code>[<code>List</code>[<code>Distribution</code>]]=<em><code>None</code></em>, <strong><code>b_norm_aux</code></strong>:<code>Optional</code>[<code>List</code>[<code>Distribution</code>]]=<em><code>None</code></em>, <strong><code>s_norm_aux</code></strong>:<code>Optional</code>[<code>List</code>[<code>Distribution</code>]]=<em><code>None</code></em>) :: <a href="/pytorch_inferno/inferno_exact.html#AbsInferno"><code>AbsInferno</code></a></p>
<h2 id="PaperInferno" class="doc_header"><code>class</code> <code>PaperInferno</code><a href="https://github.com/GilesStrong/pytorch_inferno/tree/master/pytorch_inferno/inferno.py#L107" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>PaperInferno</code>(<strong><code>float_r</code></strong>:<code>bool</code>, <strong><code>float_l</code></strong>:<code>bool</code>, <strong><code>l_init</code></strong>:<code>float</code>=<em><code>3</code></em>, <strong><code>b_true</code></strong>:<code>float</code>=<em><code>1000</code></em>, <strong><code>mu_true</code></strong>:<code>float</code>=<em><code>50</code></em>, <strong><code>n_shape_alphas</code></strong>:<code>int</code>=<em><code>0</code></em>, <strong><code>nonaux_b_norm</code></strong>:<code>bool</code>=<em><code>False</code></em>, <strong><code>shape_aux</code></strong>:<code>Optional</code>[<code>List</code>[<code>Distribution</code>]]=<em><code>None</code></em>, <strong><code>b_norm_aux</code></strong>:<code>Optional</code>[<code>List</code>[<code>Distribution</code>]]=<em><code>None</code></em>, <strong><code>s_norm_aux</code></strong>:<code>Optional</code>[<code>List</code>[<code>Distribution</code>]]=<em><code>None</code></em>) :: <a href="/pytorch_inferno/inferno_exact.html#AbsInferno"><code>AbsInferno</code></a></p>
</blockquote>
<p>Inheriting class for dealing with INFERNO paper synthetic problem</p>

Expand Down Expand Up @@ -538,7 +538,7 @@ <h1 id="Results">Results<a class="anchor-link" href="#Results"> </a></h1>


<div class="output_markdown rendered_html output_subarea ">
<h2 id="InfernoPred" class="doc_header"><code>class</code> <code>InfernoPred</code><a href="https://github.com/GilesStrong/pytorch_inferno/tree/master/pytorch_inferno/inferno.py#L120" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>InfernoPred</code>() :: <a href="/pytorch_inferno/callback.html#PredHandler"><code>PredHandler</code></a></p>
<h2 id="InfernoPred" class="doc_header"><code>class</code> <code>InfernoPred</code><a href="https://github.com/GilesStrong/pytorch_inferno/tree/master/pytorch_inferno/inferno.py#L119" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>InfernoPred</code>() :: <a href="/pytorch_inferno/callback.html#PredHandler"><code>PredHandler</code></a></p>
</blockquote>
<p>Prediction handler for hard assignments</p>

Expand Down
6 changes: 3 additions & 3 deletions docs/inferno_interp.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">OrderedDict</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">abc</span> <span class="kn">import</span> <span class="n">abstractmethod</span>
<span class="kn">from</span> <span class="nn">abc</span> <span class="kn">import</span> <span class="n">abstractmethod</span><span class="p">,</span> <span class="n">ABCMeta</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Optional</span><span class="p">,</span> <span class="n">List</span>
<span class="kn">from</span> <span class="nn">fastcore.all</span> <span class="kn">import</span> <span class="n">store_attr</span><span class="p">,</span> <span class="n">delegates</span>

Expand Down Expand Up @@ -139,7 +139,7 @@ <h1 id="Loss">Loss<a class="anchor-link" href="#Loss"> </a></h1>


<div class="output_markdown rendered_html output_subarea ">
<h2 id="AbsApproxInferno" class="doc_header"><code>class</code> <code>AbsApproxInferno</code><a href="https://github.com/GilesStrong/pytorch_inferno/tree/master/pytorch_inferno/inferno.py#L131" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>AbsApproxInferno</code>(<strong><code>aug_alpha</code></strong>:<code>bool</code>=<em><code>False</code></em>, <strong><code>n_steps</code></strong>:<code>int</code>=<em><code>100</code></em>, <strong><code>lr</code></strong>:<code>float</code>=<em><code>0.1</code></em>, <strong><code>n_shape_alphas</code></strong>:<code>int</code>=<em><code>0</code></em>, <strong><code>s_shape_alpha</code></strong>:<code>bool</code>=<em><code>False</code></em>, <strong><code>b_shape_alpha</code></strong>:<code>bool</code>=<em><code>False</code></em>, <strong><code>nonaux_b_norm</code></strong>:<code>bool</code>=<em><code>False</code></em>, <strong><code>shape_aux</code></strong>:<code>Optional</code>[<code>List</code>[<code>Distribution</code>]]=<em><code>None</code></em>, <strong><code>b_norm_aux</code></strong>:<code>Optional</code>[<code>List</code>[<code>Distribution</code>]]=<em><code>None</code></em>, <strong><code>s_norm_aux</code></strong>:<code>Optional</code>[<code>List</code>[<code>Distribution</code>]]=<em><code>None</code></em>) :: <a href="/pytorch_inferno/inferno_exact.html#AbsInferno"><code>AbsInferno</code></a></p>
<h2 id="AbsApproxInferno" class="doc_header"><code>class</code> <code>AbsApproxInferno</code><a href="https://github.com/GilesStrong/pytorch_inferno/tree/master/pytorch_inferno/inferno.py#L130" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>AbsApproxInferno</code>(<strong><code>aug_alpha</code></strong>:<code>bool</code>=<em><code>False</code></em>, <strong><code>n_steps</code></strong>:<code>int</code>=<em><code>100</code></em>, <strong><code>lr</code></strong>:<code>float</code>=<em><code>0.1</code></em>, <strong><code>n_shape_alphas</code></strong>:<code>int</code>=<em><code>0</code></em>, <strong><code>s_shape_alpha</code></strong>:<code>bool</code>=<em><code>False</code></em>, <strong><code>b_shape_alpha</code></strong>:<code>bool</code>=<em><code>False</code></em>, <strong><code>nonaux_b_norm</code></strong>:<code>bool</code>=<em><code>False</code></em>, <strong><code>shape_aux</code></strong>:<code>Optional</code>[<code>List</code>[<code>Distribution</code>]]=<em><code>None</code></em>, <strong><code>b_norm_aux</code></strong>:<code>Optional</code>[<code>List</code>[<code>Distribution</code>]]=<em><code>None</code></em>, <strong><code>s_norm_aux</code></strong>:<code>Optional</code>[<code>List</code>[<code>Distribution</code>]]=<em><code>None</code></em>) :: <a href="/pytorch_inferno/inferno_exact.html#AbsInferno"><code>AbsInferno</code></a></p>
</blockquote>
<p>Attempted reproduction INFERNO following paper description implementations with nuisances being approximated by creating up/down shapes and interpolating
Includes option to randomise params per batch and converge to better values, which results in slightly better performance</p>
Expand Down Expand Up @@ -172,7 +172,7 @@ <h2 id="AbsApproxInferno" class="doc_header"><code>class</code> <code>AbsApproxI


<div class="output_markdown rendered_html output_subarea ">
<h2 id="ApproxPaperInferno" class="doc_header"><code>class</code> <code>ApproxPaperInferno</code><a href="https://github.com/GilesStrong/pytorch_inferno/tree/master/pytorch_inferno/inferno.py#L182" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>ApproxPaperInferno</code>(<strong><code>r_mods</code></strong>:<code>Optional</code>[<code>Tuple</code>[<code>float</code>, <code>float</code>]]=<em><code>(-0.2, 0.2)</code></em>, <strong><code>l_mods</code></strong>:<code>Optional</code>[<code>Tuple</code>[<code>float</code>, <code>float</code>]]=<em><code>(2.5, 3.5)</code></em>, <strong><code>l_init</code></strong>:<code>float</code>=<em><code>3</code></em>, <strong><code>b_true</code></strong>:<code>float</code>=<em><code>1000</code></em>, <strong><code>mu_true</code></strong>:<code>float</code>=<em><code>50</code></em>, <strong><code>aug_alpha</code></strong>:<code>bool</code>=<em><code>False</code></em>, <strong><code>n_steps</code></strong>:<code>int</code>=<em><code>100</code></em>, <strong><code>lr</code></strong>:<code>float</code>=<em><code>0.1</code></em>, <strong><code>n_shape_alphas</code></strong>:<code>int</code>=<em><code>0</code></em>, <strong><code>nonaux_b_norm</code></strong>:<code>bool</code>=<em><code>False</code></em>, <strong><code>shape_aux</code></strong>:<code>Optional</code>[<code>List</code>[<code>Distribution</code>]]=<em><code>None</code></em>, <strong><code>b_norm_aux</code></strong>:<code>Optional</code>[<code>List</code>[<code>Distribution</code>]]=<em><code>None</code></em>, <strong><code>s_norm_aux</code></strong>:<code>Optional</code>[<code>List</code>[<code>Distribution</code>]]=<em><code>None</code></em>) :: <a href="/pytorch_inferno/inferno_interp.html#AbsApproxInferno"><code>AbsApproxInferno</code></a></p>
<h2 id="ApproxPaperInferno" class="doc_header"><code>class</code> <code>ApproxPaperInferno</code><a href="https://github.com/GilesStrong/pytorch_inferno/tree/master/pytorch_inferno/inferno.py#L181" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>ApproxPaperInferno</code>(<strong><code>r_mods</code></strong>:<code>Optional</code>[<code>Tuple</code>[<code>float</code>, <code>float</code>]]=<em><code>(-0.2, 0.2)</code></em>, <strong><code>l_mods</code></strong>:<code>Optional</code>[<code>Tuple</code>[<code>float</code>, <code>float</code>]]=<em><code>(2.5, 3.5)</code></em>, <strong><code>l_init</code></strong>:<code>float</code>=<em><code>3</code></em>, <strong><code>b_true</code></strong>:<code>float</code>=<em><code>1000</code></em>, <strong><code>mu_true</code></strong>:<code>float</code>=<em><code>50</code></em>, <strong><code>aug_alpha</code></strong>:<code>bool</code>=<em><code>False</code></em>, <strong><code>n_steps</code></strong>:<code>int</code>=<em><code>100</code></em>, <strong><code>lr</code></strong>:<code>float</code>=<em><code>0.1</code></em>, <strong><code>n_shape_alphas</code></strong>:<code>int</code>=<em><code>0</code></em>, <strong><code>nonaux_b_norm</code></strong>:<code>bool</code>=<em><code>False</code></em>, <strong><code>shape_aux</code></strong>:<code>Optional</code>[<code>List</code>[<code>Distribution</code>]]=<em><code>None</code></em>, <strong><code>b_norm_aux</code></strong>:<code>Optional</code>[<code>List</code>[<code>Distribution</code>]]=<em><code>None</code></em>, <strong><code>s_norm_aux</code></strong>:<code>Optional</code>[<code>List</code>[<code>Distribution</code>]]=<em><code>None</code></em>) :: <a href="/pytorch_inferno/inferno_interp.html#AbsApproxInferno"><code>AbsApproxInferno</code></a></p>
</blockquote>
<p>Inheriting class for dealing with INFERNO paper synthetic problem</p>

Expand Down
5 changes: 3 additions & 2 deletions nbs/03_callback.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"from pytorch_inferno.utils import to_np\n",
"\n",
"from typing import Optional, Callable, Union\n",
"from abc import ABC\n",
"from fastcore.all import store_attr, Path\n",
"import math\n",
"import numpy as np\n",
Expand All @@ -65,10 +64,11 @@
"outputs": [],
"source": [
"# export\n",
"class AbsCallback(ABC):\n",
"class AbsCallback():\n",
" r'''Abstract callback passing though all action points and indicating where callbacks can affect the model.\n",
" See `ModelWrapper` etc. to see where exactly these action points are called.'''\n",
" def __init__(self): pass\n",
" \n",
" def set_wrapper(self, wrapper) -> None: self.wrapper = wrapper \n",
" def on_train_begin(self) -> None: pass\n",
" def on_train_end(self) -> None: pass \n",
Expand Down Expand Up @@ -225,6 +225,7 @@
"class PaperSystMod(AbsCallback):\n",
" r'''Prediction callback for modifying input data from INFERNO paper according to specified nuisances.'''\n",
" def __init__(self, r:float=0, l:float=3): store_attr()\n",
" \n",
" def on_batch_begin(self) -> None:\n",
" self.wrapper.x[:,0] += self.r\n",
" self.wrapper.x[:,2] *= self.l/3"
Expand Down
5 changes: 2 additions & 3 deletions nbs/07_inferno_exact.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"from pytorch_inferno.inference import calc_grad_hesse\n",
"\n",
"import numpy as np\n",
"from abc import abstractmethod\n",
"from abc import abstractmethod, ABCMeta\n",
"from fastcore.all import store_attr, delegates, is_close\n",
"from typing import Optional, List\n",
"\n",
Expand Down Expand Up @@ -264,11 +264,10 @@
"outputs": [],
"source": [
"# export\n",
"class AbsInferno(AbsCallback):\n",
"class AbsInferno(AbsCallback, metaclass=ABCMeta):\n",
" r'''Attempted reproduction of TF1 & TF2 INFERNO with exact effect of nuisances being passed through model'''\n",
" def __init__(self, b_true:float, mu_true:float, n_shape_alphas:int=0, s_shape_alpha:bool=False, b_shape_alpha:bool=False, nonaux_b_norm:bool=False,\n",
" shape_aux:Optional[List[Distribution]]=None, b_norm_aux:Optional[List[Distribution]]=None, s_norm_aux:Optional[List[Distribution]]=None):\n",
" super().__init__()\n",
" store_attr()\n",
" if self.shape_aux is not None and len(self.shape_aux) != self.n_shape_alphas: raise ValueError(\"Number of auxillary measurements on shape nuisances must match the number of shape nuisance parameters\")\n",
" self.n=self.mu_true+self.b_true\n",
Expand Down
4 changes: 2 additions & 2 deletions nbs/08_inferno_interp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"from typing import *\n",
"from collections import OrderedDict\n",
"import numpy as np\n",
"from abc import abstractmethod\n",
"from abc import abstractmethod, ABCMeta\n",
"from typing import Optional, List\n",
"from fastcore.all import store_attr, delegates\n",
"\n",
Expand Down Expand Up @@ -120,7 +120,7 @@
"outputs": [],
"source": [
"# export\n",
"class AbsApproxInferno(AbsInferno):\n",
"class AbsApproxInferno(AbsInferno, metaclass=ABCMeta):\n",
" r'''Attempted reproduction INFERNO following paper description implementations with nuisances being approximated by creating up/down shapes and interpolating\n",
" Includes option to randomise params per batch and converge to better values, which results in slightly better performance'''\n",
" @delegates(AbsInferno)\n",
Expand Down
5 changes: 3 additions & 2 deletions pytorch_inferno/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from .utils import to_np

from typing import Optional, Callable, Union
from abc import ABC
from fastcore.all import store_attr, Path
import math
import numpy as np
Expand All @@ -15,10 +14,11 @@
from torch import nn

# Cell
class AbsCallback(ABC):
class AbsCallback():
r'''Abstract callback passing though all action points and indicating where callbacks can affect the model.
See `ModelWrapper` etc. to see where exactly these action points are called.'''
def __init__(self): pass

def set_wrapper(self, wrapper) -> None: self.wrapper = wrapper
def on_train_begin(self) -> None: pass
def on_train_end(self) -> None: pass
Expand Down Expand Up @@ -140,6 +140,7 @@ def on_forwards_end(self) -> None:
class PaperSystMod(AbsCallback):
r'''Prediction callback for modifying input data from INFERNO paper according to specified nuisances.'''
def __init__(self, r:float=0, l:float=3): store_attr()

def on_batch_begin(self) -> None:
self.wrapper.x[:,0] += self.r
self.wrapper.x[:,2] *= self.l/3
Expand Down
Loading

0 comments on commit dd427f3

Please sign in to comment.