unlearning / README.md
adhirajghosh's picture
Upload README.md with huggingface_hub
983a8bf verified
|
Raw
History Blame Contribute Delete
4.44 kB
# `gun` unlearning data
Target concept: **gun** (29 firearm tags: `gun`, `pistol`, `rifle`, `revolver`,
`shotgun`, `handgun`, `sniper rifle`, `uzi submachine gun`, `mp5 submachine gun`,
`bullet`, `ammunition`, `gun barrel`, … — full list in `manifest_curated.json`).
## What's on disk
| Path | Size | Shards / rows | What it is |
|------|------|---------------|------------|
| `forget/` | 37 GB | 90 tars | **Forget set** — images containing the gun concept. `447,370` samples. |
| `retain/` | 92 GB | 269 tars | **Retain set** — everything else, ~3× the forget set. `1,342,021` samples (of `1,357,557` requested; seed `42`). |
| `pairs/` | 433 MB | 69 files | Counterfactual **pair tables** (parquet). `pairs_train_clean.parquet` = `1,823,249` rows. |
| `pair_shards_seq/` | 52 GB | 180 tars | Pairs pre-materialized into sequential tar shards (used by the `seq_fast` recipe). |
| `concept_table/` | 30 GB | — | Per-concept lookup table from Stage 2/3. |
| `manifest_curated.json` | 5.5 MB | — | Authoritative counts + shard list. Read this, not the config, for exact numbers. |
| `results/` | — | — | Training output dir referenced by the 1M `juwels_gun.yaml` preset. |
### Counts (from `manifest_curated.json`)
```
n_forget_total: 447,370
n_retain_total: 1,342,021 (retain_size_requested 1,357,557, seed 42)
n_shards: 22,021
```
### The counterfactual pairs
Each row of `pairs_train_clean.parquet` is a matched pair:
- `image_pos` — image **with** the gun concept
- `image_neg` — near-duplicate image **without** it
- `pair_id`, `target_concept`, `jaccard`, `similarity_score`, `match_weight`,
`block_label`, `tags_pos/neg`, `context_pos/neg`, `split`
> **Use `pairs_train_clean.parquet`, not `pairs_train.parquet`** — ~19.4% of the
> unclean file's rows have invalid 10-digit keys.
## How it's used in training (current sequential recipe, where we need KLD anchor)
Config: `configs/unlearn/juwels_bf16_l2dist_kl_v2_seq_fast.yaml`
(`experiment_name: bf16_l2dist_kl_v2_seq_fast_gun`, `max_train_steps: 7000`).
### Two streams, merged per batch
- **Pair stream** — `pairs_train_clean.parquet` rows, images pulled from the
DataComp tars at `pair_tar_dir: /p/data1/mmlaion/cabs/dataconcept_128m`
(`pair_source: "tar"`, 48-shard cache, `pair_shuffle: false`).
`PairDataset` → `PairCollator` → `pixel_values_pos [B,C,H,W]` +
`pixel_values_neg [B,C,H,W]`, prefixed `pair_*`.
- **Retain stream** — retain SFT examples. `RetainDataCollator` →
`input_ids`, `labels`, `images`, `image_sizes`, `modalities`
(a normal LLaVA next-token batch; no `attention_mask` — LLaVA rebuilds it
after `<image>`-token expansion).
Batch mix: `pair_batch_size: 2`, `retain_batch_size: 2` (1:1). Bad/corrupt
images are replaced by zero tensors rather than crashing a rank.
### Sequential phase schedule
Unlike the interleaved presets, `seq_fast` runs `phase_mode: "sequential"`,
`phase_forget_frac: 0.5` — **two blocks** over the 7000 steps:
| Block (steps) | Data used | Active losses |
|---|---|---|
| **FORGET** — first 50% (0–3500) | pair stream only | visual invariance (pos≈neg) + L2 param-locality |
| **RETAIN** — last 50% (3500–7000) | retain stream | retain-SFT CE + KL-locality (student≈teacher logits) + L2 param-locality |
L2 locality is on throughout (it anchors params, needs no data); the retain
forward is skipped entirely during the FORGET block.
### Loss weights (unlearning_loss_adapter.py)
| Term | Data it consumes | Weight |
|---|---|---|
| retain-SFT cross-entropy | retain `input_ids/labels/images` | `1.0` |
| pooled visual invariance (l2, squared-dist, mean-pool) | `pair_pixel_values_pos/neg` | `1.0` |
| KL locality | retain batch + frozen teacher | `0.5` |
| L2 parameter locality | trainable params vs start snapshot | `0.1` |
### Model / optimisation
- Base: `llava-onevision-qwen2-7b-ov`, `model_max_length: 1024`, `image_aspect_ratio: "pad"`.
- Trainable: **projector only**. bf16, FSDP, 8 dataloader workers, no grad checkpointing.
- LR `1e-5` cosine, warmup `0.1`, `per_device_train_batch_size: 2`, grad-accum `1`, `max_grad_norm 1.0`.
## Net effect on data
Forget pairs teach the model to **stop distinguishing gun-present from
gun-absent** images (invariance); the retain block **re-anchors normal
behaviour** via SFT + KL-to-teacher; L2 locality keeps weights close to the
original throughout so retain performance doesn't drift.