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.1.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.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: eml_cost_torch-0.3.1.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.1.tar.gz
Algorithm Hash digest
SHA256 768fcf6914a5c703fb21d900ca6642d46b9d5a91ba0138df9727f2cc3485739f
MD5 29a23200e3efc1ba68b9ad2eeb465373
BLAKE2b-256 5b5fe2a4966dffc71a0d3abc2c9e98b2ef8771fe765a033500de7d3a07d157fa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: eml_cost_torch-0.3.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 515d999faab497960c4aa398ea0a4b7d28deaffa62cca33fd10fc052ce1ae110
MD5 203222f5fb502193ebbfec419b51f7ac
BLAKE2b-256 24ce7a85f2292991e94262b98af6bcc043114d1ccabb5a90e8d2e267f1402098

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