Skip to content

Commit

Permalink
Rename LMUFFT to LMUFeedforward
Browse files Browse the repository at this point in the history
  • Loading branch information
drasmuss committed Aug 12, 2021
1 parent 424f197 commit ee58c88
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 80 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Release history
- The ``A`` and ``B`` matrices are now stored as constants instead of non-trainable
variables. This can improve the training/inference speed, but it means that saved
weights from previous versions will be incompatible. (`#41`_)
- Renamed ``keras_lmu.LMUFFT`` to ``keras_lmu.LMUFeedforward``. (`#42`_)

.. _#40: https://github.com/nengo/keras-lmu/pull/40
.. _#41: https://github.com/nengo/keras-lmu/pull/41
Expand Down
2 changes: 1 addition & 1 deletion keras_lmu/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""KerasLMU provides a package for deep learning with Legendre Memory Units."""

from .layers import LMU, LMUFFT, LMUCell
from .layers import LMU, LMUCell, LMUFeedforward
from .version import version as __version__

__copyright__ = "2019-2021, Applied Brain Research"
Expand Down
15 changes: 7 additions & 8 deletions keras_lmu/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def theta(self):
if self.built:
return (
self.layer.theta
if isinstance(self.layer, LMUFFT)
if isinstance(self.layer, LMUFeedforward)
else self.layer.cell.theta
)

Expand All @@ -541,7 +541,7 @@ def build(self, input_shapes):
and input_shapes[1] is not None
and not self.trainable_theta
):
self.layer = LMUFFT(
self.layer = LMUFeedforward(
memory_d=self.memory_d,
order=self.order,
theta=self._init_theta,
Expand Down Expand Up @@ -620,15 +620,14 @@ def from_config(cls, config):
return super().from_config(config)


class LMUFFT(tf.keras.layers.Layer):
class LMUFeedforward(tf.keras.layers.Layer):
"""
Layer class for the FFT variant of the LMU.
Layer class for the feedforward variant of the LMU.
This class assumes no recurrent connections are desired in the memory component.
Produces the output of the delay system by evaluating the convolution of the input
sequence with the impulse response from the LMU cell. The convolution operation is
calculated using the fast Fourier transform (FFT).
sequence with the impulse response from the LMU cell.
Parameters
----------
Expand Down Expand Up @@ -747,8 +746,8 @@ def build(self, input_shape):
# TODO: we could dynamically run the impulse response for longer if
# needed using stateful=True
raise ValueError(
f"LMUFFT requires that the input shape's temporal axis be fully "
f"specified (got {seq_len})"
f"LMUFeedforward requires that the input shape's temporal axis be "
f"fully specified (got {seq_len})"
)

impulse = tf.reshape(tf.eye(seq_len, 1), (1, -1, 1))
Expand Down
4 changes: 3 additions & 1 deletion keras_lmu/tests/test_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ def test_performance(mode, capsys):
return_sequences=False,
)
elif mode in ("fft", "raw", "raw_nchw"):
lmu_layer = layers.LMUFFT(return_sequences=False, conv_mode=mode, **kwargs)
lmu_layer = layers.LMUFeedforward(
return_sequences=False, conv_mode=mode, **kwargs
)

inputs = tf.keras.layers.Input((seq_len, dims), batch_size=batch_size)
lmu = lmu_layer(inputs)
Expand Down

0 comments on commit ee58c88

Please sign in to comment.