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 Distribution

mindtorch-0.3.0.tar.gz (1.1 MB view details)

Uploaded Source

Built Distributions

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

Uploaded Python 3

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

Uploaded Python 2 Python 3

File details

Details for the file mindtorch-0.3.0.tar.gz.

File metadata

  • Download URL: mindtorch-0.3.0.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for mindtorch-0.3.0.tar.gz
Algorithm Hash digest
SHA256 eda347e836bc35e8efd71740072c93c7ce2e739cb93836bf442847515f86134f
MD5 6a69981138b04e73a60a81274839127b
BLAKE2b-256 9de84fc4baf39a413814fb8424baaa257266ca493bbebbfe53e1f67833b464a2

See more details on using hashes here.

File details

Details for the file mindtorch-0.3.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for mindtorch-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d66620d8b85eb6ffd35c286d6531810fc21051729dcfececef829c409278179b
MD5 438ff021b1f5fedb697d64dcdbe8af86
BLAKE2b-256 7b60946c5d1632f33c88183e0820086c22c360acc120fdc4efa8f5b90994eab4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mindtorch-0.3.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.0.0 CPython/3.9.18

File hashes

Hashes for mindtorch-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fbdfdbc2943259d9d59860c727d8e6edf3c765629485407812485cd1e6f7d20b
MD5 69062af34a2bb77f8aedf0342fd6bef4
BLAKE2b-256 ea2d26dfe65118edd15d58ad75618fae92423c0d5cfc1c586583c9186af145ef

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