Skip to main content

MindTorch is a toolkit for support the PyTorch model running on Ascend.

Project description

Introduction
=============
MindTorch is MindSpore tool for adapting the PyTorch interface, which is designed to make PyTorch code perform efficiently on Ascend without changing the habits of the original PyTorch users.

|MindTorch-architecture|

Install
=======

MindTorch has some prerequisites that need to be installed first, including MindSpore, PIL, NumPy.

.. code:: bash

# for last stable version
pip install mindtorch

# for latest release candidate
pip install --upgrade --pre mindtorch

Alternatively, you can install the latest or development version by directly pulling from OpenI:

.. code:: bash

pip3 install git+https://openi.pcl.ac.cn/OpenI/MSAdapter.git

User guide
===========
You can start using it straight away, for example:

Import mstorch_enable in the main program of the code file to adapt PyTorch code to MindTorch

.. code:: python

from mindtorch.tools import mstorch_enable # It needs to be used before importing torch related modules in the main program

import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import datasets, transforms

class LeNet(nn.Module):
def __init__(self):
super(LeNet, self).__init__()
self.conv1 = nn.Conv2d(3, 16, 5)
self.pool1 = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(16, 32, 5)
self.pool2 = nn.MaxPool2d(2, 2)
self.fc1 = nn.Linear(32*5*5, 120)
self.fc2 = nn.Linear(120, 84)
self.fc3 = nn.Linear(84, 10)

def forward(self, x):
x = F.relu(self.conv1(x))
x = self.pool1(x)
x = F.relu(self.conv2(x))
x = self.pool2(x)
x = x.view(-1, 32*5*5)
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = self.fc3(x)
return x

criterion = nn.CrossEntropyLoss()

transform = transforms.Compose(
[transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])

train_set = datasets.CIFAR10(root='./data', train=True, download=True, transform=transform)
train_data = DataLoader(train_set, batch_size=128, shuffle=True, num_workers=2, drop_last=True)

After importing mstorch_enable, the imported module with the same name of torch will be automatically converted to the corresponding module of mindtorch when the code is executed (currently supports automatic conversion of torch, torchvision, torchaudio related modules), and then execute the .py file of the main program. For more information on how to use it, please refer to User's Guide.


License
=======

MindTorch is released under the Apache 2.0 license.

.. |MindTorch-architecture| image:: https://openi.pcl.ac.cn/OpenI/MSAdapter/raw/branch/master/doc/readthedocs/source_zh/docs/pic/MSA_F.png

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

mindtorch-0.4.0-py2.py3-none-any.whl (1.4 MB view details)

Uploaded Python 2 Python 3

File details

Details for the file mindtorch-0.4.0-py2.py3-none-any.whl.

File metadata

  • Download URL: mindtorch-0.4.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.18

File hashes

Hashes for mindtorch-0.4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 99fb74d6b646d1858a9c3369858f232e4e861e44ea3e7709ab8f7a1436b39dba
MD5 21b77ced4ab249a1f797c36eba455a9a
BLAKE2b-256 4c8a67bb218d50898f3a5ec8cc4fc3140c6de463c358b986b4519c92d810ec77

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