Gradient Analysis Plotting
This folder contains the plotting utilities for the gradient-analysis workflow.
There are two plotting entry points:
- pulls one W&B run directly
- exports local
json/csv - writes per-step PNG plots
- builds a fixed 3-step comparison figure from already-exported
metrics.jsonfiles - intended for paper-style summary figures
For the training-side workflow and arguments, see:
Current default training behavior from config/base.yaml:
trainer.gradient_analysis_mode=Truetrainer.gradient_analysis_every=50trainer.gradient_analysis_env_groups=nulltrainer.gradient_analysis_group_size=nulltrainer.exit_after_gradient_analysis=False
Typical Workflow
1. Run one analysis job
Example helper runner:
bash scripts/runs/run_sokoban_ppo_filter_grad_analysis.sh \
--gpus 0,1,2,3,4,5,6,7
That job:
- trains for
101steps - validates before training and every
10steps - runs gradient analysis at steps
1,51, and101 - uses a training batch of
8x16 - uses a separate gradient-analysis batch of
128x16
2. List available analysis steps in W&B
python gradient_analysis/plot_gradient_analysis.py \
--wandb-path deimos-xing/ragen_gradient_analysis/<run_id> \
--list-steps
3. Plot all analysis steps from that run
python gradient_analysis/plot_gradient_analysis.py \
--wandb-path deimos-xing/ragen_gradient_analysis/<run_id>
Default output directory:
gradient_analysis_outputs/<run_name>_<run_id>/
4. Plot only one step
python gradient_analysis/plot_gradient_analysis.py \
--wandb-path deimos-xing/ragen_gradient_analysis/<run_id> \
--step 1
5. Choose your own output directory
python gradient_analysis/plot_gradient_analysis.py \
--wandb-path deimos-xing/ragen_gradient_analysis/<run_id> \
--step 1 \
--output-dir gradient_analysis_outputs/my_custom_dir
Files Produced By gradient_analysis/plot_gradient_analysis.py
For each selected step, the script writes:
gradient_analysis_summary_step_<N>.pnggradient_analysis_plots_step_<N>.pnggradient_analysis_loss_plots_step_<N>.pnggradient_analysis_reward_std_step_<N>.pnggradient_analysis_normed_grads_step_<N>.pnggradient_analysis_metrics_step_<N>.jsongradient_analysis_bucket_rv_table_step_<N>.csv
The metrics.json export is the bridge to the paper-style plotting script.
Building A 3-Step Comparison Figure
If you have three exported step directories and want the fixed grid figure:
python gradient_analysis/plot_icml_steps.py \
--mode ppo \
--step0-dir /path/to/step0 \
--step20-dir /path/to/step20 \
--step40-dir /path/to/step40 \
--out gradient_analysis_outputs/ppo_step0_20_40.png
Each step directory must contain:
metrics.json
If your exported file is named gradient_analysis_metrics_step_<N>.json, copy or rename it to metrics.json inside each step directory before calling plot_icml_steps.py.
What To Inspect First
For a new run, start with:
gradient_analysis_summary_step_<N>.pnggradient_analysis_plots_step_<N>.pnggradient_analysis_metrics_step_<N>.json
Those three are usually enough to tell:
- how many buckets were populated
- whether task gradients dominate regularizer gradients
- whether gradient magnitude is monotonic or non-monotonic in reward variance