# batorch
## Introduction
[batorch](https://github.com/Bertie97/pyctlib/tree/main/batorch) is a package affiliated to project [`PyCAMIA`](https://github.com/Bertie97/pycamia). We encapsulated a new type on top of `torch` tensers, which we call it `batorch.Tensor`. It has the same function as `torch.Tensor`, but it can automatically select the device it was on and provide batch or channel dimensions. Also, we try to provide more useful module for torch users to make deep learning to be implemented more easily. It relies `python v3.6+` with `torch v 1.7.0+`. ***Note that `torch v1.7.0` was released in 2020,*** *and it is necessary for this package as the inheritance behavior for this version is different from previous versions.* Most original `torch` functions should be able to be applied for `batorch` tensors.
> Special features for `batorch` are still under development. If unknown errors pop our, please use traditional `torch` code to bypass it and meanwhile it would be very kind of you to let us know if anything is needed: please contact us by [e-mail](https://github.com/Bertie97/pycamia#Contributors).
```python
>>> import batorch as bt
>>> import batorch.nn as nn
>>> bt.turn_off_autodevice()
>>> bt.manual_seed(0)
<torch._C.Generator object at 0x1071b6730>
>>> t = bt.randn([3000], 400, requires_grad=True)
>>> LP = nn.Linear(400, 400)
>>> a = LP(t)
>>> a.sum().sum().backward()
>>> print(t.grad)
Tensor([[-0.2986, 0.0267, 0.9059, ..., 0.4563, -0.1291, 0.5702],
[-0.2986, 0.0267, 0.9059, ..., 0.4563, -0.1291, 0.5702],
[-0.2986, 0.0267, 0.9059, ..., 0.4563, -0.1291, 0.5702],
...,
[-0.2986, 0.0267, 0.9059, ..., 0.4563, -0.1291, 0.5702],
[-0.2986, 0.0267, 0.9059, ..., 0.4563, -0.1291, 0.5702],
[-0.2986, 0.0267, 0.9059, ..., 0.4563, -0.1291, 0.5702]], shape=batorch.Size([3000], 400))
```
`batorch` has all of following appealing features:
1. **Auto assign** the tensors to available `GPU` **device** by default.
2. Use `[nbatch]` or `{nchannel}` to specify **the batch and channel dimensions**. i.e. `tp.rand([4], {2}, 20, 30)` returns a 2-channel feature tensor of $20\times30$ matrices with batch size 4. One may also use `tensor.batch_dimension` to access (or assign) batch dimension, channel dimension can be operated likewise. If you find it hard to remember the symbol, just remember brackets enclose paralleled items in matrices hence it represents the batch dimension for paralleled calculation; braces enclose equation systems which are highly related hence it represents the channel (or feature) dimension.
3. Batch and channel dimension can help **auto matching the sizes** of two tensors in operations. For example, tensors of sizes `(3, [2], 4)` and `(3, 4)` can be automatically added together with axis of size 3 and 4 matched together. Some methods will also use this information. Sampling, for example, will take the batch dimension as priority.
4. The tensor object is **compatible with original `torch` functions**.
## Installation
This package can be installed by `pip install batorch` or moving the source code to the directory of python libraries (the source code can be downloaded on [github](https://github.com/Bertie97/pycamia) or [PyPI](https://pypi.org/project/batorch/)).
```shell
pip install batorch
```
## Usages
Not available yet, one may check the codes for usages.
## Acknowledgment
@ Yuncheng Zhou: Developer
@ Yiteng Zhang: Important functions extraction
Raw data
{
"_id": null,
"home_page": "https://github.com/Bertie97/PyZMyc/batorch",
"name": "batorch",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "pip, pymyc, batorch, torch, batch, batched data",
"author": "Yuncheng Zhou",
"author_email": "bertiezhou@163.com",
"download_url": "https://files.pythonhosted.org/packages/70/a6/fd7809afd13e18083d5f9314bd3a25be600f00fe846e2c1b064d8c04d34a/batorch-1.0.55.tar.gz",
"platform": "any",
"description": "# batorch\n\n## Introduction\n\n[batorch](https://github.com/Bertie97/pyctlib/tree/main/batorch) is a package affiliated to project [`PyCAMIA`](https://github.com/Bertie97/pycamia). We encapsulated a new type on top of `torch` tensers, which we call it `batorch.Tensor`. It has the same function as `torch.Tensor`, but it can automatically select the device it was on and provide batch or channel dimensions. Also, we try to provide more useful module for torch users to make deep learning to be implemented more easily. It relies `python v3.6+` with `torch v 1.7.0+`. ***Note that `torch v1.7.0` was released in 2020,*** *and it is necessary for this package as the inheritance behavior for this version is different from previous versions.* Most original `torch` functions should be able to be applied for `batorch` tensors. \n\n> Special features for `batorch` are still under development. If unknown errors pop our, please use traditional `torch` code to bypass it and meanwhile it would be very kind of you to let us know if anything is needed: please contact us by [e-mail](https://github.com/Bertie97/pycamia#Contributors). \n\n```python\n>>> import batorch as bt\n>>> import batorch.nn as nn\n>>> bt.turn_off_autodevice()\n>>> bt.manual_seed(0)\n<torch._C.Generator object at 0x1071b6730>\n>>> t = bt.randn([3000], 400, requires_grad=True)\n>>> LP = nn.Linear(400, 400)\n>>> a = LP(t)\n>>> a.sum().sum().backward()\n>>> print(t.grad)\nTensor([[-0.2986, 0.0267, 0.9059, ..., 0.4563, -0.1291, 0.5702],\n [-0.2986, 0.0267, 0.9059, ..., 0.4563, -0.1291, 0.5702],\n [-0.2986, 0.0267, 0.9059, ..., 0.4563, -0.1291, 0.5702],\n ...,\n [-0.2986, 0.0267, 0.9059, ..., 0.4563, -0.1291, 0.5702],\n [-0.2986, 0.0267, 0.9059, ..., 0.4563, -0.1291, 0.5702],\n [-0.2986, 0.0267, 0.9059, ..., 0.4563, -0.1291, 0.5702]], shape=batorch.Size([3000], 400))\n```\n\n`batorch` has all of following appealing features:\n\n1. **Auto assign** the tensors to available `GPU` **device** by default. \n2. Use `[nbatch]` or `{nchannel}` to specify **the batch and channel dimensions**. i.e. `tp.rand([4], {2}, 20, 30)` returns a 2-channel feature tensor of $20\\times30$ matrices with batch size 4. One may also use `tensor.batch_dimension` to access (or assign) batch dimension, channel dimension can be operated likewise. If you find it hard to remember the symbol, just remember brackets enclose paralleled items in matrices hence it represents the batch dimension for paralleled calculation; braces enclose equation systems which are highly related hence it represents the channel (or feature) dimension. \n3. Batch and channel dimension can help **auto matching the sizes** of two tensors in operations. For example, tensors of sizes `(3, [2], 4)` and `(3, 4)` can be automatically added together with axis of size 3 and 4 matched together. Some methods will also use this information. Sampling, for example, will take the batch dimension as priority.\n4. The tensor object is **compatible with original `torch` functions**. \n\n## Installation\n\nThis package can be installed by `pip install batorch` or moving the source code to the directory of python libraries (the source code can be downloaded on [github](https://github.com/Bertie97/pycamia) or [PyPI](https://pypi.org/project/batorch/)). \n\n```shell\npip install batorch\n```\n\n## Usages\n\nNot available yet, one may check the codes for usages.\n\n## Acknowledgment\n\n@ Yuncheng Zhou: Developer\n@ Yiteng Zhang: Important functions extraction\n",
"bugtrack_url": null,
"license": "MIT Licence",
"summary": "'batorch' is an extension of package torch, for tensors with batch dimensions.",
"version": "1.0.55",
"project_urls": {
"Homepage": "https://github.com/Bertie97/PyZMyc/batorch"
},
"split_keywords": [
"pip",
" pymyc",
" batorch",
" torch",
" batch",
" batched data"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1f01b9db5d328e2eae3fe71a7ac145400ce53d09b47889406dc47fbca08a164e",
"md5": "8207283a4c3ede797afff6a44a374d03",
"sha256": "14375425a133c7699b844f599f4cc9b9604a64bdd7d92e3138914c3710f639e1"
},
"downloads": -1,
"filename": "batorch-1.0.55-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8207283a4c3ede797afff6a44a374d03",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 351504,
"upload_time": "2024-12-24T08:23:11",
"upload_time_iso_8601": "2024-12-24T08:23:11.719314Z",
"url": "https://files.pythonhosted.org/packages/1f/01/b9db5d328e2eae3fe71a7ac145400ce53d09b47889406dc47fbca08a164e/batorch-1.0.55-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "70a6fd7809afd13e18083d5f9314bd3a25be600f00fe846e2c1b064d8c04d34a",
"md5": "96f7d41972f979f74c4b541f151a8ea7",
"sha256": "4481edec88ff064b6dc15542f4b2296beaa3f0c12a4f640ca5c5e018343bc9de"
},
"downloads": -1,
"filename": "batorch-1.0.55.tar.gz",
"has_sig": false,
"md5_digest": "96f7d41972f979f74c4b541f151a8ea7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 335725,
"upload_time": "2024-12-24T08:23:20",
"upload_time_iso_8601": "2024-12-24T08:23:20.704112Z",
"url": "https://files.pythonhosted.org/packages/70/a6/fd7809afd13e18083d5f9314bd3a25be600f00fe846e2c1b064d8c04d34a/batorch-1.0.55.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-24 08:23:20",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Bertie97",
"github_project": "PyZMyc",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "batorch"
}