Pytorch Symbolic
Pytorch Symbolic is MIT licensed library that adds symbolic API for model creation to PyTorch.
Pytorch Symbolic makes it easier and faster to define complex models. It spares you writing boilerplate code. It aims to be PyTorch equivalent for Keras Functional API.
Features:
- Small extension of PyTorch
- No dependencies besides PyTorch
- Produces models entirely compatible with PyTorch
- Works with
torch.compileandtorch.export - Overhead free as tested in benchmarks
- Reduces the amount of boilerplate code
- Works well with complex architectures
- Code and documentation is automatically tested
Example
To create a symbolic model, you need Symbolic Tensors and torch.nn.Module.
Register layers and operations in your model by calling layer(inputs) or
equivalently inputs(layer).
Layers will be automagically added to your model and
all operations will be replayed on the real data.
That's all!
Using Pytorch Symbolic, we can define a working classifier in a few lines of code:
from torch import nn
from pytorch_symbolic import Input, SymbolicModel
inputs = Input(shape=(1, 28, 28))
x = nn.Flatten()(inputs)
x = nn.Linear(x.shape[1], 10)(x)(nn.Softmax(1))
model = SymbolicModel(inputs=inputs, outputs=x)
model.summary()
_______________________________________________________
Layer Output shape Params Parent
=======================================================
1 Input_1 (None, 1, 28, 28) 0
2 Flatten_1 (None, 784) 0 1
3 Linear_1 (None, 10) 7850 2
4* Softmax_1 (None, 10) 0 3
=======================================================
Total params: 7850
Trainable params: 7850
Non-trainable params: 0
_______________________________________________________
See more examples in Documentation Quick Start.
Symbolic models are plain torch.nn.Module objects, so they work with modern PyTorch tooling:
model = SymbolicModel(inputs=inputs, outputs=x)
compiled_model = torch.compile(model)
exported_program = torch.export.export(model, (example_input,))
# ...
How to start
See Jupyter Notebook showing the basic usage of Pytorch Symbolic:
- Learn Pytorch Symbolic in an interactive way.
- Try the package before installing it on your computer.
- See visualizations of graphs that are created under the hood.
Installation
Install Pytorch Symbolic easily with pip:
pip install pytorch-symbolic
Troubleshooting
Please create an issue if you notice a problem!
Links
Metadata
Release files for pytorch-symbolic 1.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pytorch_symbolic-1.2.4.tar.gz | 992.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytorch_symbolic-1.2.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.0 MB
Release files / pytorch_symbolic-1.2.4.tar.gz
| Download URL | pytorch_symbolic-1.2.4.tar.gz |
|---|---|
| Size | 992.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
286f66fb901cd9645576603ba801890b3e0c5d4c9cae6972c6b2374a58593778
|
|
BLAKE2b-256 checksum How to use checksums |
8b7e552c1ec18ca6d1e730b693e6037a3e65b68fdfda875295a41d00ed0b2981
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.14
|
Release files / pytorch_symbolic-1.2.4-py3-none-any.whl
| Download URL | pytorch_symbolic-1.2.4-py3-none-any.whl |
|---|---|
| Size | 24.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
af8c5812993ba7674b15eec357f3fc5334df3a65cc40595bcabf5621c6a61fea
|
|
BLAKE2b-256 checksum How to use checksums |
bf509539192fbee00c4f4263c16168173a1096c94c4664e0146c8566a7e62a98
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.14
|
Security for pytorch-symbolic 1.2.4
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.