提交 214cfb47 编写于 作者: HansBug's avatar HansBug 😆

dev(hansbug): add support for pip install DI-treetensor[potc]

上级 0a9c5545
......@@ -102,10 +102,6 @@ gen
*.tiff
*.tif
# Scalable Vector Graphics
*.svg
*.svgz
# Portable Document Format
*.pdf
......@@ -632,7 +628,6 @@ FodyWeavers.xsd
### Vim template
# Swap
[._]*.s[a-v][a-z]
!*.svg # comment out if you don't need vector files
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
......
......@@ -159,6 +159,25 @@ For more quick start explanation and further usage, take a look at:
* [Quick Start](https://opendilab.github.io/DI-treetensor/main/tutorials/quick_start/index.html)
## Extension
If you need to translate `treevalue` object to runnable source code, you may use the [potc-treevalue](https://github.com/potc-dev/potc-treevalue) plugin with the installation command below
```
pip install DI-treetensor[potc]
```
In potc, you can translate the objects to runnable python source code, which can be loaded to objects afterwards by the python interpreter, like the following graph
![potc_system](docs/source/_static/potc-doing.svg)
For more information, you can refer to
- [potc-dev/potc](https://github.com/potc-dev/potc)
- [potc-dev/potc-treevalue](https://github.com/potc-dev/potc-treevalue)
- [potc-dev/potc-torch](https://github.com/potc-dev/potc-torch)
- [Potc Plugin Installation](https://opendilab.github.io/DI-treetensor/main/tutorials/plugins/index.html#potc-support)
## Contribution
We appreciate all contributions to improve DI-treetensor, both logic and system designs. Please refer to CONTRIBUTING.md for more guides.
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="310"
height="310"
viewBox="0 0 194.3793 194.3793"
version="1.1"
id="svg5"
sodipodi:docname="potc-doing.svg"
inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview7"
pagecolor="#ffffff"
bordercolor="#323232"
borderopacity="1"
inkscape:pageshadow="0"
inkscape:pageopacity="0"
inkscape:pagecheckerboard="true"
inkscape:document-units="px"
showgrid="false"
borderlayer="true"
inkscape:showpageshadow="true"
showborder="true"
inkscape:zoom="1"
inkscape:cx="161"
inkscape:cy="328.5"
inkscape:window-width="1920"
inkscape:window-height="1001"
inkscape:window-x="-9"
inkscape:window-y="-9"
inkscape:window-maximized="1"
inkscape:current-layer="layer1"
width="197mm"
scale-x="0.52703"
units="px"
viewbox-height="195" />
<defs
id="defs2">
<marker
style="overflow:visible"
id="marker1316"
refX="0"
refY="0"
orient="auto"
inkscape:stockid="Arrow2Lend"
inkscape:isstock="true">
<path
transform="matrix(-1.1,0,0,-1.1,-1.1,0)"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
style="fill:context-stroke;fill-rule:evenodd;stroke:context-stroke;stroke-width:0.625;stroke-linejoin:round"
id="path1076" />
</marker>
<marker
style="overflow:visible"
id="marker15262"
refX="0"
refY="0"
orient="auto"
inkscape:stockid="Arrow2Lend"
inkscape:isstock="true">
<path
transform="matrix(-1.1,0,0,-1.1,-1.1,0)"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
style="fill:context-stroke;fill-rule:evenodd;stroke:context-stroke;stroke-width:0.625;stroke-linejoin:round"
id="path15260" />
</marker>
<marker
style="overflow:visible"
id="marker15252"
refX="0"
refY="0"
orient="auto"
inkscape:stockid="Arrow1Lend"
inkscape:isstock="true">
<path
transform="matrix(-0.8,0,0,-0.8,-10,0)"
style="fill:context-stroke;fill-rule:evenodd;stroke:context-stroke;stroke-width:1pt"
d="M 0,0 5,-5 -12.5,0 5,5 Z"
id="path15250" />
</marker>
<marker
style="overflow:visible"
id="Arrow1Lend"
refX="0"
refY="0"
orient="auto"
inkscape:stockid="Arrow1Lend"
inkscape:isstock="true">
<path
transform="matrix(-0.8,0,0,-0.8,-10,0)"
style="fill:context-stroke;fill-rule:evenodd;stroke:context-stroke;stroke-width:1pt"
d="M 0,0 5,-5 -12.5,0 5,5 Z"
id="path14354" />
</marker>
<marker
style="overflow:visible"
id="Arrow2Lend"
refX="0"
refY="0"
orient="auto"
inkscape:stockid="Arrow2Lend"
inkscape:isstock="true">
<path
transform="matrix(-1.1,0,0,-1.1,-1.1,0)"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
style="fill:context-stroke;fill-rule:evenodd;stroke:context-stroke;stroke-width:0.625;stroke-linejoin:round"
id="path14372" />
</marker>
<marker
style="overflow:visible"
id="Arrow1Lstart"
refX="0"
refY="0"
orient="auto"
inkscape:stockid="Arrow1Lstart"
inkscape:isstock="true">
<path
transform="matrix(0.8,0,0,0.8,10,0)"
style="fill:context-stroke;fill-rule:evenodd;stroke:context-stroke;stroke-width:1pt"
d="M 0,0 5,-5 -12.5,0 5,5 Z"
id="path14351" />
</marker>
<filter
style="color-interpolation-filters:sRGB"
inkscape:label="Drop Shadow"
id="filter14120"
x="-0.11204367"
y="-0.27115467"
width="1.2520983"
height="1.610098">
<feFlood
flood-opacity="0.498039"
flood-color="rgb(0,0,0)"
result="flood"
id="feFlood14110" />
<feComposite
in="flood"
in2="SourceGraphic"
operator="in"
result="composite1"
id="feComposite14112" />
<feGaussianBlur
in="composite1"
stdDeviation="5"
result="blur"
id="feGaussianBlur14114" />
<feOffset
dx="3"
dy="3"
result="offset"
id="feOffset14116" />
<feComposite
in="SourceGraphic"
in2="offset"
operator="over"
result="composite2"
id="feComposite14118" />
</filter>
<filter
style="color-interpolation-filters:sRGB"
inkscape:label="Drop Shadow"
id="filter14150"
x="-0.11504064"
y="-0.30774402"
width="1.2588414"
height="1.692424">
<feFlood
flood-opacity="0.498039"
flood-color="rgb(0,0,0)"
result="flood"
id="feFlood14140" />
<feComposite
in="flood"
in2="SourceGraphic"
operator="in"
result="composite1"
id="feComposite14142" />
<feGaussianBlur
in="composite1"
stdDeviation="5"
result="blur"
id="feGaussianBlur14144" />
<feOffset
dx="3"
dy="3"
result="offset"
id="feOffset14146" />
<feComposite
in="SourceGraphic"
in2="offset"
operator="over"
result="composite2"
id="feComposite14148" />
</filter>
</defs>
<g
inkscape:label="图层 1"
inkscape:groupmode="layer"
id="layer1">
<g
id="g5166"
transform="translate(12.122605,-0.05363983)">
<g
id="g13626"
style="filter:url(#filter14120)"
transform="translate(16.458305,4.5870873)">
<rect
style="fill:#f6b5fc;fill-opacity:0.839542;fill-rule:evenodd;stroke-width:0.291935;stroke-miterlimit:4;stroke-dasharray:none"
id="rect31"
width="107.1011"
height="44.255184"
x="13.725255"
y="14.507528" />
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:10.5833px;line-height:1.25;font-family:sans-serif;fill:#00002f;fill-opacity:0.843137;stroke:none;stroke-width:0.264583"
x="47.409298"
y="31.980234"
id="text1630"><tspan
sodipodi:role="line"
id="tspan1628"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:10.5833px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#00002f;fill-opacity:0.843137;stroke-width:0.264583"
x="47.409298"
y="31.980234">Object</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:7.76111px;line-height:1.25;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#000068;fill-opacity:0.843137;stroke:none;stroke-width:0.264583"
x="22.442272"
y="46.848244"
id="text5854"><tspan
sodipodi:role="line"
id="tspan5852"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:7.76111px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#000068;fill-opacity:0.843137;stroke-width:0.264583"
x="22.442272"
y="46.848244">Existing python objects</tspan></text>
</g>
<g
id="g13560"
transform="translate(-135.30756,12.161354)"
style="filter:url(#filter14150)">
<rect
style="fill:#b5fcdf;fill-opacity:0.839542;stroke-width:0.182715;stroke-miterlimit:4;stroke-dasharray:none"
id="rect8153"
width="104.31097"
height="38.993446"
x="168.31702"
y="121.74933" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:10.5833px;line-height:1.25;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#3a052b;fill-opacity:0.836676;stroke:none;stroke-width:0.264583"
x="206.46889"
y="136.89786"
id="text10085"><tspan
sodipodi:role="line"
id="tspan10083"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:10.5833px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#3a052b;fill-opacity:0.836676;stroke-width:0.264583"
x="206.46889"
y="136.89786">Code</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:7.76111px;line-height:1.25;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#5b0843;fill-opacity:0.835294;stroke:none;stroke-width:0.264583"
x="176.17181"
y="150.36322"
id="text13323"><tspan
sodipodi:role="line"
id="tspan13321"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:7.76111px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#5b0843;fill-opacity:0.835294;stroke-width:0.264583"
x="176.17181"
y="150.36322">Runnable python code</tspan></text>
</g>
<g
id="g5140"
transform="translate(-59.003831,-2.1455939)">
<path
style="fill:none;stroke:#30031a;stroke-width:0.565;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:3.2;stroke-dasharray:none;stroke-opacity:0.802292;marker-end:url(#marker15262);paint-order:normal"
d="m 163.82858,65.924171 c 18.23435,35.627099 -1.9637,69.571039 -1.9637,69.571039"
id="path15083" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.46667px;line-height:1.25;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#30031a;fill-opacity:0.803922;stroke:none;stroke-width:0.264583"
x="184.21156"
y="93.483849"
id="text16760"><tspan
sodipodi:role="line"
id="tspan16758"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.46667px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#30031a;fill-opacity:0.803922;stroke-width:0.264583"
x="184.21156"
y="93.483849">Translated</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.46667px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#30031a;fill-opacity:0.803922;stroke-width:0.264583"
x="184.21156"
y="104.06718"
id="tspan16762">by <tspan
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:8.46667px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#30031a;fill-opacity:0.803922"
id="tspan19836">potc</tspan></tspan></text>
</g>
<g
id="g5133"
transform="translate(-59.003831,-2.1455939)">
<path
style="fill:none;stroke:#200348;stroke-width:0.565;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:3.2;stroke-dasharray:none;stroke-opacity:0.848138;marker-end:url(#marker1316)"
d="m 126.85823,135.44061 c -19.04214,-33.5249 -0.80459,-69.999998 -0.80459,-69.999998"
id="path208" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.46667px;line-height:1.25;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#200348;fill-opacity:0.847059;stroke:none;stroke-width:0.265;stroke-miterlimit:3.2;stroke-dasharray:none"
x="62.222221"
y="97.08812"
id="text2838"><tspan
sodipodi:role="line"
id="tspan2836"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.46667px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#200348;fill-opacity:0.847059;stroke-width:0.265;stroke-miterlimit:3.2;stroke-dasharray:none"
x="62.222221"
y="97.08812">Loaded</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.46667px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#200348;fill-opacity:0.847059;stroke-width:0.265;stroke-miterlimit:3.2;stroke-dasharray:none"
x="62.222221"
y="107.67146"
id="tspan2840">by <tspan
style="font-weight:bold"
id="tspan3808">python</tspan></tspan></text>
</g>
</g>
</g>
</svg>
......@@ -14,6 +14,7 @@ module.
tutorials/installation/index
tutorials/quick_start/index
tutorials/plugins/index
.. toctree::
:maxdepth: 2
......
Plugins
=================
Potc support
---------------------
`Potc <https://github.com/potc-dev/potc>`_ is a package that can convert any object into executable source code.
For ``DI-treetensor``, potc can support the source code transformation of treevalue objects
through the installation of additional plugins. So we can execute the following installation command
.. code:: shell
pip install DI-treetensor[potc]
After this installation, you will be able to directly convert tree-nested tensors to objects
without any additional operations. Such as
.. literalinclude:: potc_demo.demo.py
:language: python
:linenos:
The output should be
.. literalinclude:: potc_demo.demo.py.txt
:language: text
:linenos:
Also, you can use the following CLI command to get the same output results as above.
.. code:: shell
potc export -v 'test_simple.t_*'
For further information, you can refer to
* `potc-dev/potc <https://github.com/potc-dev/potc>`_
* `potc-dev/potc-treevalue <https://github.com/potc-dev/potc-treevalue>`_
* `potc-dev/potc-torch <https://github.com/potc-dev/potc-torch>`_
from potc import transvars
import treetensor.torch as ttorch
t_tensor = ttorch.randn({'a': (2, 3), 'b': (3, 4)})
t_i_tensor = ttorch.randint(-5, 10, {'a': (3, 4), 'x': {'b': (2, 3)}})
t_shape = t_i_tensor.shape
if __name__ == '__main__':
_code = transvars(
{
't_tensor': t_tensor,
't_i_tensor': t_i_tensor,
't_shape': t_shape,
},
reformat='pep8'
)
print(_code)
......@@ -6,4 +6,6 @@ plantumlcli>=0.0.2
packaging
sphinx-multiversion~=0.2.4
where~=1.0.2
easydict>=1.7,<2
\ No newline at end of file
easydict>=1.7,<2
potc-torch>=0.0.1
potc-treevalue>=0.0.1
\ No newline at end of file
potc-treevalue>=0.0.1
potc-torch>=0.0.1
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册