LifeMem Qwen GPU job sources
Browse files- README.md +67 -9
- lifemem/experiment.py +7 -0
- lifemem/llm.py +10 -3
- scripts/hf_job.py +14 -2
README.md
CHANGED
|
@@ -1,11 +1,69 @@
|
|
| 1 |
-
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
task_categories:
|
| 4 |
-
- text-generation
|
| 5 |
-
pretty_name: LifeMem Qwen GPU job sources
|
| 6 |
-
---
|
| 7 |
|
| 8 |
-
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# LifeMem replication (arXiv:2608.19621)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
Replication of [Mitigating Identity Essentialism in LLM Agents with Longitudinal Life Trajectories](https://arxiv.org/abs/2608.19621) (Wang, Zhou, Du, Su, Cao, Pan, Ai, Wu, Zhang, Liu). Official code: [halsayxi/LifeMem](https://github.com/halsayxi/LifeMem).
|
| 4 |
|
| 5 |
+
The paper's claim: static demographic prompts make LLM survey agents essentialist — within-group answers collapse, SES clusters separate. LifeMem stores life events in a hippocampal retriever (top-K=5, α=0.9) and consolidates them into a per-agent LoRA adapter.
|
| 6 |
+
|
| 7 |
+
## What this folder runs
|
| 8 |
+
|
| 9 |
+
Add Health and Understanding Society public-use files are restricted. This folder does not ship respondent microdata.
|
| 10 |
+
|
| 11 |
+
It does ship:
|
| 12 |
+
|
| 13 |
+
1. The paper's published Table 1–3 and appendix sweeps (Tables 12, 13, 14, 15).
|
| 14 |
+
2. A synthetic six-wave panel (24 agents, 8 Likert items, 12 event types) with the same metrics: KL, within-group pairwise gap, entropy gap, transition JS, SES silhouette.
|
| 15 |
+
3. Method prompts for Direct, Profile, Anti-stereotype, Full History, Event RAG, Random Event, LifeMem, and the two ablations.
|
| 16 |
+
4. A hashed n-gram encoder in place of MiniLM / bge-m3, and a persistent event-binding vector in place of LoRA, so the CPU path stays deterministic.
|
| 17 |
+
|
| 18 |
+
The default GPU backbone for a full run is `Qwen/Qwen3.5-4B` (lab default). The paper used Llama-3.1-8B-Instruct, Ministral-3-8B-Instruct-2512, and Qwen3.5-9B.
|
| 19 |
+
|
| 20 |
+
## Run the CPU suite
|
| 21 |
+
|
| 22 |
+
From the repository root:
|
| 23 |
+
|
| 24 |
+
```bash
|
| 25 |
+
uv sync --all-packages --extra test
|
| 26 |
+
uv run pytest autoresearch/mitigating_identity_essentialism_lifemem_2026_09_09/tests -q
|
| 27 |
+
uv run python autoresearch/mitigating_identity_essentialism_lifemem_2026_09_09/scripts/export_dashboard_data.py
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
That writes `data/replication_results.json` and `dashboard/public/data/results.json`.
|
| 31 |
+
|
| 32 |
+
## Dashboard
|
| 33 |
+
|
| 34 |
+
Live Vercel preview: [https://temporary-prompt-birch-7xdekgc.vercel.app](https://temporary-prompt-birch-7xdekgc.vercel.app)
|
| 35 |
+
|
| 36 |
+
That URL is an anonymous Vercel deploy. Claim it to keep it: [claim deployment](https://vercel.com/claim-deployment?code=81a2f69e-26b4-4b8c-9839-e6ce949a0df1). A durable static mirror is on Hugging Face: [mtorres98/lifemem-identity-dashboard](https://huggingface.co/spaces/mtorres98/lifemem-identity-dashboard).
|
| 37 |
+
|
| 38 |
+
```bash
|
| 39 |
+
cd autoresearch/mitigating_identity_essentialism_lifemem_2026_09_09/dashboard
|
| 40 |
+
npm install
|
| 41 |
+
npm run dev
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
The UI has the paper takeaways, Table 1 charts, identity PCA, the synthetic ranking, a compose-a-person control, retrieval scores, latency, and hyperparameter sweeps.
|
| 45 |
+
|
| 46 |
+
## GPU run (Hugging Face Jobs)
|
| 47 |
+
|
| 48 |
+
The lab default backbone is `Qwen/Qwen3.5-4B`. `scripts/hf_job.py` loads that model, trains a PEFT LoRA adapter per agent for LifeMem / `lifemem_no_struct`, and scores the same nine methods.
|
| 49 |
+
|
| 50 |
+
Jobs cannot see this git checkout. `scripts/submit_hf_job.py` uploads `lifemem/` to a Hub dataset, then submits:
|
| 51 |
+
|
| 52 |
+
```bash
|
| 53 |
+
uv run python autoresearch/mitigating_identity_essentialism_lifemem_2026_09_09/scripts/submit_hf_job.py
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
Default hardware is `a10g-small` (24 GB), 8 agents × 6 waves, timeout 3h. Results go to `data/gpu_results.json`, Hub dataset `mtorres98/lifemem-replication-2026-09-09`, and `s3://mind-technology-lab-experiments/autoresearch/mitigating_identity_essentialism_lifemem_2026_09_09/`.
|
| 57 |
+
|
| 58 |
+
Jobs require a positive credit balance on the submitting namespace. This token currently gets HTTP 402 from Jobs. The same `scripts/hf_job.py` suite can run on a GPU pod until Jobs credits exist:
|
| 59 |
+
|
| 60 |
+
```bash
|
| 61 |
+
uv run python autoresearch/mitigating_identity_essentialism_lifemem_2026_09_09/scripts/submit_runpod_job.py
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
After a job finishes:
|
| 65 |
+
|
| 66 |
+
```bash
|
| 67 |
+
uv run python autoresearch/mitigating_identity_essentialism_lifemem_2026_09_09/scripts/fetch_gpu_results.py
|
| 68 |
+
uv run python autoresearch/mitigating_identity_essentialism_lifemem_2026_09_09/scripts/export_dashboard_data.py
|
| 69 |
+
```
|
lifemem/experiment.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
|
|
|
|
|
|
| 3 |
from copy import deepcopy
|
| 4 |
from pathlib import Path
|
| 5 |
from random import Random
|
|
@@ -110,6 +112,11 @@ def run_method(
|
|
| 110 |
train_adapter = getattr(respondent, "train_adapter", None)
|
| 111 |
generate_batch = getattr(respondent, "generate_batch", None)
|
| 112 |
for wave in panel.waves:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
for agent in agents:
|
| 114 |
new_events = panel.events_by_wave[(agent.profile.agent_id, wave)]
|
| 115 |
replay = _sample_replay(agent.events, config.replay_size, rng)
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
from copy import deepcopy
|
| 6 |
from pathlib import Path
|
| 7 |
from random import Random
|
|
|
|
| 112 |
train_adapter = getattr(respondent, "train_adapter", None)
|
| 113 |
generate_batch = getattr(respondent, "generate_batch", None)
|
| 114 |
for wave in panel.waves:
|
| 115 |
+
if os.environ.get("LIFEMEM_PROGRESS"):
|
| 116 |
+
print(
|
| 117 |
+
json.dumps({"progress": "wave", "method": method, "wave": wave}),
|
| 118 |
+
flush=True,
|
| 119 |
+
)
|
| 120 |
for agent in agents:
|
| 121 |
new_events = panel.events_by_wave[(agent.profile.agent_id, wave)]
|
| 122 |
replay = _sample_replay(agent.events, config.replay_size, rng)
|
lifemem/llm.py
CHANGED
|
@@ -50,7 +50,6 @@ class QwenRespondent:
|
|
| 50 |
import torch
|
| 51 |
from transformers import (
|
| 52 |
AutoModelForImageTextToText,
|
| 53 |
-
AutoProcessor,
|
| 54 |
AutoTokenizer,
|
| 55 |
)
|
| 56 |
|
|
@@ -62,8 +61,16 @@ class QwenRespondent:
|
|
| 62 |
else torch.float32
|
| 63 |
)
|
| 64 |
name = self.config.model_name
|
| 65 |
-
self.processor =
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
if self.tokenizer is None:
|
| 68 |
self.tokenizer = AutoTokenizer.from_pretrained(name, trust_remote_code=True)
|
| 69 |
if self.tokenizer.pad_token is None:
|
|
|
|
| 50 |
import torch
|
| 51 |
from transformers import (
|
| 52 |
AutoModelForImageTextToText,
|
|
|
|
| 53 |
AutoTokenizer,
|
| 54 |
)
|
| 55 |
|
|
|
|
| 61 |
else torch.float32
|
| 62 |
)
|
| 63 |
name = self.config.model_name
|
| 64 |
+
self.processor = None
|
| 65 |
+
try:
|
| 66 |
+
from transformers import AutoProcessor
|
| 67 |
+
|
| 68 |
+
self.processor = AutoProcessor.from_pretrained(name, trust_remote_code=True)
|
| 69 |
+
self.tokenizer = getattr(self.processor, "tokenizer", None)
|
| 70 |
+
except Exception:
|
| 71 |
+
# Text-only survey path: Qwen3.5's AutoProcessor pulls torchvision.
|
| 72 |
+
self.processor = None
|
| 73 |
+
self.tokenizer = None
|
| 74 |
if self.tokenizer is None:
|
| 75 |
self.tokenizer = AutoTokenizer.from_pretrained(name, trust_remote_code=True)
|
| 76 |
if self.tokenizer.pad_token is None:
|
scripts/hf_job.py
CHANGED
|
@@ -15,7 +15,7 @@ the source dataset when it is not already on PYTHONPATH.
|
|
| 15 |
# "peft>=0.17.0",
|
| 16 |
# "pillow>=10.0.0",
|
| 17 |
# "safetensors>=0.4.0",
|
| 18 |
-
# "
|
| 19 |
# "transformers>=5.0.0",
|
| 20 |
# ]
|
| 21 |
# ///
|
|
@@ -85,7 +85,18 @@ def main() -> None:
|
|
| 85 |
raise SystemExit(
|
| 86 |
"CUDA is required for the Qwen LifeMem job; got CPU-only torch"
|
| 87 |
)
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
config = LifeMemConfig(
|
| 90 |
model_name=os.environ.get("LIFEMEM_MODEL", "Qwen/Qwen3.5-4B")
|
| 91 |
)
|
|
@@ -102,6 +113,7 @@ def main() -> None:
|
|
| 102 |
results["lora"] = lora_config_dict(config)
|
| 103 |
results["backbone"] = config.model_name
|
| 104 |
results["device"] = torch.cuda.get_device_name(0)
|
|
|
|
| 105 |
out = Path(os.environ.get("LIFEMEM_OUT", "gpu_results.json"))
|
| 106 |
urls = push_json(results, "gpu_results.json", out)
|
| 107 |
print(json.dumps({"urls": urls}, indent=2))
|
|
|
|
| 15 |
# "peft>=0.17.0",
|
| 16 |
# "pillow>=10.0.0",
|
| 17 |
# "safetensors>=0.4.0",
|
| 18 |
+
# "torchvision>=0.21.0",
|
| 19 |
# "transformers>=5.0.0",
|
| 20 |
# ]
|
| 21 |
# ///
|
|
|
|
| 85 |
raise SystemExit(
|
| 86 |
"CUDA is required for the Qwen LifeMem job; got CPU-only torch"
|
| 87 |
)
|
| 88 |
+
os.environ.setdefault("LIFEMEM_PROGRESS", "1")
|
| 89 |
+
os.environ.setdefault("TOKENIZERS_PARALLELISM", "false")
|
| 90 |
+
print(
|
| 91 |
+
json.dumps(
|
| 92 |
+
{
|
| 93 |
+
"cuda": torch.cuda.get_device_name(0),
|
| 94 |
+
"root": str(ROOT),
|
| 95 |
+
"torch": torch.__version__,
|
| 96 |
+
}
|
| 97 |
+
),
|
| 98 |
+
flush=True,
|
| 99 |
+
)
|
| 100 |
config = LifeMemConfig(
|
| 101 |
model_name=os.environ.get("LIFEMEM_MODEL", "Qwen/Qwen3.5-4B")
|
| 102 |
)
|
|
|
|
| 113 |
results["lora"] = lora_config_dict(config)
|
| 114 |
results["backbone"] = config.model_name
|
| 115 |
results["device"] = torch.cuda.get_device_name(0)
|
| 116 |
+
results["hardware"] = os.environ.get("LIFEMEM_HARDWARE", "huggingface-jobs")
|
| 117 |
out = Path(os.environ.get("LIFEMEM_OUT", "gpu_results.json"))
|
| 118 |
urls = push_json(results, "gpu_results.json", out)
|
| 119 |
print(json.dumps({"urls": urls}, indent=2))
|