potc-torch
January 2, 2022 ยท View on GitHub
Potc support for torch module.
Installation
You can simply install it with pip command line from the official PyPI site.
pip install potc-torch
Quick Start
After potc-torch is installed, you can convert the torch objects into executable source code without any additional operations.
We can create a python script which is named test_simple.py
import torch
from potc import transvars
a = torch.randn(2, 3)
b = torch.randint(-5, 10, (3, 4))
bs = b.size()
bd = b.device
if __name__ == '__main__':
_code = transvars(
{'a': a, 'b': b, 'bs': bs, 'bd': bd},
reformat='pep8',
)
print(_code)
The output result should be like this (may be slightly different because of the usage of torch.randn and torch.randint)
import torch
__all__ = ['a', 'b', 'bd', 'bs']
a = torch.as_tensor(
[[0.6224261522293091, 0.4725508689880371, 0.45328783988952637],
[-0.5855962634086609, 0.4898407459259033, 0.4769541621208191]],
dtype=torch.float32)
b = torch.as_tensor([[2, 7, 4, -3], [-2, 4, 8, 1], [7, -5, 3, 6]],
dtype=torch.long)
bd = torch.device('cpu')
bs = torch.Size([3, 4])
And, you can use the following CLI command to get the same output results as above.
potc export -v 'test_simple.a' -v 'test_simple.b*'
Contributing
We appreciate all contributions to improve potc and potc-torch, both logic and system designs. Please refer to CONTRIBUTING.md for more guides.
License
potc-torch released under the Apache 2.0 license.