A tiny symbolic autodiff demo built on Sympy.
Project description
SymGrad4T
一个用 Sympy 做符号表达的极简自动求导/张量广播示例。支持基本张量算子(加减乘除、幂、求和、广播、LaTeX 输出等),附带示例脚本与测试。
安装
- 直接通过 PyPI 安装:
pip install symgrad4t - 或本地开发模式:
pip install -e .
运行测试
- 项目根目录执行:
pytest -q - 如需只跑库内测试:
cd python && pytest -q
运行示例
- 示例脚本在
examples/下,如:- RMSNorm:
python examples/rms_norm/rms_norm.py - 矩阵四则运算:
python examples/matrix_arith.py - 矩阵求和:
python examples/matrix_sum.py - 三层 MLP:
python examples/mlp.py
- RMSNorm:
- 输出会打印计算图中张量的梯度(LaTeX 形式),可粘贴到 https://www.latexlive.com/ 查看公式效果。
已支持的 OP
- 加减乘除:
Add/Sub/Mul/Div(支持广播与标量/符号) - 幂:
Power(支持标量或张量指数,广播) - 平方根:
Sqrt - 维度求和:
Sum(dim, keepdim=False)(支持负索引与 keepdim) - 广播:
Broadcast/Tensor.broadcast_to - LaTeX 输出:
Tensor.latex_expr()/Tensor.latex_grad() - 其他:
MatMul/Transpose/Max/ReLU/Softmax/CrossEntropy
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
symgrad4t-0.2.0.tar.gz
(7.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file symgrad4t-0.2.0.tar.gz.
File metadata
- Download URL: symgrad4t-0.2.0.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
509fb2336dc19ffc7621d21a787dd44bae0db4c20921f7779e8a9873abc58218
|
|
| MD5 |
f89d3d0a33c80d6bc4ad71387aaebe1c
|
|
| BLAKE2b-256 |
5161aa0b96df1d58523f864460080f3cf335be95a4b3ca363efef218340f30f6
|
File details
Details for the file symgrad4t-0.2.0-py3-none-any.whl.
File metadata
- Download URL: symgrad4t-0.2.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1af740e5c569dd9c1d5238c6248df135b88ac28195fe74f1400cd2cfaba3e4f4
|
|
| MD5 |
964e04d6df2ddbfe7cfe192405ad5b00
|
|
| BLAKE2b-256 |
e7752478d739965e26fdb72eaff8884855c53cbac16cb1ca9c80099db4670a03
|