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.4.0.tar.gz (15.9 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.4.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: eml_cost_torch-0.4.0.tar.gz
  • Upload date:
  • Size: 15.9 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.4.0.tar.gz
Algorithm Hash digest
SHA256 0a8482ce5023ffe44eb1aeb03b08d31286f70097ba6b5155669c35483c21211d
MD5 886a60245ab0077f757f0dda7f21d2b7
BLAKE2b-256 24b16b673abfca51e1864011f80ed774a27c5b2964e582537f035c0c4ed71686

See more details on using hashes here.

File details

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

File metadata

  • Download URL: eml_cost_torch-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 13.3 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 da7a214a5303d761cad1e273060f8237e16f37b7f0be3b6f5dac96e49287625c
MD5 e7cc461f8a50d2571842b3333422b30b
BLAKE2b-256 375af69a2f6f914d4d54deca66fa221aa8743ecefb76707472ef78a3002e5c6a

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