# Debugging a simple MPI application

## Outline

1. The Example: Two Layer Neural Network
2. Setting up the Python environment
3. Launching the application to Debug with Linaro DDT

----

## 1. The Example: Two Layer Neural Network

This Python script manually implements a simple two-layer neural network using PyTorch tensors to fit random data. It explicitly calculates the gradients and updates weights from scratch, demonstrating the core mechanics of backpropagation without using PyTorch's built-in automatic differentiation.

----

## 2. Setting up the Python environment

Create a virtual python environment and install Pytorch

```python
python -m venv /path/to/new/virtual/environment
. .venv/bin/activate
pip install torch
pip install numpy
```

----

## 3. Launching the application to Debug with Linaro DDT

```bash
FORGE_STOP_AT_MAIN=1 ddt --connect --np 2 --mpi="generic" --mpiargs="--oversubscribe" $(which python) %allinea_python_debug% 2_layer_net.py
```

## 4. Debug the PyTorch Application

![image_alt](screenshots/pytorch.png)