Skip to main content

Nytorch enhances PyTorch with advanced particle operations, seamlessly integrating new functionalities for effortless compatibility and enrichment.

Project description

Introduction

Nytorch enriches PyTorch with advanced particle operations through nytorch.NytoModule, seamlessly integrated with torch.nn.Module. It enhances PyTorch without redundancy, allowing effortless integration by simply inheriting from nytorch.NytoModule instead of torch.nn.Module. This ensures full compatibility with existing methods while unlocking powerful new functionalities.

Below is a simple example:

import nytorch
import torch

class NytoLinear(nytorch.NytoModule):
    def __init__(self) -> None:
        super().__init__()
        self.weight = torch.nn.Parameter(torch.Tensor([2.]))
        self.bias = torch.nn.Parameter(torch.Tensor([1.]))

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        return self.weight * x + self.bias

net: NytoLinear = NytoLinear()

Particle operation allows the model to perform operations similar to tensors to obtain a new model. For example, net obtains a new NytoLinear instance through particle operation:

net2: NytoLinear = net + 10

Compare the parameters of net and net2:

print(net.weight)   # Parameter containing: tensor([2.], requires_grad=True)
print(net2.weight)  # Parameter containing: tensor([12.], requires_grad=True)
print(net.bias)     # Parameter containing: tensor([1.], requires_grad=True)
print(net2.bias)    # Parameter containing: tensor([11.], requires_grad=True)

We can observe that the result of adding a scalar to the model is equivalent to applying the scalar to all parameters of the model. Similar principles apply to other arithmetic operations such as subtraction or multiplication. When the operands are models, the operation acts on corresponding parameter positions:

net3: NytoLinear = net + net2

print(net3.weight)  # Parameter containing: tensor([14.], requires_grad=True)
print(net3.bias)    # Parameter containing: tensor([12.], requires_grad=True)

So, algorithms that might have been difficult to implement in the past can now be implemented elegantly and simply through Nytorch.

Installation

Nytorch is a tool developed based on PyTorch. Before installing Nytorch, please ensure that you have installed PyTorch version 1.7 or higher, and are using Python version 3.8 or higher.

You can install Nytorch via PyPi:

pip install nytorch

Documentation

For detailed documentation and usage instructions, please visit ReadTheDocs.

Author(jimmyzzzz)

gmail: sciencestudyjimmy@gmail.com github: https://github.com/jimmyzzzz

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

nytorch-1.1.0.tar.gz (33.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nytorch-1.1.0-py3-none-any.whl (47.1 kB view details)

Uploaded Python 3

File details

Details for the file nytorch-1.1.0.tar.gz.

File metadata

  • Download URL: nytorch-1.1.0.tar.gz
  • Upload date:
  • Size: 33.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for nytorch-1.1.0.tar.gz
Algorithm Hash digest
SHA256 c132a9d6675e840b847929eeb46a5553ab3bcd0e13df58f7c8002dac50d59102
MD5 eb1c90439cb81adffdae88d5345e4885
BLAKE2b-256 4929f8dc90f12552deacf35ef326afda1eedaa02c4be742da484eb0e8b55fa1d

See more details on using hashes here.

File details

Details for the file nytorch-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: nytorch-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 47.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for nytorch-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 002c9fff29b910d13e71fd2c206b3df966faba1d9c7282ba37fe11b39b48d462
MD5 156e88509f7d039990b0c9384d573ec9
BLAKE2b-256 bacefebe7cd2c410055152451f865a69d5e7a7a792ae454da4a4a463d58e1ef9

See more details on using hashes here.

Supported by

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