# myay/binarizedneuralnetworks-training architecture

> Architecture diagram of the GitHub repository myay/binarizedneuralnetworks-training, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/myay/binarizedneuralnetworks-training
- Repository: https://github.com/myay/binarizedneuralnetworks-training

## Overview

BNN-Training trains and evaluates binary neural networks on FashionMNIST. The principal workflow in `run_fashion.py` loads the dataset, selects a CNN or fully connected model and CPU or CUDA binarization, then trains and tests the model across epochs. Model layers apply quantized weights and activations; the CUDA option delegates binarization to the extension. The README also documents CPU-only operation and both model choices. The CUDA kernel implementation and some runtime details were not sampled, so only documented or directly evidenced links are shown.

Main entry points: [`run_fashion.py`](https://github.com/myay/binarizedneuralnetworks-training/blob/main/run_fashion.py) (Train and evaluate), [`code/python/QuantizedNN.py`](https://github.com/myay/binarizedneuralnetworks-training/blob/main/code/python/QuantizedNN.py) (Quantized layers), [`code/python/BNNmodels.py`](https://github.com/myay/binarizedneuralnetworks-training/blob/main/code/python/BNNmodels.py) (CNN model), [`code/cuda/binarizationPM1/binarizePM1.cpp`](https://github.com/myay/binarizedneuralnetworks-training/blob/main/code/cuda/binarizationPM1/binarizePM1.cpp) (CUDA binding)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Training workflow"]
  node_runner["Train and evaluate<br/>[run_fashion.py]"]
end

subgraph group_data["FashionMNIST data"]
  node_fashion[("FashionMNIST")]
  node_loader["Data loaders<br/>[run_fashion.py]"]
end

subgraph group_models["Network models"]
  node_cnn["CNN model<br/>[BNNmodels.py]"]
  node_fc["Fully connected model<br/>[BNNmodels.py]"]
end

subgraph group_quant["Quantization"]
  node_quant_layers["Quantized layers<br/>[QuantizedNN.py]"]
  node_quantizer["Quantization selector<br/>[run_fashion.py]"]
  node_cpu_bin["CPU binarization<br/>[run_fashion.py]"]
  node_cuda_bind["CUDA binding<br/>[binarizePM1.cpp]"]
end

node_user(("Training user"))
node_torch["PyTorch runtime"]

node_user -->|"starts training"| node_runner
node_runner -->|"downloads and loads"| node_fashion
node_runner -->|"builds loaders"| node_loader
node_loader -->|"supplies batches"| node_runner
node_runner -->|"selects CNN"| node_cnn
node_runner -->|"selects FC model"| node_fc
node_runner -->|"selects binarizer"| node_quantizer
node_runner -->|"uses training runtime"| node_torch
node_cnn -->|"uses quantized layers"| node_quant_layers
node_fc -->|"uses quantized layers"| node_quant_layers
node_quant_layers -->|"quantizes weights and activations"| node_quantizer
node_quantizer -->|"uses CPU option"| node_cpu_bin
node_quantizer -->|"calls CUDA option"| node_cuda_bind

click node_runner "https://github.com/myay/binarizedneuralnetworks-training/blob/main/run_fashion.py"
click node_loader "https://github.com/myay/binarizedneuralnetworks-training/blob/main/run_fashion.py"
click node_cnn "https://github.com/myay/binarizedneuralnetworks-training/blob/main/code/python/BNNmodels.py"
click node_fc "https://github.com/myay/binarizedneuralnetworks-training/blob/main/code/python/BNNmodels.py"
click node_quant_layers "https://github.com/myay/binarizedneuralnetworks-training/blob/main/code/python/QuantizedNN.py"
click node_quantizer "https://github.com/myay/binarizedneuralnetworks-training/blob/main/run_fashion.py"
click node_cpu_bin "https://github.com/myay/binarizedneuralnetworks-training/blob/main/run_fashion.py"
click node_cuda_bind "https://github.com/myay/binarizedneuralnetworks-training/blob/main/code/cuda/binarizationPM1/binarizePM1.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_runner,node_user toneBlue
class node_fashion,node_loader toneAmber
class node_cnn,node_fc toneMint
class node_quant_layers,node_quantizer,node_cpu_bin,node_cuda_bind toneRose
class node_torch toneIndigo
```

## Components

### Training workflow

- [Train and evaluate](https://github.com/myay/binarizedneuralnetworks-training/blob/main/run_fashion.py): `run_fashion.py`

### FashionMNIST data

- **FashionMNIST**
- [Data loaders](https://github.com/myay/binarizedneuralnetworks-training/blob/main/run_fashion.py): `run_fashion.py`

### Network models

- [CNN model](https://github.com/myay/binarizedneuralnetworks-training/blob/main/code/python/BNNmodels.py): `code/python/BNNmodels.py`
- [Fully connected model](https://github.com/myay/binarizedneuralnetworks-training/blob/main/code/python/BNNmodels.py): `code/python/BNNmodels.py`

### Quantization

- [Quantized layers](https://github.com/myay/binarizedneuralnetworks-training/blob/main/code/python/QuantizedNN.py): `code/python/QuantizedNN.py`
- [Quantization selector](https://github.com/myay/binarizedneuralnetworks-training/blob/main/run_fashion.py): `run_fashion.py`
- [CPU binarization](https://github.com/myay/binarizedneuralnetworks-training/blob/main/run_fashion.py): `run_fashion.py`
- [CUDA binding](https://github.com/myay/binarizedneuralnetworks-training/blob/main/code/cuda/binarizationPM1/binarizePM1.cpp): `code/cuda/binarizationPM1/binarizePM1.cpp`

### Other components

- **Training user**
- **PyTorch runtime**

## Connections

- Training user → Train and evaluate: starts training
- Train and evaluate → FashionMNIST: downloads and loads
- Train and evaluate → Data loaders: builds loaders
- Data loaders → Train and evaluate: supplies batches
- Train and evaluate → CNN model: selects CNN
- Train and evaluate → Fully connected model: selects FC model
- Train and evaluate → Quantization selector: selects binarizer
- Train and evaluate → PyTorch runtime: uses training runtime
- CNN model → Quantized layers: uses quantized layers
- Fully connected model → Quantized layers: uses quantized layers
- Quantized layers → Quantization selector: quantizes weights and activations
- Quantization selector → CPU binarization: uses CPU option
- Quantization selector → CUDA binding: calls CUDA option
