Temporal Gradient Inversion for Private Trajectory Reconstruction in Embodied Reinforcement Learning
Sudip Bhujel1, Shanghao Shi2, Ruiquan Huang1, Ning Zhang2, Yang Xiao1
1 University of Kentucky 2 Washington University in St. Louis
Gradient inversion attack framework for reinforcement learning agents in embodied visual navigation environments. We introduce Temporal Reconstruction Attack on Consecutive Encodings (TRACE) that reconstructs observations and recovers actions from intercepted policy gradients using an autoregressive transformer-based architecture.
trace/
├── victim/ # Victim RL agent pipeline
│ ├── training/ # Train PPO / A2C / SAC agents
│ ├── capture/ # Capture gradient trajectories from trained agents
│ ├── augment/ # Augment captured gradients for training data
│ ├── models/ # Victim network architectures
│ ├── config/ # Per-algorithm YAML configs
│ │ ├── ppo/ # train, capture_{train,test}, augment_{train,test}
│ │ ├── a2c/
│ └── scripts/ # SLURM / shell launch scripts
├── attacker/ # Attacker (inversion) model pipeline
│ ├── training/ # Train the autoregressive inversion model
│ ├── evaluation/ # Evaluate reconstruction quality
│ ├── baselines/ # DLG, IG, Learning-to-Invert baselines
│ ├── models/ # Encoder, decoder, transformer, autoregressive model
│ ├── data/ # Dataset loaders
│ ├── config/ # Per-algorithm YAML configs
│ │ ├── ppo/ # base, adaptation/, ablation/, ss_ablation/
│ │ ├── a2c/
│ └── scripts/ # SLURM / shell launch scripts
├── defense/ # Defense strategies (DP-SGD, gradient pruning, etc.)
├── evaluation/ # Cross-cutting evaluation & reporting scripts
├── trajectory_data/ # Captured gradient HDF5 files (generated)
└── ckpts/ # Model checkpoints (generated)
- Python ≥ 3.13
- uv package manager
- CUDA-capable GPU (recommended: A100 40 GB+)
Training is performed on multi-GPU SLURM clusters. Single-GPU training is supported with reduced batch size by adjusting training.batch_size and training.accumulation_steps in the config.
# Install dependencies with uv
uv syncThe full pipeline generates HDF5 trajectory data under trajectory_data/. Follow stages 1–3 below to produce the training and test sets from scratch.
Train a victim RL agent (PPO or A2C) on AI2-THOR visual navigation:
# PPO
uv run -m victim.training.train victim/config/ppo/train.yaml
# A2C
uv run -m victim.training.train victim/config/a2c/train.yamlCapture gradient snapshots from the trained victim during rollouts:
# PPO
uv run -m victim.capture.capture victim/config/ppo/capture_train.yaml
uv run -m victim.capture.capture victim/config/ppo/capture_test.yaml
# A2C
uv run -m victim.capture.capture victim/config/a2c/capture_train.yaml
uv run -m victim.capture.capture victim/config/a2c/capture_test.yamlApply data augmentation (temporal shifts, noise, etc.) to the captured gradients:
# PPO
uv run -m victim.augment.augment victim/config/ppo/augment_train.yaml
# A2C
uv run -m victim.augment.augment victim/config/a2c/augment_train.yamlThe generated HDF5 files are expected at the paths specified in each experiment config (e.g., trajectory_data/ppo/gradients_train_augmented.h5).
Use the same pipeline with a variant config:
VARIANT=cnn_nav8 # or tiny_vit_nav5, impala_nav5
uv run -m victim.training.train victim/config/ppo/$VARIANT/train.yaml
uv run -m victim.capture.capture victim/config/ppo/$VARIANT/capture_train.yaml
uv run -m victim.capture.capture victim/config/ppo/$VARIANT/capture_test.yaml
uv run -m attacker.training.train attacker/config/ppo/$VARIANT.yamlFor augmented training, retain the victim checkpoint and replace the last command with:
uv run -m victim.augment.augment victim/config/ppo/$VARIANT/augment_train.yaml
uv run -m attacker.training.train attacker/config/ppo/${VARIANT}_augmented.yamlTrain the autoregressive gradient inversion model.
Single GPU:
uv run -m attacker.training.train attacker/config/ppo/base.yamlDistributed (multi-GPU):
NGPUS=4 # adjust to your setup
uv run -m torch.distributed.run \
--standalone \
--nproc_per_node=$NGPUS \
-m attacker.training.train \
attacker/config/ppo/base.yamlSequence length ablation (T = 1, 8, 16, 32, 64):
uv run -m attacker.training.train attacker/config/ppo/ablation/train_t1.yaml
uv run -m attacker.training.train attacker/config/ppo/ablation/train_t8.yaml
uv run -m attacker.training.train attacker/config/ppo/ablation/train_t16.yaml
uv run -m attacker.training.train attacker/config/ppo/ablation/train_t32.yaml
uv run -m attacker.training.train attacker/config/ppo/ablation/train_t64.yamlLoss component ablation:
uv run -m attacker.training.train attacker/config/ppo/ablation/train_no_mse.yaml
uv run -m attacker.training.train attacker/config/ppo/ablation/train_no_l1.yaml
uv run -m attacker.training.train attacker/config/ppo/ablation/train_no_lpips.yaml
uv run -m attacker.training.train attacker/config/ppo/ablation/train_no_action.yamlGradient subspace ablation:
uv run -m attacker.training.train attacker/config/ppo/ablation/train_cnn_only.yaml
uv run -m attacker.training.train attacker/config/ppo/ablation/train_fc_only.yaml
uv run -m attacker.training.train attacker/config/ppo/ablation/train_heads_only.yamlFine-tune a pretrained model on a small fraction of out-of-distribution data:
# 10% adaptation on PPO gradients
uv run -m attacker.training.train attacker/config/ppo/adaptation/10.yaml
# 10% adaptation on A2C gradients
uv run -m attacker.training.train attacker/config/a2c/adaptation/10.yamlAvailable fractions: 10, 20, 30, 40, 50 (percent).
Run from code/ using raw PPO captures. Four-step fine-tuning requires
ckpts/trace/ppo/base/best_model.pt:
uv run -m attacker.tools.aggregate_gradients attacker/config/ppo/aggregation/agg4.yaml
uv run -m attacker.evaluation.evaluate attacker/config/ppo/aggregation/eval_agg4_before.yaml
uv run -m attacker.training.train attacker/config/ppo/aggregation/agg4.yamlEight-step training from scratch requires no base checkpoint:
uv run -m attacker.tools.aggregate_gradients attacker/config/ppo/aggregation/agg8_scratch.yaml
uv run -m torch.distributed.run --standalone --nproc_per_node=4 \
-m attacker.training.train attacker/config/ppo/aggregation/agg8_scratch.yamlAggregation averages consecutive stored gradients within episodes, targeting the last frame and action histogram; it does not recompute PPO minibatch updates. Evaluation runs automatically after training and saves metrics and histograms under the configured output directory.
uv run -m attacker.evaluation.evaluate attacker/config/ppo/eval.yaml| Metric | Description |
|---|---|
| PSNR | Peak Signal-to-Noise Ratio (dB) |
| SSIM | Structural Similarity Index |
| LPIPS | Learned Perceptual Image Patch Similarity (VGG backbone) |
| Action Accuracy | Top-1 classification accuracy over discrete actions |
All image metrics are computed per-frame and averaged across the test set. Per-timestep breakdowns are also reported.
Four baselines are implemented under attacker/baselines/:
| Baseline | File | Reference |
|---|---|---|
| DLG | dlg.py |
Zhu et al., NeurIPS 2019 |
| Inverting Gradients (IG) | ig.py |
Geiping et al., NeurIPS 2020 |
| Learning to Invert (LtI) | learning_to_invert.py |
Wu et al., UAI 2023 |
uv run -m attacker.evaluation.evaluate attacker/config/ppo/eval_baselines.yamlEvaluate reconstruction quality under gradient defense mechanisms (quantization, pruning, noise injection, DP-SGD):
# PPO
uv run -m defense.evaluate defense/config/ppo/eval_defenses.yaml
# A2C
uv run -m defense.evaluate defense/config/a2c/eval_defenses.yamlResults (comparison charts, reconstruction grids, and CSV summaries) are saved to the directory specified in the config's output.save_dir.
All experiments are driven by YAML config files under victim/config/ and attacker/config/. Key sections:
| Section | Description |
|---|---|
data |
HDF5 paths, gradient dimensions, data fractions |
model |
Architecture (sequence length, transformer layers) |
training |
Epochs, LR schedule, scheduled sampling, rollout |
loss |
MSE, L1, action, LPIPS weights |
eval |
Evaluation dataset and sequence count |
wandb |
Weights & Biases logging |
We gratefully acknowledge the authors of the following open-source repositories, whose code we adapted for our baseline implementations:
- DLG — Deep Leakage from Gradients
- IG — Inverting Gradients
- Learning-to-Invert — Learning to Invert
This project is licensed under the MIT License. See LICENSE for details.
If you find this work useful in your research, please consider citing our paper:
@inproceedings{bhujel2026temporal,
title = {Temporal Gradient Inversion for Private Trajectory Reconstruction in Embodied Reinforcement Learning},
author = {Bhujel, Sudip and Shi, Shanghao and Huang, Ruiquan and Zhang, Ning and Xiao, Yang},
booktitle = {Advances in Neural Information Processing Systems},
volume = {39},
year = {2026}
}