Files
experiments_codebase/baselines/agzo/README.md
T
gloamxun e0feabec8f Initialize optimizer research workspace with official baselines and history-free coverage
Vendor pinned MeZO, AGZO, LOZO and LoREN sources with independent environments. Add direct in-place fix/adjust/node training, derived history-free basis gradients, development-best checkpoints and experiment tooling. Keep models, datasets, caches and credentials outside Git.

Validation: 93 project tests passed; 521 vendored author files verified.
2026-11-12 23:32:33 +08:00

74 lines
4.6 KiB
Markdown

ActivationGuidedZO-NPU: Activation-Guided Zeroth-Order Optimization for LLM Fine-Tuning(NPU)
=================================================
[License: GPL v3](https://www.gnu.org/licenses/gpl-3.0) \
[License: OPENPANGU MODEL LICENSE AGREEMENT VERSION 1.0](/openPangu%20LICENSE)
This repository is built to benchmark ActivationGuidedZO/ZO-LLM performance on openPangu-embedeb-1B. It extends the ZO-LLM benchmark with Activation-Guided Zeroth-Order optimization (ActivationGuidedZO). It remains under GPLv3: any distribution or modification must keep GPLv3 terms and notices. The training loop and README were forked from ZO-LLM (https://github.com/ZO-Bench/ZO-LLM); ActivationGuidedZO logic was added in [zo-bench/trainer.py](zo-bench/trainer.py), and this README was rewritten accordingly.
Table of Contents
-----------------
1. Overview
2. ActivationGuidedZO at a Glance
3. What's New in This Fork
4. Repository Layout
5. Setup
6. Root Scripts
7. Licenses and Attribution
8. Citation
## 1) Overview
This fork builds on the "Revisiting Zeroth-Order Optimization for Memory-Efficient LLM Fine-Tuning: A Benchmark" codebase to deliver Activation-Guided Zeroth-Order Optimization (ActivationGuidedZO). ZO-LLM benchmarks backpropagation-free, memory-efficient fine-tuning across OPT, LLaMA/Vicuna, Mistral, and RoBERTa families on classification and reasoning tasks. ActivationGuidedZO aligns perturbations with activation subspaces via lightweight power iteration, improving gradient direction quality without increasing memory beyond near-inference levels.
## 2) ActivationGuidedZO at a Glance
- Guided basis: For each linear layer, a forward hook captures activations, reshapes to (batch*seq, hidden), and runs a few power-iteration steps to approximate the top activation direction.
- Rank-1 perturbation: Builds $P_l = r_l u_l^T$ with a regenerated random vector $r_l$ and stored direction $u_l$, keeping storage minimal.
- Two-point estimate: Evaluates $L_+$ and $L_-$ with $\pm \epsilon P$ and forms the projected gradient $(L_+ - L_-)/(2\epsilon)$.
- Memory-saving tricks: Uses a single random seed to reconstruct $r_l$ in-place and discards activations after the basis is computed; only $u_l$ vectors are kept.
## 3) What's New in This Fork
- ActivationGuidedZO trainer with configurable `agzo_power_iter_steps` and activation hooks that store only principal directions.
- Rank-1 perturbation path integrated into the training loop with the same LR scheduling as other ZO optimizers.
- Experiment tagging that records ActivationGuidedZO settings for sweeps.
- Scripts targeting NPU runs (see run_*_pangu-1b.sh) plus updated documentation.
## 4) Repository Layout
- [zo-bench/run.py](zo-bench/run.py): Entry point for training and evaluation.
- [zo-bench/trainer.py](zo-bench/trainer.py): Optimizers and training loop; ActivationGuidedZO implementation lives here.
- [zo-bench/tasks.py](zo-bench/tasks.py) and [zo-bench/templates.py](zo-bench/templates.py): Task definitions and prompt templates.
- [zo-bench/sweeps](zo-bench/sweeps): Hyperparameter sweeps organized by task, model, optimizer, and tuning scheme.
## 5) Setup
```bash
conda create -n zollm python=3.10
conda activate zollm
pip install -r requirements.txt
```
## 6) Root Scripts
- `run_agzo_pangu-1b.sh`: ActivationGuidedZO training/eval entry tailored for Pangu-1B NPUs.
- `run_fo_pangu-1b.sh`: Forward-gradient baseline on Pangu-1B.
- `run_lozo_pangu-1b.sh`: Low-Rank ZO (LOZO) baseline on Pangu-1B.
- `run_zo_sgd_pangu-1b.sh`: ZO-SGD baseline on Pangu-1B.
- `run_icl_pangu-1b.sh`: In-context learning routines on Pangu-1B.
- `run_zeroshot_pangu-1b.sh`: Zero-shot pipeline that can also be used for direct inference without fine-tuning.
## 7) Licenses and Attribution
- Code license: GPLv3 (see LICENSE). Redistributions and derivatives must retain GPLv3 terms and notices.
- Model license: OPENPANGU MODEL LICENSE AGREEMENT VERSION 1.0 applies to model assets (see link above).
- Upstream origin: Forked from ZO-LLM (https://github.com/ZO-Bench/ZO-LLM). The baseline training loop in [zo-bench/trainer.py](zo-bench/trainer.py) and this README were derived from the upstream project and modified here to add ActivationGuidedZO.
## 8) Citation
If you use this work, please cite the original ActivationGuidedZO paper:
```
@misc{lin2026agzoactivationguidedzerothorderoptimization,
title={AGZO: Activation-Guided Zeroth-Order Optimization for LLM Fine-Tuning},
author={Wei Lin and Yining Jiang and Qingyu Song and Qiao Xiang and Hong Xu},
year={2026},
eprint={2601.17261},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/2601.17261},
}
```