File size: 1,800 Bytes
f15a766
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""Train the NODE-ONLY ablation (isolated wrapper around train_wm_graph.py).

Reuses the ENTIRE original training pipeline (arg parsing, dataset, loop,
checkpointing, sidecar) unchanged, and only swaps the model class to
CtrlWorldGraphNodeOnly via a monkeypatch — so the original code is untouched and
the training recipe is identical to the full edge_transformer run.

Launch exactly like the original, e.g.:
  CUDA_VISIBLE_DEVICES=0 python -u scripts/train_nodeonly.py \
    --tag ablation_node_only_edge_transformer \
    --output-dir model_ckpt/ablation_node_only_edge_transformer \
    --tensorboard-log-dir model_ckpt/ablation_node_only_edge_transformer/tensorboard \
    --history-corruption --graph-backbone edge_transformer --graph-resampler query \
    --max-train-steps 50000 --checkpointing-steps 25000
"""
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path:
    sys.path.insert(0, str(ROOT))

import scripts.train_wm_graph as T  # noqa: E402
from graphwm.models.ctrl_world_graph_node_only import CtrlWorldGraphNodeOnly  # noqa: E402
from accelerate import Accelerator as _BaseAccelerator  # noqa: E402
from accelerate.utils import DistributedDataParallelKwargs  # noqa: E402

# ISOLATION: make train_wm_graph.main() instantiate the node-only model.
T.CtrlWorldGraph = CtrlWorldGraphNodeOnly


def _Accelerator(*args, **kwargs):
    # node-only strips edges -> edge_proj/edge_bias get no gradient; multi-GPU DDP
    # needs find_unused_parameters=True to not error on those unused parameters.
    kwargs.setdefault("kwargs_handlers", [DistributedDataParallelKwargs(find_unused_parameters=True)])
    return _BaseAccelerator(*args, **kwargs)


T.Accelerator = _Accelerator


if __name__ == "__main__":
    T.main(T.parse_args())