Skip to main content

Per-layer Pfaffian profile and EML routing depth for any torch.nn.Module.

Project description

eml-cost-torch

Per-layer Pfaffian profile and EML routing depth for any torch.nn.Module.

Walks a PyTorch model, classifies each leaf module by mapping it to its symbolic SymPy equivalent, and runs eml-cost to produce a Pfaffian chain order, EML routing depth, and canonical axes-tuple per layer.

Install

pip install eml-cost-torch          # core (sympy + eml-cost only)
pip install "eml-cost-torch[torch]" # adds torch>=2.0 for live model walking

Quick start

import torch.nn as nn
from eml_cost_torch import summary, profile

model = nn.Sequential(
    nn.Linear(64, 32),
    nn.GELU(),
    nn.LayerNorm(32),
    nn.Linear(32, 16),
    nn.Sigmoid(),
)

print(summary(model))

Output:

==========================================================================================
  Per-layer Pfaffian profile  (5 leaf modules)
==========================================================================================
  name                              class                 axes                r     depth
  --------------------------------------------------------------------------------------
  0                                 Linear                p0-d2-w0-c0         r= 0  d=  2
  1                                 GELU                  p3-d5-w3-c0         r= 3  d=  6
  2                                 LayerNorm             p1-d4-w1-c0         r= 1  d=  4
  3                                 Linear                p0-d2-w0-c0         r= 0  d=  2
  4                                 Sigmoid               p1-d1-w1-c-1        r= 1  d=  2
  --------------------------------------------------------------------------------------
  total r (sum across leaves): 5
  max r in any leaf:           3
  max predicted_depth:         6
  distinct cost classes:       4
    p0-d2-w0-c0       x 2
    p3-d5-w3-c0       x 1
    p1-d4-w1-c0       x 1
    p1-d1-w1-c-1      x 1

Programmatic access

from eml_cost_torch import profile, profile_dict

# Returns list of LayerProfile dataclass instances
rows = profile(model)
for r in rows:
    print(r.class_name, r.axes, r.pfaffian_r)

# Or as JSON-friendly dicts
import json
json.dumps(profile_dict(model))

What's measured per layer

Field Meaning
pfaffian_r Total Pfaffian chain order (Khovanskii convention)
max_path_r Chain order along the deepest path
eml_depth EML routing tree depth
predicted_depth Full predicted depth (chain + structural + corrections)
axes Canonical fingerprint p<r>-d<n>-w<m>-c<k>
is_pfaffian_not_eml True for Bessel, Airy, Lambert W, etc.

Supported torch.nn classes

50+ classes registered out of the box, including:

  • Linear / Conv (Linear, Conv1d/2d/3d, ConvTranspose*)
  • Activations (ReLU, GELU, Sigmoid, Tanh, SiLU, Mish, ELU, Softmax, ...)
  • Normalisation (LayerNorm, BatchNorm*, GroupNorm, RMSNorm)
  • Pooling (MaxPool*, AvgPool*, adaptive variants)
  • Regularisation (Dropout, AlphaDropout)
  • Embedding (Embedding, EmbeddingBag)
  • Attention (MultiheadAttention — simplified score)

Unknown layer classes are reported as UNKNOWN rather than raising.

See also

License

PROPRIETARY PRE-RELEASE — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eml_cost_torch-0.3.0.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

eml_cost_torch-0.3.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file eml_cost_torch-0.3.0.tar.gz.

File metadata

  • Download URL: eml_cost_torch-0.3.0.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for eml_cost_torch-0.3.0.tar.gz
Algorithm Hash digest
SHA256 0f3b603594dee126ad58d2b6094d6812d4cd9019c37492e8c1b20447b073618e
MD5 73667e20cf496f35ccc9a6a1c0244018
BLAKE2b-256 9016255230dc49d3a0d76bd84d134e25af3d3536018d877d4ece1dfb06c40241

See more details on using hashes here.

File details

Details for the file eml_cost_torch-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: eml_cost_torch-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for eml_cost_torch-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db0a32fec4bdbbfd95dc363251bc7b260fbce0d0c89143d046a92087db6bc1c9
MD5 277cc6bc3ac53a36768186f023a229ad
BLAKE2b-256 cb8edcbefb01c64c6cfa50810e314e7330b98d832265968e1186bbfea5da0e85

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page