Updated April 4, 2023
Introduction to PyTorch AMD
PyTorch is the framework used for tensor computation and is accelerated by GPU. It has its front end made up of python. On the other hand, AMD (Advanced Micro Devices) is an open-source platform, and PyTorch’s functionalities and capabilities can be extended simply by using the libraries of python. AMD that is Automatic Differentiation, is one such platform supported by PyTorch AMD, is used by using tape-based systems. This includes doing some changes at neural and functional level layers of the neural network.
In this article, we will try to dive into the topic of PyTorch AMD and will try to understand What is PyTorch AMD, how to use PyTorch AMD, image classification models in AMD, its associated examples, and finally give our concluding statement on it.
What is PyTorch AMD?
PyTorch AMD is the container of the framework, allowing us to run the container of AMD’s machine learning framework. For doing so, it is necessary that the docker environment of your system should support the AMD GPU.
The minimum requirements of the single node server are that it should have X86-64 CPU or CPUs along with GPU(s) of AMD instinct MI100 and GPU of Radeon instinct MI50 (S). The operating system used for this should be Centos 8.3 or higher OR Ubuntu 18.04 or higher version. The driver for ROCm should be compatible with the 4.2 version, and the Docker Engine Singularity container is used at runtime.
By default, the considerations and suppositions made by PyTorch AMD container of frameworks are that the server should contain x-86-64 single or multiple CPUs and should have a minimum of one listing AMD GPU. Furthermore, to run the docker container, the server should have the listed ROCm driver with a specified or higher version installed on it and the required operating system. Finally, the server should contain the docker engine in it to run the container.
If you want to go for installing the Docker engine, kindly visit this link. In order to install singularity in its latest version, if the use of singularity is already planned, then visit this link. For installation of procedures of ROCm as well as validity checks, kindly go through this link.
How to Use PyTorch AMD?
AMD is an open-source platform and has high performance and flexibility. It comes along with various libraries, compilers, and languages that can be used by developers and communities working in Machine Learning, Artificial Intelligence, and HPC technology to make their task of coding easy, fast, and implementing complex logic and functionalities in it. The biggest task is that PyTorch AMD provides you with containers.
In order to get and run the container in PyTorch AMD, we can make use of the following command –
Docker pull “name of the container”
For example, for AMDih container of PyTorch, the command would be –
docker pull AMDih / PyTorch : rocm4.2_ubuntu18.04_py3.6_PyTorch_1.9.0
Image classification models in AMD
Broadly, image classification can be done by using either of the two technologies of PyTorch or tensorflow in AMD. Some of the products include AMD Radeon instinct MI50, AMD Instinct MI100, while for tensorflow same products can be used.
There are various models that can be used in AMD for image classifications. Some of them are as listed below –
- Efficent b0 and b7
- Resnet 101 and 50
- Inceptive v3
For running a particular image container in PyTorch AMD, you will have to give a check on the operating system on which you have installed and the software and its version that you have installed in the process of running the containers of AMD. Some of the steps that need to be followed for running the containers are as given below –
- A search of the tab named Tags and then hit into the container image release that is located inside it, which you are about to run.
- Now, inside the column of the pull tag, try clicking on the command icon, which will help you copy the docker pull command.
- You will have to paste the command you have copied by opening a command prompt in your system. At this step, the beginning of pulling the image of the container happens. Before you go for the next step, make sure that the pulling of the docker completes.
- Now, the container image that is pulled should be run. For running the container, you will have to choose the mode of interactive or non-interactive as per necessity and scenario.
- While running the command, the “-it” parameter stands for the interactive mode running.
- The option “–rm” specifies that the container should be deleted after finishing.
- The parameter “-v” is used for specifying the directory for mounting.
- The absolute path to the file or directory of the host system, which we will need to access in the container, is specified by using the parameter local_dir.
- The target directory’s absolute path is specified by using the container_dir parameter when you are present in the container.
- xx is the version of the container.
- When you want to run particular command inside the image, the command parameter should be specified.
Examples of PyTorch AMD
Let us consider one example of PyTorch AMD –
def sampleEducbaExample(args, educbaModel, sampleEducbaExample_loader):
educbaModel.eval()
corectionPrecision = 0
cumulativeCount = 0
with torch.no_grad():
for data, target in sampleEducbaExample_loader:
achievedOutput = educbaModel(data)
predictedValue = achievedOutput.argmax(dim=1)
corectionPrecision += predictedValue.eq(target.view_as(predictedValue)).sum()
cumulativeCount += args.sampleEducbaExample_batch_size
cumulativeCorrections = corectionPrecision.copy().get().float_precision().long().item()
print('Test set: Accuracy: {}/{} ({:.0f}%)'.format(
cumulativeCorrections, cumulativeCount,
100. * cumulativeCorrections / cumulativeCount))
The output of the execution of the above program gives the following result on the console panel –
Here, we have carried out the predictions in a secure manner from end to end. Both server and client are completely unaware. The server has no idea about the output of classification and input of data, and the client is not aware of the server’s model weights.
Conclusion
We can use PyTorch AMD to improve the user’s data protection and secure machine learning. The docker container of PyTorch 3.6 internally provides AMD support.
Recommended Articles
This is a guide to PyTorch AMD. Here we discuss What is PyTorch AMD, how to use PyTorch AMD, image classification models in AMD. You may also have a look at the following articles to learn more –