在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:treevalue开源软件地址:https://gitee.com/opendilab/treevalue开源软件介绍:treevalue
Almost all the operation can be supported in form of trees in a convenient way to simplify the structure processing when the calculation is tree-based. InstallationYou can simply install it with pip install treevalue For more information about installation, you can refer to the installation guide. DocumentationThe detailed documentation are hosted on https://opendilab.github.io/treevalue. Only english version is provided now, the chinese documentation is still under development. Quick StartYou can easily create a tree value object based on from treevalue import FastTreeValueif __name__ == '__main__': t = FastTreeValue({ 'a': 1, 'b': 2.3, 'x': { 'c': 'str', 'd': [1, 2, None], 'e': b'bytes', } }) print(t) The result should be <FastTreeValue 0x7f6c7df00160 keys: ['a', 'b', 'x']>├── 'a' --> 1├── 'b' --> 2.3└── 'x' --> <FastTreeValue 0x7f6c81150860 keys: ['c', 'd', 'e']> ├── 'c' --> 'str' ├── 'd' --> [1, 2, None] └── 'e' --> b'bytes' And Not only a visible tree structure, but abundant operation supports is provided.You can just put objects (such as import torchfrom treevalue import FastTreeValuet = FastTreeValue({ 'a': torch.rand(2, 5), 'x': { 'c': torch.rand(3, 4), }})print(t)# <FastTreeValue 0x7f8c069346a0># ├── a --> tensor([[0.3606, 0.2583, 0.3843, 0.8611, 0.5130],# │ [0.0717, 0.1370, 0.1724, 0.7627, 0.7871]])# └── x --> <FastTreeValue 0x7f8ba6130f40># └── c --> tensor([[0.2320, 0.6050, 0.6844, 0.3609],# [0.0084, 0.0816, 0.8740, 0.3773],# [0.6523, 0.4417, 0.6413, 0.8965]])print(t.shape) # property access# <FastTreeValue 0x7f8c06934ac0># ├── a --> torch.Size([2, 5])# └── x --> <FastTreeValue 0x7f8c069346d0># └── c --> torch.Size([3, 4])print(t.sin()) # method call# <FastTreeValue 0x7f8c06934b80># ├── a --> tensor([[0.3528, 0.2555, 0.3749, 0.7586, 0.4908],# │ [0.0716, 0.1365, 0.1715, 0.6909, 0.7083]])# └── x --> <FastTreeValue 0x7f8c06934b20># └── c --> tensor([[0.2300, 0.5688, 0.6322, 0.3531],# [0.0084, 0.0816, 0.7669, 0.3684],# [0.6070, 0.4275, 0.5982, 0.7812]])print(t.reshape((2, -1))) # method with arguments# <FastTreeValue 0x7f8c06934b80># ├── a --> tensor([[0.3606, 0.2583, 0.3843, 0.8611, 0.5130],# │ [0.0717, 0.1370, 0.1724, 0.7627, 0.7871]])# └── x --> <FastTreeValue 0x7f8c06934b20># └── c --> tensor([[0.2320, 0.6050, 0.6844, 0.3609, 0.0084, 0.0816],# [0.8740, 0.3773, 0.6523, 0.4417, 0.6413, 0.8965]])print(t[:, 1:-1]) # index operator# <FastTreeValue 0x7f8ba5c8eca0># ├── a --> tensor([[0.2583, 0.3843, 0.8611],# │ [0.1370, 0.1724, 0.7627]])# └── x --> <FastTreeValue 0x7f8ba5c8ebe0># └── c --> tensor([[0.6050, 0.6844],# [0.0816, 0.8740],# [0.4417, 0.6413]])print(1 + (t - 0.8) ** 2 * 1.5) # math operators# <FastTreeValue 0x7fdfa5836b80># ├── a --> tensor([[1.6076, 1.0048, 1.0541, 1.3524, 1.0015],# │ [1.0413, 1.8352, 1.2328, 1.7904, 1.0088]])# └── x --> <FastTreeValue 0x7fdfa5836880># └── c --> tensor([[1.1550, 1.0963, 1.3555, 1.2030],# [1.0575, 1.4045, 1.0041, 1.0638],# [1.0782, 1.0037, 1.5075, 1.0658]]) For more quick start explanation and further usage, take a look at: Speed PerformanceHere is the speed performance of all the operations in
The following 2 tables are the performance comparison result with jax pytree.
This is the comparison between dm-tree, jax-libtree and us, with The following table is the performance comparison result with tianshou Batch.
And this is the comparison between tianshou Batch and us, with Test benchmark code can be found here: ExtensionIf you need to translate pip install potc-treevalue Or just install it with pip install treevalue[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 For more information, you can refer to ContributionWe appreciate all contributions to improve treevalue, both logic and system designs. Please refer to CONTRIBUTING.md for more guides. And users can join our slack communication channel, or contact the core developer HansBug for more detailed discussion. License
|
请发表评论