Skip to main content

'batorch' is an extension of package torch, for tensors with batch dimensions.

Project description

batorch

Introduction

batorch is a package affiliated to project 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.

>>> 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 or PyPI).

pip install batorch

Usages

Not available yet, one may check the codes for usages.

Acknowledgment

@ Yuncheng Zhou: Developer @ Yiteng Zhang: Important functions extraction

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

batorch-1.0.33.tar.gz (262.7 kB view details)

Uploaded Source

Built Distribution

batorch-1.0.33-py3-none-any.whl (284.2 kB view details)

Uploaded Python 3

File details

Details for the file batorch-1.0.33.tar.gz.

File metadata

  • Download URL: batorch-1.0.33.tar.gz
  • Upload date:
  • Size: 262.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.1

File hashes

Hashes for batorch-1.0.33.tar.gz
Algorithm Hash digest
SHA256 27bf9428ed03c71b294e352abac03d7475eaa86d34d36c2427e9fd5c2540b7c8
MD5 dfb1c364ebb47adab0a1558353a6c448
BLAKE2b-256 e624f73ff6adc7e8710b8828cbdbdc7a8261e3c223e874aab20168d7d3df53cb

See more details on using hashes here.

File details

Details for the file batorch-1.0.33-py3-none-any.whl.

File metadata

  • Download URL: batorch-1.0.33-py3-none-any.whl
  • Upload date:
  • Size: 284.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.1

File hashes

Hashes for batorch-1.0.33-py3-none-any.whl
Algorithm Hash digest
SHA256 a5363dda0491d3a58fb26cea0968d6f036fab2c92d5ec7fb86259cb9ef6b4aae
MD5 0717d946cc0ba45ccadcdf15e91159e8
BLAKE2b-256 c9da1a433630aa02fb81d81dec9f0b05dd0d3c422b8af1117e9b31a9f92a9fae

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page