{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "flsf21MK3KTd" }, "source": [ "\n", "# Probabilistic gradient pruning\n", "
\n", "\n", "
\n", "\n", "Tutorial Author: Zirui Li, Hanrui Wang\n" ] }, { "cell_type": "markdown", "source": [ "bugs:\n", " - Directly run all. In the first epoch, the process will get stuck in the inference phase.\n", " - modify `torchquantum/plugins/qiskit_processor.py:228 parallel=True` to `parallel=False` to fix the bug.\n" ], "metadata": { "id": "7ZB2E7IfzHGQ" } }, { "cell_type": "markdown", "source": [ "## Outline\n", " - Introduction to probabilistic gradient pruning.\n", " - Train a model with gradient pruning." ], "metadata": { "id": "mWygf3uG6rOj" } }, { "cell_type": "markdown", "source": [ "## Introduction to probabilistic gradient pruning\n", "\n", "By carefully investigating the on-chip training process, we observe that small gradients tend to have large relative variations\n", "or even wrong directions under quantum noises. Also, not all gradient computations are necessary for the\n", "training process, especially for small-magnitude gradients. \n", "\n", "The observations provide great opportunities for us to boost the robustness and efficiency of QNN on-chip learning. Inspired by that, we\n", "propose a **probabilistic gradient pruning** method to predict and only\n", "compute gradients of high reliability. Hence we can reduce noise impact and also save the required number of circuit runs on real\n", "quantum machines.\n", "\n", "### Accumulation Window and Pruning Window\n", "\n", "We separate all the training epochs into a repeat of an accumulation window followed by a pruning window. There are three important hyper-parameters in our probabilistic gradient pruning method:\n", " - accumulation window width 𝑤𝑎,\n", " - pruning ratio 𝑟,\n", " - pruning window width 𝑤𝑝 .\n", "\n", "In the accumulation window, we collect the information of gradients in each training step. In each step of the pruning window, we probabilistically exempt the calculations of some gradients based on the information collected from the accumulation window and pruning ratio.\n", "\n", "