Performance Analysis of Models Using AWS Trainium and TorchNeuron

This article introduces the performance analysis method of TorchNeuron utilizing AWS Trainium. It systematically analyzes the causes of slow model performance and explains the features of TorchNeuron. Additionally, it covers how to visualize performance data using Neuron Explorer.

Introduction

Recently, optimizing the performance of artificial intelligence (AI) models has become an important task for machine learning (ML) practitioners. In particular, performance analysis using dedicated AI chips like AWS Trainium is essential for maximizing model efficiency. This report will delve deeply into the performance analysis methods of TorchNeuron based on AWS Trainium.

Overview of TorchNeuron

TorchNeuron is an open-source native PyTorch backend for AWS Trainium. This backend supports the standard workflow of PyTorch and provides various features without code changes. TorchNeuron integrates with the Neuron Kernel Interface (NKI) to enable custom operators and performance optimization. As a result, ML practitioners can more easily analyze model performance.

Setup for Performance Analysis

Before starting performance analysis, it is important to understand how TorchNeuron integrates with PyTorch. The NeuronConfig object controls the Neuron data stream and NeuronCore, and is passed to torch.profiler.profile as experimental_config. This allows ML practitioners to collect and analyze performance data.

Steps for Performance Analysis

1. Setting NeuronConfig: Set up the data stream to be collected and NeuronCore through NeuronConfig. This setup is passed to torch.profiler.profile to perform performance analysis. 2. Calling Profiler: Call the Profiler to collect activities on the Neuron backend. At this time, activities on the Neuron device, including ProfilerActivity.PrivateUse1, are recorded. 3. Analyzing key_averages() Table: The analysis results appear in the key_averages() table, where the time consumed by each operation can be compared.

Utilizing Neuron Explorer

Neuron Explorer is a browser-based viewer for system traces, device timelines, and engine-specific analysis. Through this tool, ML practitioners can visually confirm performance data and track the execution process of each operation. For example, when analyzing the performance of the RMSNorm operation, the execution times of each ATen operation can be checked through Neuron Explorer.

Analyzing RMSNorm Operation

To analyze the RMSNorm operation, three implementations were compared. Each implementation used the same input and profiler configuration for direct comparison of results.

This analysis revealed that in the case of Naive RMSNorm, the aten::mul call consumed the most Neuron device time.

OperationNeuron Device Time (ms)
aten::mul2.355
aten::mean0.500
aten::add0.300
aten::rsqrt0.200

Conclusion

Performance analysis using AWS Trainium and TorchNeuron offers ML practitioners new opportunities for model optimization. By visualizing performance data with tools like Neuron Explorer and analyzing the execution process of each operation, model efficiency can be maximized. These analysis methods will become essential elements in future AI model development.

Our take

The integration of AWS Trainium and TorchNeuron presents a new paradigm for AI model performance analysis. Utilizing these technologies allows for more effective exploration of optimization opportunities.

Open questions

Source

Back to catalog