Skip to content

Functional layer API, conventions #21

Closed
@albertz

Description

@albertz

Definition: Functional means that the layer / op does not have trainable parameters.

Examples:

  • tanh, sigmoid etc, i.e. all math ops. RETURNN: ActivationLayer
  • dot/matmul/einsum. RETURNN: DotLayer
  • split. RETURNN: SplitLayer

Instead of writing Activation(activation="tanh")(x), one should be able to write simply tanh(x).
Instead of Dot(...)(x, y), one should be able to write dot(x, y, ...) or so. (Or maybe using a more einsum-like API.)
Instead of Split(...)(x), split(x, ...).

Similar as in the PyTorch functional API.

The naming convention would be to start with lowercase letter, unlike modules which start with upper case.

Also, modules are classes, and need to be initiated. The functional API would just behave like functions.

Related are also the elemwise ops on a LayerRef, such as +, == etc.


Some open questions:

  • Where to define? Namescope?
  • How far automatically generated?
    • E.g. we could extend the current layer generation code, to automatically put layers without params into the functional namescope.
    • Still we additionally want to manually/explicitly define some functions, e.g. einsum/dot. Also tanh etc need to be explicit.
  • Should we have always both variants, like Sigmoid as a module, and sigmoid as a function?
    • PyTorch has this for some functions. But not always.
    • Flax only has the functional variant when some op is purely functional.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions