Skip to main content

PyTorch Extra Activations And Layers (pyteals)

Small, self-contained PyTorch primitives (currently all nn.Module classes, not guaranteed to stay that way as the package grows), extracted from the ScatterNet project. Each depends only on torch, no project-specific code.

Install

pip install -e /path/to/pyteals   # editable, for local development

Contents

Split into two subpackages by kind: pyteals.activations (pure elementwise nonlinearities, one tensor in, same-shape tensor out) and pyteals.layers (learned/composite layers that take multiple inputs and/or wrap submodules). Everything is also re-exported at the top level, so from pyteals import PBId and from pyteals.activations import PBId both work.

Activations (pyteals.activations)

  • PBId - bent identity activation with a learned, bounded per-feature bend strength, interpolating continuously between the identity (w=0) and the standard bent identity (w=1). Use where a layer should be able to learn its way toward linear behaviour rather than being forced through a fixed nonlinearity from the start.
  • SqrP - square-plus activation, a smooth strictly-positive approximation to max(x, 0) with a learned width and a numerically stable form on the negative tail. Defined only from +, *, and sqrt (no exp/log), so it's cheaper than softplus on hardware without fast transcendental ops, at the cost of a slower-decaying negative tail (1/|x| vs softplus's exponential); good for a strictly-positive, order-1, softplus-like output where an exact zero is never required. See Barron (2021) below.

Layers (pyteals.layers)

  • NoTrilinBilin - drop-in replacement for nn.Bilinear that avoids the generic _trilinear autograd kernel via one matmul plus an elementwise reduce. Best when one side of the bilinear form is small (e.g. min(out_features, in2_features) == 1); profile before reusing it where both sides are large, since it trades PyTorch's fused kernel for an intermediate tensor that PyTorch's implementation never materializes.
  • QDiagBilin - bilinear form with one independent weight matrix per point along a designated axis, rather than one matrix shared across it. Use whenever a bilinear combination should vary per grid point, per time step, or per any other structured index instead of being homogeneous across it.
  • PTanhShrink - a bilinear layer followed by a width-parametric tanh shrink (y - c*tanh(y/c)), a soft, cubic-near-zero shrink toward 0 with a learned, bounded per-channel width. Generalizes PyTorch's nn.Tanhshrink. Useful wherever a signal should stay near-inert until it clears a per-channel threshold, rather than responding linearly from zero.
  • PPSpline - adaptive P-spline / Whittaker smoother for batches of 1D curves, with per-sample, per-point smoothing strength (Λ) supplied at call time (e.g. from an external, input-conditioned "amortized hyperparameter" head) rather than fixed or learned as a free parameter inside the module itself. Use for smoothing a batch of same-length curves where the right amount of smoothing may vary per sample and per position along the curve.

See each module's docstring for the full mathematical description and the reasoning behind its parameterization.

torch.compile

Each module takes three constructor-time flags, consistent across all, controlling whether and how its forward math is compiled:

  • compile: bool = False - if True, the actual math runs through a separate _forward_fn wrapped in torch.compile.
  • dynamic: bool | None = None - passed straight through to torch.compile. Default None is torch.compile's own default (start static, switch to dynamic shapes automatically on detected recompilation).
  • fullgraph: bool = False - passed straight through to torch.compile. Default False falls back to eager on a graph break instead of raising; set True if you'd rather compilation fail loudly on any break.

References

License

MIT, see LICENSE.

Metadata

Release files for pyteals 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyteals 1.0.3
File Size Uploaded
pyteals-1.0.3.tar.gz 17.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyteals 1.0.3
File Interpreter ABI Platform
pyteals-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 37.9 kB

Release files / pyteals-1.0.3.tar.gz

Download URL pyteals-1.0.3.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
08ca36e2bfd8c62a5500a560e3bab4dd8795ddef9dc570d20e02813858decbba
BLAKE2b-256 checksum
How to use checksums
7c123bf72e369c05c82c3fda84f7723282d569281021881f3695139d2914e089
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 14, 2026.

Transparency log

Release files / pyteals-1.0.3-py3-none-any.whl

Download URL pyteals-1.0.3-py3-none-any.whl
Size 20.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0694a86dbc6913c70e323cdd40419e062fd2cff6072bfb0c3ef4ad91e678301f
BLAKE2b-256 checksum
How to use checksums
c4832dd9e801eb68c8fcc99ac6de5cf7149be7053cba483e564bcfcb0db52786
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page